bearcat 1.4.12 → 1.4.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9624073616df55ad692ec0eb808b54f351b41449f5bd6a75806b4ef6934bb87
4
- data.tar.gz: c6eae2b5630dfd0c6b588d782055d414f5b2ae90e2c455aa71d2784c8b7e55dd
3
+ metadata.gz: 56127337ffe67a0c9a01aa12a8c7d858331c49a8c608c2ec7e82de2b10abaadc
4
+ data.tar.gz: ef63a06ce0fc281a255763afbd1d7e0d07e85b2d40bf2a45b01a4a41f21efb1b
5
5
  SHA512:
6
- metadata.gz: e2afebc157550a3372fdeee760f47b6bbba7a7c88f366d67f4d24abb8eee0f4e2deae063530b7eded3b6e608ff2213ba090abf2c4de3aa8c1a9c005aa1167701
7
- data.tar.gz: 0dd4001957e00e222210560338f1790b3e09c9597e646375ac00ac3f7d6fd8028c5c91469ce77d69a9f07982d6f8f982e694d208ae389cff2f895d63722be773
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)
@@ -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.12' 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)
@@ -8,7 +8,7 @@ describe Bearcat::Client::LearningOutcomes do
8
8
  end
9
9
 
10
10
  it "returns an individual learning outcome" do
11
- stub_get(@client, "/api/v1/outcomes/1").to_return(json_response("learning_outcomes.json"))
11
+ stub_get(@client, "/api/v1/outcomes/1").to_return(json_response("learning_outcome.json"))
12
12
  outcome = @client.learning_outcome(1)
13
13
  outcome["id"].should == 1
14
14
  outcome["context_type"].should == "Course"
@@ -16,7 +16,7 @@ describe Bearcat::Client::LearningOutcomes do
16
16
  end
17
17
 
18
18
  it "updates an individual learning outcome" do
19
- stub_put(@client, "/api/v1/outcomes/1").to_return(json_response("learning_outcomes.json"))
19
+ stub_put(@client, "/api/v1/outcomes/1").to_return(json_response("learning_outcome.json"))
20
20
  outcome = @client.update_learning_outcome(1)
21
21
  outcome["id"].should == 1
22
22
  outcome["context_type"].should == "Course"
@@ -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'))
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.12
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-07-12 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
@@ -386,7 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
386
386
  - !ruby/object:Gem::Version
387
387
  version: '0'
388
388
  requirements: []
389
- rubygems_version: 3.0.3
389
+ rubygems_version: 3.1.6
390
390
  signing_key:
391
391
  specification_version: 4
392
392
  summary: Canvas API