down 1.1.0 → 2.0.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/README.md +3 -4
- data/down.gemspec +1 -1
- data/lib/down.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6bfc27c3e2b954afac30e137fa798cf1455914a
|
4
|
+
data.tar.gz: 3b4dac64774179f307ff94bd235815a404f412f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eea506a22d4f612acbcd6de0cd5b5a1a8416edb8cd768dc2b3f66b3f4f20a26185b978e1a7502278afb6d94c3b9f3ee909028c36ab184a0b425cd1d5b956c96
|
7
|
+
data.tar.gz: 102506a0f63fd5d87393a9a317bdf2ac60b155fe4467e121000b16c0cd1fe94c444a0383a9ad82a2e40e66fe76ec434d0d6567c5568073dd029a2d01b7a11a84
|
data/README.md
CHANGED
@@ -78,8 +78,7 @@ Down.download "http://example.com/image.jpg",
|
|
78
78
|
|
79
79
|
### Download errors
|
80
80
|
|
81
|
-
|
82
|
-
URL has a space. There are a lot of ways that a download can fail:
|
81
|
+
There are a lot of ways in which a download can fail:
|
83
82
|
|
84
83
|
* URL is really invalid (`URI::InvalidURIError`)
|
85
84
|
* URL is a little bit invalid, e.g. "http:/example.com" (`Errno::ECONNREFUSED`)
|
@@ -88,8 +87,8 @@ URL has a space. There are a lot of ways that a download can fail:
|
|
88
87
|
* Request went into a redirect loop (`RuntimeError`)
|
89
88
|
* Request timeout out (`Timeout::Error`)
|
90
89
|
|
91
|
-
Down unifies all of these errors
|
92
|
-
|
90
|
+
Down unifies all of these errors into one `Down::NotFound` error (because this
|
91
|
+
is what actually happened from the outside perspective).
|
93
92
|
|
94
93
|
### Timeout
|
95
94
|
|
data/down.gemspec
CHANGED
data/lib/down.rb
CHANGED
@@ -11,13 +11,13 @@ module Down
|
|
11
11
|
module_function
|
12
12
|
|
13
13
|
def download(url, options = {})
|
14
|
-
|
14
|
+
uri = URI.parse(url)
|
15
15
|
|
16
16
|
max_size = options.delete(:max_size)
|
17
17
|
progress = options.delete(:progress)
|
18
18
|
timeout = options.delete(:timeout)
|
19
19
|
|
20
|
-
downloaded_file =
|
20
|
+
downloaded_file = uri.open({
|
21
21
|
"User-Agent" => "Down/1.0.0",
|
22
22
|
content_length_proc: proc { |size|
|
23
23
|
raise Down::TooLarge if size && max_size && size > max_size
|
@@ -36,7 +36,7 @@ module Down
|
|
36
36
|
# file extension, so we want to run it against #copy_to_tempfile which
|
37
37
|
# does.
|
38
38
|
open_uri_file = downloaded_file
|
39
|
-
downloaded_file = copy_to_tempfile(
|
39
|
+
downloaded_file = copy_to_tempfile(uri.path, open_uri_file)
|
40
40
|
OpenURI::Meta.init downloaded_file, open_uri_file
|
41
41
|
|
42
42
|
downloaded_file.extend DownloadedFile
|
@@ -44,7 +44,7 @@ module Down
|
|
44
44
|
|
45
45
|
rescue => error
|
46
46
|
raise if error.is_a?(Down::Error)
|
47
|
-
raise Down::NotFound, error.message
|
47
|
+
raise Down::NotFound, "#{error.class}: #{error.message}"
|
48
48
|
end
|
49
49
|
|
50
50
|
def copy_to_tempfile(basename, io)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: down
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|