bearcat 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bearcat/client/reports.rb +32 -1
- data/lib/bearcat/version.rb +1 -1
- data/spec/bearcat/client/content_migrations_spec.rb +11 -9
- data/spec/bearcat/client/quizzes_spec.rb +1 -1
- data/spec/bearcat/client/reports_spec.rb +40 -1
- data/spec/fixtures/account_groups.json +42 -0
- data/spec/fixtures/file.csv +5 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 244cd4a8f9e8a9996c2b0d0f4c98b2dc80bf9b64
|
4
|
+
data.tar.gz: 5d081d0e5c5eb3734439d25ac3f89ee4523fb80a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d933adc2b8cf295b326b595697b27403b0768c4a2e1690ccfb091c2717897e9c75cf25fbafd8168b702f3c3c84e76a3e57ad09f8abaf4cca8c70d363787894a5
|
7
|
+
data.tar.gz: d8c701f1f5f65c9d7741d343108453ce61ebd09e20cb5f4c38b59000e493dbbf7521590313ef7e6e0a42ec55e6aa11dabb3f9e117ead2fdbdfc38cd48b97c83a
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
1
3
|
module Bearcat
|
2
4
|
class Client < Footrest::Client
|
3
5
|
module Reports
|
@@ -22,6 +24,35 @@ module Bearcat
|
|
22
24
|
delete("/api/v1/accounts/#{account}/reports/#{report_name}/#{report_id}")
|
23
25
|
end
|
24
26
|
|
27
|
+
def download_report(url, save_location=nil)
|
28
|
+
#This method takes the verified URL returned in a Canvas report (attachment['url']), and if
|
29
|
+
#a save_location is included, it will download it in chunks to the disk to save memory. You
|
30
|
+
#can also download the report to memory if you do not include a save location.
|
31
|
+
attempts = 0
|
32
|
+
begin
|
33
|
+
uri = URI.parse(url)
|
34
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
35
|
+
http.use_ssl = true if url.start_with?('https')
|
36
|
+
response = http.head(uri.to_s)
|
37
|
+
url = response['Location']
|
38
|
+
attempts += 1
|
39
|
+
end while attempts <= 5 && (response.code == '301' || response.code == '302' || response.code == '307')
|
40
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
41
|
+
http.use_ssl = true if uri.to_s.start_with?('https')
|
42
|
+
if save_location
|
43
|
+
File.open(save_location, 'wb') do |file|
|
44
|
+
http.request_get(uri.to_s) do |resp|
|
45
|
+
resp.read_body do |segment|
|
46
|
+
file.write(segment)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
else
|
51
|
+
response = http.request_get(uri.to_s)
|
52
|
+
CSV.parse(response.read_body, headers: true)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
25
56
|
end
|
26
57
|
end
|
27
|
-
end
|
58
|
+
end
|
data/lib/bearcat/version.rb
CHANGED
@@ -5,16 +5,18 @@ describe Bearcat::Client::ContentMigrations do
|
|
5
5
|
@client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
to_return(json_response('content_migrations', 'upload_success.json'))
|
8
|
+
it 'uploads a file' do
|
9
|
+
stub_post(@client, "/my/upload/path").
|
10
|
+
to_return(json_response('content_migration_files/response.json'))
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
stub_request(:post, "http://host/files_api").
|
13
|
+
to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
stub_post(@client, '/confirm').to_return(json_response('content_migration_files/upload_success.json'))
|
16
|
+
|
17
|
+
opts = {migration_type: 'canvas_cartridge_importer', pre_attachment: {name: 'cc.imscc', size: '2034'}}
|
18
|
+
response = @client.upload_content_package('my/upload/path', fixture('cc.imscc'), opts)
|
19
|
+
expect(response['id']).to eq 293
|
20
|
+
end
|
19
21
|
|
20
22
|
end
|
@@ -36,7 +36,7 @@ describe Bearcat::Client::Quizzes do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'returns a quiz assignment override' do
|
39
|
-
|
39
|
+
stub_get(@client, "/api/v1/courses/1/quizzes/assignment_overrides?quiz_assignment_overrides%5B%5D%5Bquiz_ids%5D=13").to_return(json_response("quizzes/quiz_assignment_override.json"))
|
40
40
|
quiz_overrides = @client.quiz_assignment_overrides('1',{:quiz_assignment_overrides => [{ :quiz_ids => 13 }] })
|
41
41
|
quiz_overrides.class.should eq(Hash)
|
42
42
|
quiz_overrides['quiz_assignment_overrides'].first['quiz_id'].should eq(1014)
|
@@ -35,4 +35,43 @@ describe Bearcat::Client::Reports do
|
|
35
35
|
status['report'] == 'last_user_access_csv'
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
context '#download_report' do
|
39
|
+
it 'downloads a report to memory' do
|
40
|
+
report = IO.read(fixture('file.csv'))
|
41
|
+
stub_request(:head, 'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string').to_return(status: 200, body: report)
|
42
|
+
stub_request(:get, 'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string').to_return(status: 200, body: report)
|
43
|
+
csv = @client.download_report('https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string')
|
44
|
+
expect(csv.count).to eq 4
|
45
|
+
expect(csv.first.fields).to eq ['132',nil,'Alg202CR','Algebra 2 Semester 2 Credit Recovery','11',nil,'1',nil,'unpublished',nil,nil,'false']
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'downloads a report to disk' do
|
49
|
+
report = IO.read(fixture('file.csv'))
|
50
|
+
tempfile = Tempfile.new('report')
|
51
|
+
stub_request(:head, 'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string').to_return(status: 200, body: report)
|
52
|
+
stub_request(:get,'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string').to_return(status: 200, body: report)
|
53
|
+
@client.download_report('https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string', tempfile)
|
54
|
+
csv = CSV.read(tempfile, headers: true)
|
55
|
+
expect(csv.count).to eq 4
|
56
|
+
expect(csv.first.fields).to eq ['132',nil,'Alg202CR','Algebra 2 Semester 2 Credit Recovery','11',nil,'1',nil,'unpublished',nil,nil,'false']
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'follows redirects' do
|
60
|
+
report = IO.read(fixture('file.csv'))
|
61
|
+
tempfile = Tempfile.new('report')
|
62
|
+
stub_request(:head, 'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string')
|
63
|
+
.to_return(status: 302, body: 'You are being redirected',headers: {'Location' => 'https://cluster1-files.instructure.com/files/1/download?download_frd=1&sf_verifier=verifier=1478139862&user_id=1&verifier=verifier'})
|
64
|
+
stub_request(:head, 'https://cluster1-files.instructure.com/files/1/download?download_frd=1&sf_verifier=verifier=1478139862&user_id=1&verifier=verifier')
|
65
|
+
.to_return(status: 302, body: 'You are being redirected', headers: {'Location' => 'https://instructure-uploads.s3.amazonaws.com/account_1/attachments/1/assignment_submission.csv'})
|
66
|
+
stub_request(:head, 'https://instructure-uploads.s3.amazonaws.com/account_1/attachments/1/assignment_submission.csv')
|
67
|
+
.to_return(status: 200)
|
68
|
+
stub_request(:get, 'https://instructure-uploads.s3.amazonaws.com/account_1/attachments/1/assignment_submission.csv')
|
69
|
+
.to_return(status: 200, body: report)
|
70
|
+
@client.download_report('https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string', tempfile)
|
71
|
+
csv = CSV.read(tempfile, headers: true)
|
72
|
+
expect(csv.count).to eq 4
|
73
|
+
expect(csv.first.fields).to eq ['132',nil,'Alg202CR','Algebra 2 Semester 2 Credit Recovery','11',nil,'1',nil,'unpublished',nil,nil,'false']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": 1,
|
4
|
+
"name": "2010",
|
5
|
+
"max_membership": null,
|
6
|
+
"is_public": false,
|
7
|
+
"join_level": "invitation_only",
|
8
|
+
"group_category_id": 22446,
|
9
|
+
"description": null,
|
10
|
+
"members_count": 7,
|
11
|
+
"storage_quota_mb": 50,
|
12
|
+
"context_type": "Account",
|
13
|
+
"account_id": 97006,
|
14
|
+
"avatar_url": null,
|
15
|
+
"role": null,
|
16
|
+
"leader": null,
|
17
|
+
"sis_group_id": null,
|
18
|
+
"sis_import_id": null,
|
19
|
+
"has_submission": false,
|
20
|
+
"concluded": false
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"id": 3,
|
24
|
+
"name": "UI Test Groups",
|
25
|
+
"max_membership": null,
|
26
|
+
"is_public": false,
|
27
|
+
"join_level": "invitation_only",
|
28
|
+
"group_category_id": 13091,
|
29
|
+
"description": null,
|
30
|
+
"members_count": 6,
|
31
|
+
"storage_quota_mb": 50,
|
32
|
+
"context_type": "Account",
|
33
|
+
"account_id": 97006,
|
34
|
+
"avatar_url": null,
|
35
|
+
"role": null,
|
36
|
+
"leader": null,
|
37
|
+
"sis_group_id": null,
|
38
|
+
"sis_import_id": null,
|
39
|
+
"has_submission": false,
|
40
|
+
"concluded": false
|
41
|
+
}
|
42
|
+
]
|
@@ -0,0 +1,5 @@
|
|
1
|
+
canvas_course_id,course_id,short_name,long_name,canvas_account_id,account_id,canvas_term_id,term_id,status,start_date,end_date,created_by_sis
|
2
|
+
132,,Alg202CR,Algebra 2 Semester 2 Credit Recovery,11,,1,,unpublished,,,false
|
3
|
+
78,,mark,mark alsdorf,3,,1,,unpublished,,,false
|
4
|
+
64,,PhySci102standard,Physical Science 1 Semester 2 Standard,6,,1,,deleted,,,false
|
5
|
+
37,,A2,Algebra 2,9,,1,,unpublished,,,false
|
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.3.
|
4
|
+
version: 1.3.3
|
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: 2016-
|
11
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- spec/fixtures/account_admins.json
|
174
174
|
- spec/fixtures/account_courses.json
|
175
175
|
- spec/fixtures/account_grading_standards.json
|
176
|
+
- spec/fixtures/account_groups.json
|
176
177
|
- spec/fixtures/account_reports.json
|
177
178
|
- spec/fixtures/account_reports_index.json
|
178
179
|
- spec/fixtures/account_reports_result_success.json
|
@@ -234,6 +235,7 @@ files:
|
|
234
235
|
- spec/fixtures/edited_group_category.json
|
235
236
|
- spec/fixtures/enroll_student.json
|
236
237
|
- spec/fixtures/enrollment_terms.json
|
238
|
+
- spec/fixtures/file.csv
|
237
239
|
- spec/fixtures/gradebook_history.json
|
238
240
|
- spec/fixtures/group.json
|
239
241
|
- spec/fixtures/group_categories.json
|
@@ -338,6 +340,7 @@ test_files:
|
|
338
340
|
- spec/fixtures/account_admins.json
|
339
341
|
- spec/fixtures/account_courses.json
|
340
342
|
- spec/fixtures/account_grading_standards.json
|
343
|
+
- spec/fixtures/account_groups.json
|
341
344
|
- spec/fixtures/account_reports.json
|
342
345
|
- spec/fixtures/account_reports_index.json
|
343
346
|
- spec/fixtures/account_reports_result_success.json
|
@@ -399,6 +402,7 @@ test_files:
|
|
399
402
|
- spec/fixtures/edited_group_category.json
|
400
403
|
- spec/fixtures/enroll_student.json
|
401
404
|
- spec/fixtures/enrollment_terms.json
|
405
|
+
- spec/fixtures/file.csv
|
402
406
|
- spec/fixtures/gradebook_history.json
|
403
407
|
- spec/fixtures/group.json
|
404
408
|
- spec/fixtures/group_categories.json
|