bearcat 1.4.11 → 1.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 65992dcbb43af93a7a7f34bdf322bd82dd7ee45c
4
- data.tar.gz: 3bf3d5f3e0849977b01b64df3c544519c2da928c
2
+ SHA256:
3
+ metadata.gz: 56127337ffe67a0c9a01aa12a8c7d858331c49a8c608c2ec7e82de2b10abaadc
4
+ data.tar.gz: ef63a06ce0fc281a255763afbd1d7e0d07e85b2d40bf2a45b01a4a41f21efb1b
5
5
  SHA512:
6
- metadata.gz: 2936b59a7848832d98927f55e16abcce88f975a48319acaa2d8888ac5fe0ddb3e824f2eb1b638c44e0adeb0e5269eb6dd1304b0866feefca1714ce4c2c58565e
7
- data.tar.gz: 1f176cce865ed38077e99e8a4960a09953d9c62bc0dbf7e0353caf8d1fc281152764ffbe05321ad13c01986b148c7f5154c20dee1096ab44ec444692cbb360c8
6
+ metadata.gz: 9dee94f956ca584cc6c0d892277e424430f81c62074106f040fe92974d926b5df72dc8b57d7e3f84dff64d135ba274967da32110bb8201aee061715b331b4969
7
+ data.tar.gz: 114bbcc3a2374c8b8774da933c412ea73f57a9adb0273a5d1683ee4949fd077088bdb12ca91e430011cda1740023a4c9b480a45c573c9685ee30a9215488d2c0
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/module'
2
+
1
3
  module Bearcat
2
4
  class ApiArray
3
5
  include Enumerable
@@ -5,7 +5,7 @@ module Bearcat
5
5
  {
6
6
  size: File.open(file_path).size,
7
7
  name: File.basename(file_path)
8
- }
8
+ }.with_indifferent_access
9
9
  end
10
10
 
11
11
  def declare_file(api_path, params)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bearcat
4
+ class Client < Footrest::Client
5
+ module LearningOutcomes
6
+
7
+ def learning_outcome(outcome, params={})
8
+ get("/api/v1/outcomes/#{outcome}", params)
9
+ end
10
+
11
+ def update_learning_outcome(outcome, params={})
12
+ put("/api/v1/outcomes/#{outcome}", params)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -34,22 +34,12 @@ module Bearcat
34
34
  put("/api/v1/sections/#{section}/assignments/#{assignment}/submissions/#{user}", params)
35
35
  end
36
36
 
37
- def course_file_upload_submission(course, assignment, user, file_path, params={})
38
- response = upload_file("/api/v1/courses/#{course}/assignments/#{assignment}/submissions/#{user}/files", file_path, params)
39
- params['submission'] = {
40
- 'submission_type' => 'online_upload',
41
- 'file_ids'=> [response['id']]
42
- }
43
- course_submission(course, assignment, params)
37
+ def course_file_upload_submission(course, assignment, user, file_data, params={})
38
+ file_upload_submission(course, assignment, user, file_data, params, type: :course)
44
39
  end
45
40
 
46
- def section_file_upload_submission(section, assignment, user, file_path, params={})
47
- response = upload_file("/api/v1/sections/#{section}/assignments/#{assignment}/submissions/#{user}/files", file_path, params)
48
- params['submission'] = {
49
- 'submission_type' => 'online_upload',
50
- 'file_ids'=> [response['id']]
51
- }
52
- section_submission(section, assignment, params)
41
+ def section_file_upload_submission(section, assignment, user, file_data, params={})
42
+ file_upload_submission(section, assignment, user, file_data, params, type: :section)
53
43
  end
54
44
 
55
45
  def course_update_grades(course, assignment, params={})
@@ -60,6 +50,43 @@ module Bearcat
60
50
  post("/api/v1/sections/#{section}/assignments/#{assignment}/submissions/update_grades", params)
61
51
  end
62
52
 
53
+ protected
54
+
55
+ # @param file_data One of an array of file_path strings or an array of Hashes, each being upload file params plus the file's path
56
+ def file_upload_submission(type_id, assignment, user, file_data=nil, params={}, type:)
57
+ raise ArgumentError, 'Invalid type' unless [:course, :section].include?(type)
58
+ raise ArgumentError, 'Must provide either file paths or fully formed submission params' if params.dig(:submission, :file_ids).nil? && file_data.nil?
59
+
60
+ params = params.with_indifferent_access
61
+ sub_params = if params.dig(:submission, :file_ids).present?
62
+ {}
63
+ else
64
+ file_data = Array.wrap(file_data)
65
+ file_ids = file_data.map do |datum|
66
+ if datum.is_a?(Hash) && datum[:file_path].present?
67
+ # datum is a param hash for upload_file API plus the file_path
68
+ path = datum[:file_path]
69
+ upload_params = datum.except(:file_path)
70
+ else
71
+ # treat datum as a file_path string
72
+ path = datum
73
+ upload_params = params
74
+ end
75
+
76
+ response = upload_file("/api/v1/#{type}s/#{type_id}/assignments/#{assignment}/submissions/#{user}/files", path, upload_params)
77
+ response['id']
78
+ end
79
+
80
+ {
81
+ submission_type: 'online_upload',
82
+ file_ids: file_ids,
83
+ }
84
+ end
85
+ sub_params.merge!(params[:submission]) if params[:submission].present?
86
+ params[:submission] = sub_params
87
+ send("#{type}_submission".to_sym, type_id, assignment, params)
88
+ end
89
+
63
90
  end
64
91
  end
65
92
  end
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.4.11' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.4.13' unless defined?(Bearcat::VERSION)
3
3
  end
@@ -13,8 +13,8 @@ describe Bearcat::Client::CanvasFiles do
13
13
  stub_request(:post, "https://upload-url.invalid/").
14
14
  to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})
15
15
 
16
- stub_post(@client, "/confirm").
17
- with(:body => {"param" => ["true"]}).to_return(json_response('canvas_files', 'upload_success.json'))
16
+ stub_get(@client, "/confirm").
17
+ with(:query => {"param" => ["true"]}).to_return(json_response('canvas_files', 'upload_success.json'))
18
18
 
19
19
  response = @client.upload_file('my/upload/path', fixture('bearcat.jpg'))
20
20
  expect(response['id']).to eq 123
@@ -7,12 +7,12 @@ describe Bearcat::Client::ContentMigrations do
7
7
 
8
8
  it 'uploads a file' do
9
9
  stub_post(@client, "/my/upload/path").
10
- to_return(json_response('content_migration_files/response.json'))
10
+ to_return(json_response('content_migration_files/response.json'))
11
11
 
12
12
  stub_request(:post, "http://host/files_api").
13
13
  to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})
14
14
 
15
- stub_post(@client, '/confirm').to_return(json_response('content_migration_files/upload_success.json'))
15
+ stub_get(@client, '/confirm').with(:query => {"param" => ["true"]}).to_return(json_response('content_migration_files/upload_success.json'))
16
16
 
17
17
  opts = {migration_type: 'canvas_cartridge_importer', pre_attachment: {name: 'cc.imscc', size: '2034'}}
18
18
  response = @client.upload_content_package('my/upload/path', fixture('cc.imscc'), opts)
@@ -49,8 +49,8 @@ describe Bearcat::Client::Sections do
49
49
  stub_request(:post, "http://host/files_api").
50
50
  to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})
51
51
 
52
- stub_post(@client, "/confirm").
53
- with(:body => {"param" => ["true"]}).to_return(json_response('content_migration_files', 'upload_success.json'))
52
+ stub_get(@client, "/confirm").
53
+ with(:query => {"param" => ["true"]}).to_return(json_response('content_migration_files', 'upload_success.json'))
54
54
 
55
55
  opts = {'migration_type' => 'canvas_cartridge_importer', 'pre_attachment[name]' => 'cc.imscc', 'pre_attachment[size]' => '2034'}
56
56
  response = @client.create_content_migration('659', fixture('cc.imscc'), opts)
@@ -66,8 +66,8 @@ describe Bearcat::Client::Sections do
66
66
  stub_request(:post, "http://host/files_api").
67
67
  to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})
68
68
 
69
- stub_post(@client, "/confirm").
70
- with(:body => {"param" => ["true"]}).to_return(json_response('content_migration_files', 'upload_success.json'))
69
+ stub_get(@client, "/confirm").
70
+ with(:query => {"param" => ["true"]}).to_return(json_response('content_migration_files', 'upload_success.json'))
71
71
 
72
72
  opts = {'migration_type' => 'canvas_cartridge_importer', 'pre_attachment[name]' => 'cc.imscc', 'pre_attachment[size]' => '2034'}
73
73
  content_migration_response, file_upload_response = @client.create_content_migration_with_both_responses('659', fixture('cc.imscc'), opts)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'helper'
4
+
5
+ describe Bearcat::Client::LearningOutcomes do
6
+ before do
7
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
8
+ end
9
+
10
+ it "returns an individual learning outcome" do
11
+ stub_get(@client, "/api/v1/outcomes/1").to_return(json_response("learning_outcome.json"))
12
+ outcome = @client.learning_outcome(1)
13
+ outcome["id"].should == 1
14
+ outcome["context_type"].should == "Course"
15
+ outcome["title"].should == "First Outcome"
16
+ end
17
+
18
+ it "updates an individual learning outcome" do
19
+ stub_put(@client, "/api/v1/outcomes/1").to_return(json_response("learning_outcome.json"))
20
+ outcome = @client.update_learning_outcome(1)
21
+ outcome["id"].should == 1
22
+ outcome["context_type"].should == "Course"
23
+ outcome["title"].should == "First Outcome"
24
+ end
25
+ end
@@ -45,6 +45,13 @@ describe Bearcat::Client::Submissions do
45
45
  response['id'].should == 8444510
46
46
  end
47
47
 
48
+ it "submits multiple files" do
49
+ @client.stub(:upload_file).and_return({})
50
+ stub_post(@client, '/api/v1/courses/1/assignments/2/submissions').to_return(json_response('submissions', 'submission.json'))
51
+ response = @client.course_file_upload_submission(1, 2, 3, [fixture('bearcat.jpg'), fixture('file.csv')])
52
+ response['id'].should == 8444510
53
+ end
54
+
48
55
  it "updates grades" do
49
56
  params = {"grade_data[123]" => "19"}
50
57
  stub_post(@client, "/api/v1/courses/1/assignments/1/submissions/update_grades").with(body: {"grade_data"=>["19"]}).to_return(json_response("progress.json"))
@@ -56,6 +63,13 @@ describe Bearcat::Client::Submissions do
56
63
 
57
64
  context 'section' do
58
65
  it "submits a file" do
66
+ @client.stub(:upload_file).and_return({})
67
+ stub_post(@client, '/api/v1/sections/1/assignments/2/submissions').to_return(json_response('submissions', 'submission.json'))
68
+ response = @client.section_file_upload_submission(1, 2, 3, [fixture('bearcat.jpg'), fixture('file.csv')])
69
+ response['id'].should == 8444510
70
+ end
71
+
72
+ it "submits multiple files" do
59
73
  @client.stub(:upload_file).and_return({})
60
74
  stub_post(@client, '/api/v1/sections/1/assignments/2/submissions').to_return(json_response('submissions', 'submission.json'))
61
75
  response = @client.section_file_upload_submission(1, 2, 3, fixture('bearcat.jpg'))
@@ -0,0 +1,32 @@
1
+ {
2
+ "id": 1,
3
+ "context_id": 1,
4
+ "context_type": "Course",
5
+ "vendor_guid": null,
6
+ "display_name": "",
7
+ "title": "First Outcome",
8
+ "url": "/api/v1/outcomes/1",
9
+ "can_edit": true,
10
+ "has_updateable_rubrics": false,
11
+ "description": "<p>Description</p>",
12
+ "friendly_description": null,
13
+ "points_possible": 5.0,
14
+ "mastery_points": 3.0,
15
+ "ratings": [
16
+ {
17
+ "description": "Exceeds Expectations",
18
+ "points": 5.0
19
+ },
20
+ {
21
+ "description": "Meets Expectations",
22
+ "points": 3.0
23
+ },
24
+ {
25
+ "description": "Does Not Meet Expectations",
26
+ "points": 0.0
27
+ }
28
+ ],
29
+ "calculation_method": "decaying_average",
30
+ "calculation_int": 65,
31
+ "assessed": true
32
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bearcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.11
4
+ version: 1.4.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Mills, Jake Sorce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-13 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -158,6 +158,7 @@ files:
158
158
  - lib/bearcat/client/group_categories.rb
159
159
  - lib/bearcat/client/group_memberships.rb
160
160
  - lib/bearcat/client/groups.rb
161
+ - lib/bearcat/client/learning_outcomes.rb
161
162
  - lib/bearcat/client/module_items.rb
162
163
  - lib/bearcat/client/modules.rb
163
164
  - lib/bearcat/client/o_auth2.rb
@@ -202,6 +203,7 @@ files:
202
203
  - spec/bearcat/client/group_categories_spec.rb
203
204
  - spec/bearcat/client/group_membership_spec.rb
204
205
  - spec/bearcat/client/groups_spec.rb
206
+ - spec/bearcat/client/learning_outcomes_spec.rb
205
207
  - spec/bearcat/client/module_items_spec.rb
206
208
  - spec/bearcat/client/modules_spec.rb
207
209
  - spec/bearcat/client/o_auth2_spec.rb
@@ -318,6 +320,7 @@ files:
318
320
  - spec/fixtures/group_category_groups.json
319
321
  - spec/fixtures/group_conferences.json
320
322
  - spec/fixtures/group_membership.json
323
+ - spec/fixtures/learning_outcome.json
321
324
  - spec/fixtures/link_unlink_outcome.json
322
325
  - spec/fixtures/merge_user.json
323
326
  - spec/fixtures/module.json
@@ -383,8 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
383
386
  - !ruby/object:Gem::Version
384
387
  version: '0'
385
388
  requirements: []
386
- rubyforge_project:
387
- rubygems_version: 2.4.5.1
389
+ rubygems_version: 3.1.6
388
390
  signing_key:
389
391
  specification_version: 4
390
392
  summary: Canvas API
@@ -423,6 +425,7 @@ test_files:
423
425
  - spec/bearcat/client/external_tools_spec.rb
424
426
  - spec/bearcat/client/rubric_spec.rb
425
427
  - spec/bearcat/client/accounts_spec.rb
428
+ - spec/bearcat/client/learning_outcomes_spec.rb
426
429
  - spec/bearcat/client/outcomes_spec.rb
427
430
  - spec/bearcat/client/courses_spec.rb
428
431
  - spec/bearcat/client/reports_spec.rb
@@ -540,6 +543,7 @@ test_files:
540
543
  - spec/fixtures/account_admin_delete.json
541
544
  - spec/fixtures/account_reports_result_success.json
542
545
  - spec/fixtures/deleted_conversation.json
546
+ - spec/fixtures/learning_outcome.json
543
547
  - spec/fixtures/user_details.json
544
548
  - spec/fixtures/outcome_group_import.json
545
549
  - spec/fixtures/modules.json