url_fetcher 1.0.3 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c6eed420473ae21636daa796c36f23fb6dbea52
4
- data.tar.gz: f5055142823e55cc5bb58dd1bdfa4d4c2e381e3e
3
+ metadata.gz: 9991d0da25a1994e5e1d046ce3f267473ca50158
4
+ data.tar.gz: b908958f96b23b0777be7b4db2017a124f2837e0
5
5
  SHA512:
6
- metadata.gz: 082a8bf25261e514cb2f1bc41e5bf85063d0147689d3cb25b07239dd31839db54bad9774910683fb0ea9b44d8e9e78ce7cf51a92fab7c2d7ecfa64d265ea0d89
7
- data.tar.gz: 54a1b9c69359f7e8886a3688200e8f24f18f96a35a7d9c09aa839e6b1b8896f63215043d3f08e13f4b16693b348a9877d613a488a588ee4a68b991dffcc471db
6
+ metadata.gz: 4fd94a1f0dfbb1240e3e5ddc4184ca09c3e408a717c099c13b385b3f15387dac8c4eca17970053ccf281a1f872335dc939c2c84e1adfce4e7264496bfdad0db3
7
+ data.tar.gz: 426266e185736573cb24e2b6ac5c0787e3e2458b58c155857b263b7b6ff2a195a8decbc65bb7da0d7e92f54a67ee928c140c8105f085342ebf7476e96eb7be1f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.1.0
data/lib/url_fetcher.rb CHANGED
@@ -29,10 +29,18 @@ class UrlFetcher
29
29
  @response = fetch_response(@url, options)
30
30
  end
31
31
 
32
- # Return an open stream to the downloaded URL.
32
+ # Return a stream to the downloaded URL.
33
33
  def body
34
34
  @response.body if success?
35
35
  end
36
+
37
+ def close
38
+ body.close unless body.closed?
39
+ end
40
+
41
+ def closed?
42
+ body.closed? if body
43
+ end
36
44
 
37
45
  # Get the header with the specified name from the response.
38
46
  def header(name)
@@ -93,7 +101,7 @@ class UrlFetcher
93
101
  raise FileTooBig.new(content_length) if content_length > (options[:max_size] || 10 * MEGABYTE)
94
102
  tempfile = Tempfile.new("url_fetcher", :encoding => 'ascii-8bit')
95
103
  resp.read_body(tempfile)
96
- tempfile.close
104
+ tempfile.rewind
97
105
  end
98
106
  end
99
107
 
@@ -8,8 +8,12 @@ describe UrlFetcher do
8
8
  expect(url_fetcher).to be_success
9
9
  expect(url_fetcher).not_to be_redirect
10
10
  expect(url_fetcher.header("content-length")).to eql("5")
11
- url_fetcher.body.open
11
+ expect(url_fetcher).to_not be_closed
12
+ expect(url_fetcher.body).to_not be_closed
12
13
  expect(url_fetcher.body.read).to eql("Hello")
14
+ url_fetcher.close
15
+ expect(url_fetcher).to be_closed
16
+ expect(url_fetcher.body).to be_closed
13
17
  end
14
18
 
15
19
  it "should perform a POST request" do
@@ -18,7 +22,6 @@ describe UrlFetcher do
18
22
  expect(url_fetcher).to be_success
19
23
  expect(url_fetcher).not_to be_redirect
20
24
  expect(url_fetcher.header("content-length")).to eql("5")
21
- url_fetcher.body.open
22
25
  expect(url_fetcher.body.read).to eql("Hello")
23
26
  end
24
27
 
@@ -37,7 +40,7 @@ describe UrlFetcher do
37
40
  expect(url_fetcher).to be_success
38
41
  expect(url_fetcher).not_to be_redirect
39
42
  expect(url_fetcher.header("content-length")).to eql("5")
40
- expect(url_fetcher.body.open.read).to eql("Hello")
43
+ expect(url_fetcher.body.read).to eql("Hello")
41
44
  end
42
45
 
43
46
  it "should honor redirects" do
@@ -48,7 +51,7 @@ describe UrlFetcher do
48
51
  expect(url_fetcher).to be_success
49
52
  expect(url_fetcher).not_to be_redirect
50
53
  expect(url_fetcher.header("content-length")).to eql("5")
51
- expect(url_fetcher.body.open.read).to eql("Hello")
54
+ expect(url_fetcher.body.read).to eql("Hello")
52
55
  end
53
56
 
54
57
  it "should not honor redirects if :follow_redirects == false" do
@@ -71,7 +74,7 @@ describe UrlFetcher do
71
74
  expect(url_fetcher).to be_success
72
75
  expect(url_fetcher).not_to be_redirect
73
76
  expect(url_fetcher.header("content-length")).to eql("5")
74
- expect(url_fetcher.body.open.read).to eql("Hello")
77
+ expect(url_fetcher.body.read).to eql("Hello")
75
78
  expect(redirects).to eql(["http://example.com/test2", "http://example.com/test3"])
76
79
  end
77
80
 
@@ -115,7 +118,8 @@ describe UrlFetcher do
115
118
  expect(url_fetcher).to be_success
116
119
  expect(url_fetcher).not_to be_redirect
117
120
  expect(url_fetcher.header("content-length")).to eql("5")
118
- expect(url_fetcher.body.open.read).to eql("Hello")
121
+ expect(url_fetcher.body).to_not be_closed
122
+ expect(url_fetcher.body.read).to eql("Hello")
119
123
  expect(url_fetcher.body.path).not_to be_nil
120
124
  end
121
125
 
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.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - weheartit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-16 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.3.0
123
+ rubygems_version: 2.4.5
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Fetch resources from the internetz with circular redirects support