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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/wasapi_client/version.rb +1 -1
- data/lib/wasapi_client.rb +9 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ec626b5ee6e6398e898e50939949f7b93d0a0b4cea6aeaa574ced99c5851fef
|
4
|
+
data.tar.gz: 4e93d3010713536b39fb2e6113c25fcf0c7ef2571ee775abe4b4ce01afdb4601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e99bfd867c73e2d2500d0ad558796429ae88aeb466d7d087b4a0e32824a50421d912544351365eff04001804ec37b2727b7731076211cfe7c0863129a765ba7
|
7
|
+
data.tar.gz: 21427620fefc1729a793bc35e9be8e26324dc98c703e6cb40c0ce93f9f658ec204af67d95ff5d8431bd86598bb86c272e27db0d48b23b7ebdfd17343ac5b2a2d
|
data/Gemfile.lock
CHANGED
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
|
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
|
|