wasapi_client 0.1.0 → 0.2.0

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: 62152f5af7e6336feaf5798316ca24ff79b482d9d232cb56c2b06da3758180fd
4
- data.tar.gz: e4b18ec16684c28a59bba87d31d547e333374fb4f54b31e388a475b5633987c9
3
+ metadata.gz: 7ec626b5ee6e6398e898e50939949f7b93d0a0b4cea6aeaa574ced99c5851fef
4
+ data.tar.gz: 4e93d3010713536b39fb2e6113c25fcf0c7ef2571ee775abe4b4ce01afdb4601
5
5
  SHA512:
6
- metadata.gz: 83e3974f8e4ab44afd47a0d8d1e0fc70b1852ec49e3a51f530decfce7035cc80341f923305bc806e87804cfa25c200393ab0ea118cc6ba59997a8d5d9b50da18
7
- data.tar.gz: 68068f5f03f933662a9c28f03febe9559d2985576843c8e1cd7687bf7d73d2fba93844053b6ee89bd8f66fec2bdee2cf15ff908f187f019177b19bc01f12feff
6
+ metadata.gz: 6e99bfd867c73e2d2500d0ad558796429ae88aeb466d7d087b4a0e32824a50421d912544351365eff04001804ec37b2727b7731076211cfe7c0863129a765ba7
7
+ data.tar.gz: 21427620fefc1729a793bc35e9be8e26324dc98c703e6cb40c0ce93f9f658ec204af67d95ff5d8431bd86598bb86c272e27db0d48b23b7ebdfd17343ac5b2a2d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wasapi_client (0.1.0)
4
+ wasapi_client (0.2.0)
5
5
  activesupport
6
6
  digest
7
7
  faraday
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class WasapiClient
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/wasapi_client.rb CHANGED
@@ -36,6 +36,7 @@ class WasapiClient
36
36
  # Set up an authenticated GET request for the account
37
37
  def connection(url)
38
38
  Faraday.new(url:) do |conn|
39
+ conn.use Faraday::Response::RaiseError
39
40
  conn.request :authorization, :basic, username, password
40
41
  conn.request :retry, max: 3, interval: 0.05, backoff_factor: 2
41
42
  conn.response :follow_redirects
@@ -162,10 +163,16 @@ class WasapiClient
162
163
  File.open(filepath, 'wb') do |file|
163
164
  # Use streaming to write the file in chunks. WARCs can be large.
164
165
  connection(url).get do |req|
165
- req.options.on_data = proc { |chunk, _| file.write(chunk) }
166
+ req.options.on_data = proc do |chunk, _size, env|
167
+ if env.status >= 400
168
+ FileUtils.rm_f(filepath) if File.exist?(filepath)
169
+ raise "Failed to download file from #{url}: #{env.status}"
170
+ end
171
+
172
+ file.write(chunk)
173
+ end
166
174
  end
167
175
  end
168
-
169
176
  filepath
170
177
  end
171
178
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasapi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laura Wrubel