url_fetcher 1.1.5 → 1.1.6
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/VERSION +1 -1
- data/lib/url_fetcher.rb +14 -2
- data/spec/url_fetcher_spec.rb +6 -0
- 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: 8523decc234223ef23d0ad21e091b8e02b10697d
|
4
|
+
data.tar.gz: 54d317200ebbd7921eef0def888b0932a23a2f2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82a6284bcd4a7096f8828b950431adb7940d2c9c2ad1b8e932ce16bf912ba4dac5fde62065c93ba4045028b97f8b8415f6fccb5de8fdebd0a6ebec56c26e5674
|
7
|
+
data.tar.gz: ad131782b83ac319e3819139c278f8f705c4c9a8f36705a1418aa494d54669521a2c64bde94dab23fa2990750504d3b4844d4e6714e55d2dbef494ad5c804e44
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.6
|
data/lib/url_fetcher.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require "url_fetcher/errors"
|
2
1
|
require "net/http"
|
3
2
|
require "openssl"
|
4
|
-
require "
|
3
|
+
require "addressable/uri"
|
5
4
|
require "tempfile"
|
5
|
+
require "url_fetcher/errors"
|
6
6
|
|
7
7
|
# This class will fetch the contents of a URL and store them in a Tempfile. The
|
8
8
|
# results are exposed as a stream so you don't need to read potentialy huge responses
|
@@ -22,6 +22,7 @@ class UrlFetcher
|
|
22
22
|
# * :max_size (10 megabytes)- The maximum size in bytes that should be fetched.
|
23
23
|
# * :open_timeout (10) - Time in seconds to wait for a connection to be established.
|
24
24
|
# * :read_timeout (20) - Time in seconds to wait for reading the HTTP response.
|
25
|
+
# * :headers ("Accept" => "*")- Hash of headers to send with request.
|
25
26
|
def initialize(url, options = {}, &redirect_hook)
|
26
27
|
@url = url
|
27
28
|
@redirect_hook = redirect_hook
|
@@ -94,6 +95,17 @@ class UrlFetcher
|
|
94
95
|
Net::HTTP::Get.new(uri.request_uri)
|
95
96
|
end
|
96
97
|
|
98
|
+
if options[:headers]
|
99
|
+
options[:headers].each do |name, value|
|
100
|
+
name = name.to_s
|
101
|
+
values = Array(value)
|
102
|
+
request[name] = values[0].to_s
|
103
|
+
values[1, values.length].each do |val|
|
104
|
+
request.add_field(name, val.to_s)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
97
109
|
response = http.request(request) do |resp|
|
98
110
|
unless resp.is_a?(Net::HTTPSuccess) || resp.is_a?(Net::HTTPRedirection)
|
99
111
|
resp.value # Raises an appropriate HTTP error
|
data/spec/url_fetcher_spec.rb
CHANGED
@@ -43,6 +43,12 @@ describe UrlFetcher do
|
|
43
43
|
expect(url_fetcher.header("content-length")).to eql("5")
|
44
44
|
expect(url_fetcher.body.read).to eql("Hello")
|
45
45
|
end
|
46
|
+
|
47
|
+
it "should send custom headers" do
|
48
|
+
WebMock.stub_request(:get, "https://example.com/test").with(:headers => {"Accept" => ["image/jpeg", "image/gif"]}).to_return(:status => 200, :body => "Hello", :headers => {"Content-Length" => 5})
|
49
|
+
url_fetcher = UrlFetcher.new("https://example.com/test", :headers => {"Accept" => ["image/jpeg", "image/gif"]})
|
50
|
+
expect(url_fetcher).to be_success
|
51
|
+
end
|
46
52
|
|
47
53
|
it "should honor redirects" do
|
48
54
|
WebMock.stub_request(:get, "http://example.com/test1").to_return(:status => 301, :headers => {"Location" => "http://example.com/test2"})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- weheartit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|