down 4.3.0 → 4.4.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/CHANGELOG.md +6 -0
- data/README.md +16 -4
- data/lib/down/http.rb +12 -5
- data/lib/down/net_http.rb +6 -1
- data/lib/down/version.rb +1 -1
- data/lib/down/wget.rb +7 -1
- 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: a80bdc5c9a560cb80bb1ad7ff6ff5d37c7286516
|
|
4
|
+
data.tar.gz: f9015c19819666eaeeaa13dbcf5e9537e63699f9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3a250ed7339d70e339f8591e260a85925395add6f18d8b4c2aa5cea40bfa420442606e0bdfa96b76df2661beec0830b1c011d609a16d15996bca80072b41c5e9
|
|
7
|
+
data.tar.gz: 884481d0a865cf7664715a77fcd0ae9a43fc36aa6dc0bc7729197c1dea6c1382aaca80925a2c6411390ca2c72e6ea825e2be41681399c59bd0cc0e1fe403a020
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 4.4.0 (2018-04-12)
|
|
2
|
+
|
|
3
|
+
* Add `:method` option to `Down::Http` for specifying the request method (@janko-m)
|
|
4
|
+
|
|
5
|
+
* Set default timeout of 30 for each operation to all backends (@janko-m)
|
|
6
|
+
|
|
1
7
|
## 4.3.0 (2018-03-11)
|
|
2
8
|
|
|
3
9
|
* Accept CLI arguments as a list of symbols in `Down::Wget#download` (@janko-m)
|
data/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Down allows you to pass a `:max_size` option:
|
|
|
41
41
|
|
|
42
42
|
```rb
|
|
43
43
|
Down.download("http://example.com/image.jpg", max_size: 5 * 1024 * 1024) # 5 MB
|
|
44
|
-
#
|
|
44
|
+
# Down::TooLarge: file is too large (max is 5MB)
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
What is the advantage over simply checking size after downloading? Well, Down
|
|
@@ -57,7 +57,6 @@ specific location on disk, you can specify the `:destination` option:
|
|
|
57
57
|
|
|
58
58
|
```rb
|
|
59
59
|
Down.download("http://example.com/image.jpg", destination: "/path/to/destination")
|
|
60
|
-
#=> nil
|
|
61
60
|
```
|
|
62
61
|
|
|
63
62
|
### Basic authentication
|
|
@@ -355,7 +354,7 @@ Net::HTTP include:
|
|
|
355
354
|
All additional options will be forwarded to `HTTP::Client#request`:
|
|
356
355
|
|
|
357
356
|
```rb
|
|
358
|
-
Down::Http.download("http://example.org/image.jpg",
|
|
357
|
+
Down::Http.download("http://example.org/image.jpg", headers: { "Foo" => "Bar" })
|
|
359
358
|
Down::Http.open("http://example.org/image.jpg", follow: { max_hops: 0 })
|
|
360
359
|
```
|
|
361
360
|
|
|
@@ -370,7 +369,7 @@ end
|
|
|
370
369
|
You can also initialize the backend with default options:
|
|
371
370
|
|
|
372
371
|
```rb
|
|
373
|
-
http = Down::Http.new(
|
|
372
|
+
http = Down::Http.new(headers: { "Foo" => "Bar" })
|
|
374
373
|
# or
|
|
375
374
|
http = Down::Http.new(HTTP.timeout(connect: 3))
|
|
376
375
|
|
|
@@ -378,6 +377,19 @@ http.download("http://example.com/image.jpg")
|
|
|
378
377
|
http.open("http://example.com/image.jpg")
|
|
379
378
|
```
|
|
380
379
|
|
|
380
|
+
#### Request method
|
|
381
|
+
|
|
382
|
+
By default `Down::Http` makes a `GET` request to the specified endpoint, but you
|
|
383
|
+
can specify a different request method using the `:method` option:
|
|
384
|
+
|
|
385
|
+
```rb
|
|
386
|
+
Down::Http.download("http://example.org/image.jpg", method: :post)
|
|
387
|
+
Down::Http.open("http://example.org/image.jpg", method: :post)
|
|
388
|
+
|
|
389
|
+
down = Down::Http.new(method: :post)
|
|
390
|
+
down.download("http://example.org/image.jpg")
|
|
391
|
+
```
|
|
392
|
+
|
|
381
393
|
### Wget (experimental)
|
|
382
394
|
|
|
383
395
|
```rb
|
data/lib/down/http.rb
CHANGED
|
@@ -15,8 +15,15 @@ end
|
|
|
15
15
|
module Down
|
|
16
16
|
class Http < Backend
|
|
17
17
|
def initialize(client_or_options = {})
|
|
18
|
-
options
|
|
19
|
-
|
|
18
|
+
options = client_or_options.is_a?(HTTP::Client) ? client_or_options.default_options.to_hash : client_or_options
|
|
19
|
+
|
|
20
|
+
@method = options.delete(:method) || :get
|
|
21
|
+
@options = {
|
|
22
|
+
headers: { "User-Agent" => "Down/#{Down::VERSION}" },
|
|
23
|
+
follow: { max_hops: 2 },
|
|
24
|
+
timeout_class: HTTP::Timeout::PerOperation,
|
|
25
|
+
timeout_options: { write_timeout: 30, connect_timeout: 30, read_timeout: 30 }
|
|
26
|
+
}.merge(options)
|
|
20
27
|
end
|
|
21
28
|
|
|
22
29
|
def download(url, max_size: nil, progress_proc: nil, content_length_proc: nil, destination: nil, **options, &block)
|
|
@@ -58,7 +65,7 @@ module Down
|
|
|
58
65
|
end
|
|
59
66
|
|
|
60
67
|
def open(url, rewindable: true, **options, &block)
|
|
61
|
-
response =
|
|
68
|
+
response = request(url, **options, &block)
|
|
62
69
|
|
|
63
70
|
response_error!(response) unless response.status.success?
|
|
64
71
|
|
|
@@ -78,13 +85,13 @@ module Down
|
|
|
78
85
|
@default_client ||= HTTP::Client.new(@options)
|
|
79
86
|
end
|
|
80
87
|
|
|
81
|
-
def
|
|
88
|
+
def request(url, method: @method, **options, &block)
|
|
82
89
|
url = process_url(url, options)
|
|
83
90
|
|
|
84
91
|
client = default_client
|
|
85
92
|
client = block.call(client) if block
|
|
86
93
|
|
|
87
|
-
client.
|
|
94
|
+
client.send(method.to_s.downcase, url, options)
|
|
88
95
|
rescue => exception
|
|
89
96
|
request_error!(exception)
|
|
90
97
|
end
|
data/lib/down/net_http.rb
CHANGED
|
@@ -12,7 +12,12 @@ require "cgi"
|
|
|
12
12
|
module Down
|
|
13
13
|
class NetHttp < Backend
|
|
14
14
|
def initialize(options = {})
|
|
15
|
-
@options = {
|
|
15
|
+
@options = {
|
|
16
|
+
"User-Agent" => "Down/#{Down::VERSION}",
|
|
17
|
+
max_redirects: 2,
|
|
18
|
+
open_timeout: 30,
|
|
19
|
+
read_timeout: 30,
|
|
20
|
+
}.merge(options)
|
|
16
21
|
end
|
|
17
22
|
|
|
18
23
|
def download(url, options = {})
|
data/lib/down/version.rb
CHANGED
data/lib/down/wget.rb
CHANGED
|
@@ -16,7 +16,13 @@ require "cgi"
|
|
|
16
16
|
module Down
|
|
17
17
|
class Wget < Backend
|
|
18
18
|
def initialize(*arguments)
|
|
19
|
-
@arguments = [
|
|
19
|
+
@arguments = [
|
|
20
|
+
user_agent: "Down/#{Down::VERSION}",
|
|
21
|
+
max_redirect: 2,
|
|
22
|
+
dns_timeout: 30,
|
|
23
|
+
connect_timeout: 30,
|
|
24
|
+
read_timeout: 30,
|
|
25
|
+
] + arguments
|
|
20
26
|
end
|
|
21
27
|
|
|
22
28
|
def download(url, *args, max_size: nil, content_length_proc: nil, progress_proc: nil, destination: nil, **options)
|
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.
|
|
4
|
+
version: 4.4.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: 2018-
|
|
11
|
+
date: 2018-04-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|