bearcat 1.5.38 → 1.5.39

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
2
  SHA256:
3
- metadata.gz: 93e58f81247055b990fa17d5d98f823c253a28c383e26a8bb5e908befb5d845d
4
- data.tar.gz: a1179323c73208512485325e1c4263e4e49bb9e3c7d9682c5147e3a3d9fc32aa
3
+ metadata.gz: 162fc05f04d1d475f69cdd6cab1d449539d288284cb89868487be991922da485
4
+ data.tar.gz: 936bfa6f545ce8bd7f0fe81c15f938d1232fcbdd3685869caae7e8c47ca7aba0
5
5
  SHA512:
6
- metadata.gz: d26752bb5749819f4aedf02873ee118834b6bc69aaaec52e8ae8281dc9fe239e4947ae401a9022850ba21f2c06d7e53f1907a8cc90938b4602af42918eda89e1
7
- data.tar.gz: ba0107db287c5962e3d3291b2b8dc0695887ce74d14f4217c2956e5d648c85219249564db5fba43d7b347e238d1d654001a5e1574b5cc0e15e6aa797af9235e0
6
+ metadata.gz: 63da23efc98f40c13824887429bd5df839054a6d0c28f14ce213745ad7811b2c453f34a9ee1e31871c42928017f9f1fee2d7a02744dc8880c621ba25a3efb6b1
7
+ data.tar.gz: 77094d36014b3ffded25baf37d58647877ae7689691f673bc2606407be493e1120f388437172ff43ebc2ccce0e55f20d32aeaa576b6ef49e239b4e2add0ca225
@@ -14,34 +14,20 @@ module Bearcat
14
14
  end
15
15
 
16
16
  def download_report(url, save_location=nil)
17
- #This method takes the verified URL returned in a Canvas report (attachment['url']), and if
18
- #a save_location is included, it will download it in chunks to the disk to save memory. You
19
- #can also download the report to memory if you do not include a save location.
20
- attempts = 0
21
- begin
22
- uri = URI.parse(url)
23
- http = Net::HTTP.new(uri.host, uri.port)
24
- http.use_ssl = true if url.start_with?('https')
25
- response = http.head(uri.to_s)
26
- url = response['Location']
27
- attempts += 1
28
- end while attempts <= 5 && (response.code == '301' || response.code == '302' || response.code == '307')
29
- http = Net::HTTP.new(uri.host, uri.port)
30
- http.use_ssl = true if uri.to_s.start_with?('https')
17
+ require 'open-uri'
18
+ open_uri_stream = URI.open(url, {
19
+ 'User-Agent' => "Bearcat/#{Bearcat::VERSION} (#{RUBY_PLATFORM})",
20
+ 'Authorization' => "Bearer #{config[:token]}"
21
+ })
22
+
31
23
  if save_location
32
- File.open(save_location, 'wb') do |file|
33
- http.request_get(uri.to_s) do |resp|
34
- resp.read_body do |segment|
35
- file.write(segment)
36
- end
37
- end
38
- end
24
+ save_location = save_location.path if save_location.respond_to?(:path)
25
+ IO.copy_stream(open_uri_stream, save_location)
26
+ save_location
39
27
  else
40
- response = http.request_get(uri.to_s)
41
- CSV.parse(response.read_body, headers: true)
28
+ CSV.parse(open_uri_stream.read, headers: true)
42
29
  end
43
30
  end
44
-
45
31
  end
46
32
  end
47
33
  end
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.5.38' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.5.39' unless defined?(Bearcat::VERSION)
3
3
  end
@@ -48,7 +48,6 @@ describe Bearcat::Client::Reports do
48
48
  it 'downloads a report to disk' do
49
49
  report = IO.read(fixture('file.csv'))
50
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
51
  stub_request(:get,'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string').to_return(status: 200, body: report)
53
52
  @client.download_report('https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string', tempfile)
54
53
  csv = CSV.read(tempfile, headers: true)
@@ -59,12 +58,10 @@ describe Bearcat::Client::Reports do
59
58
  it 'follows redirects' do
60
59
  report = IO.read(fixture('file.csv'))
61
60
  tempfile = Tempfile.new('report')
62
- stub_request(:head, 'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string')
61
+ stub_request(:get, 'https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string')
63
62
  .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')
63
+ stub_request(:get, 'https://cluster1-files.instructure.com/files/1/download?download_frd=1&sf_verifier=verifier=1478139862&user_id=1&verifier=verifier')
65
64
  .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
65
  stub_request(:get, 'https://instructure-uploads.s3.amazonaws.com/account_1/attachments/1/assignment_submission.csv')
69
66
  .to_return(status: 200, body: report)
70
67
  @client.download_report('https://canvas.instructure.com/files/1/download?download_frd=1&verifier=string', tempfile)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bearcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.38
4
+ version: 1.5.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure CustomDev
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-03-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -429,10 +428,8 @@ files:
429
428
  - spec/fixtures/user_page_views.json
430
429
  - spec/fixtures/user_profile.json
431
430
  - spec/helper.rb
432
- homepage:
433
431
  licenses: []
434
432
  metadata: {}
435
- post_install_message:
436
433
  rdoc_options: []
437
434
  require_paths:
438
435
  - lib
@@ -447,8 +444,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
447
444
  - !ruby/object:Gem::Version
448
445
  version: '0'
449
446
  requirements: []
450
- rubygems_version: 3.5.16
451
- signing_key:
447
+ rubygems_version: 3.6.7
452
448
  specification_version: 4
453
449
  summary: Canvas API
454
450
  test_files: