down 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -4
  3. data/down.gemspec +1 -1
  4. data/lib/down.rb +4 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae5eb943b2a1423b964812f6eabaab6e2db3ac80
4
- data.tar.gz: d94df3114f9784599967e67bd74b2efaa53ff0de
3
+ metadata.gz: d6bfc27c3e2b954afac30e137fa798cf1455914a
4
+ data.tar.gz: 3b4dac64774179f307ff94bd235815a404f412f8
5
5
  SHA512:
6
- metadata.gz: 858b972338a5b2252c6674cd55199ce29b491406fba507bac8c86ae8c342c62ca78d9f84bbf7d6f64f3c739e5d15e4328268d0be77e4682da58b1600cb8dda90
7
- data.tar.gz: 33399d6ee408a32882b3077fc88478527fc3a5d3ce2fd1bbd53e14e77df9ff5bb3668e6950b0720d636c30b8d029c1af5b775ca22959fe00dc1a6c60505ae227
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
- Firstly, Down encodes unencoded URLs, `open-uri` will for example trip if the
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, and simply throws `Down::NotFound` error
92
- (because this is what actually happened from the outside perspective).
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "down"
3
- spec.version = "1.1.0"
3
+ spec.version = "2.0.0"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
@@ -11,13 +11,13 @@ module Down
11
11
  module_function
12
12
 
13
13
  def download(url, options = {})
14
- url = URI.encode(URI.decode(url))
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 = URI(url).open({
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(URI(url).path, open_uri_file)
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: 1.1.0
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-01-26 00:00:00.000000000 Z
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake