url_fetcher 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a80bd44f053156a452d45a80f43ef5b468fa19e
4
- data.tar.gz: ba7077dedcf80cf86ee76b8d6a37f2f431fd42f6
3
+ metadata.gz: 8c6eed420473ae21636daa796c36f23fb6dbea52
4
+ data.tar.gz: f5055142823e55cc5bb58dd1bdfa4d4c2e381e3e
5
5
  SHA512:
6
- metadata.gz: fede6c50ad1bbdbf67e7ff4281828b604d2696efa6d77c18a01697d5175c105ceebd35cbb2f965caed2036ece8b851c3e031069425d9c89eafe7846ee5591473
7
- data.tar.gz: c34c7070a64cb0d1715d347f211a6fd4b831d549949d70ff2d8720e54420826d35df86a7ade93a61523f4ee422e36a6b747b4dbc042088f4d79c0bd062de89bb
6
+ metadata.gz: 082a8bf25261e514cb2f1bc41e5bf85063d0147689d3cb25b07239dd31839db54bad9774910683fb0ea9b44d8e9e78ce7cf51a92fab7c2d7ecfa64d265ea0d89
7
+ data.tar.gz: 54a1b9c69359f7e8886a3688200e8f24f18f96a35a7d9c09aa839e6b1b8896f63215043d3f08e13f4b16693b348a9877d613a488a588ee4a68b991dffcc471db
data/README.md CHANGED
@@ -18,8 +18,10 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ```ruby
21
22
  response = UrlFetcher.new("http://example.com/large_file")
22
23
  response.body # Returns a stream to a the body from a Tempfile on disk.
24
+ ```
23
25
 
24
26
  ## Contributing
25
27
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -13,6 +13,16 @@ class UrlFetcher
13
13
  end
14
14
  end
15
15
 
16
+ class FileTooBig < Error
17
+ attr_reader :size
18
+ def initialize(size)
19
+ @size = size
20
+ end
21
+
22
+ def to_s
23
+ "File too big (#{size} bytes)"
24
+ end
25
+ end
16
26
 
17
27
  class CircularRedirect < Error
18
28
  attr_reader :url
data/lib/url_fetcher.rb CHANGED
@@ -90,7 +90,7 @@ class UrlFetcher
90
90
  end
91
91
  if resp.is_a?(Net::HTTPSuccess) && resp.class.body_permitted?
92
92
  content_length = resp["Content-Length"].to_i
93
- raise "File to big (#{content_length} bytes" if content_length > (options[:max_size] || 10 * MEGABYTE)
93
+ raise FileTooBig.new(content_length) if content_length > (options[:max_size] || 10 * MEGABYTE)
94
94
  tempfile = Tempfile.new("url_fetcher", :encoding => 'ascii-8bit')
95
95
  resp.read_body(tempfile)
96
96
  tempfile.close
@@ -123,6 +123,6 @@ describe UrlFetcher do
123
123
  WebMock.stub_request(:get, "http://example.com/test").to_return(:status => 200, :body => "Hello", :headers => {"Content-Length" => 1001})
124
124
  expect do
125
125
  UrlFetcher.new("http://example.com/test", :max_size => 1000)
126
- end.to raise_error
126
+ end.to raise_error(UrlFetcher::FileTooBig)
127
127
  end
128
128
  end
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.2
4
+ version: 1.0.3
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-12 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable