eat 0.1.2 → 0.1.3
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.
- data/README.rdoc +3 -3
- data/eat.gemspec +2 -0
- data/lib/eat.rb +18 -22
- data/lib/eat/version.rb +1 -1
- data/test/test_eat.rb +4 -0
- metadata +27 -5
data/README.rdoc
CHANGED
@@ -15,9 +15,9 @@ Try <tt>#eat</tt>, which ALWAYS returns a <tt>String</tt>:
|
|
15
15
|
|
16
16
|
==Options
|
17
17
|
|
18
|
-
eat('http://yahoo.com', :timeout => 10)
|
19
|
-
eat('http://yahoo.com', :limit => 1024)
|
20
|
-
eat('https://yahoo.com', :openssl_verify_mode => 'none) # don't bother verifying SSL certificate
|
18
|
+
eat('http://yahoo.com', :timeout => 10) # timeout after 10 seconds
|
19
|
+
eat('http://yahoo.com', :limit => 1024) # only read the first 1024 chars
|
20
|
+
eat('https://yahoo.com', :openssl_verify_mode => 'none') # don't bother verifying SSL certificate
|
21
21
|
|
22
22
|
==Warning: DOES verify SSL certs
|
23
23
|
|
data/eat.gemspec
CHANGED
@@ -18,5 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
+
s.add_runtime_dependency 'httpclient'
|
21
22
|
s.add_development_dependency 'test-unit'
|
23
|
+
s.add_development_dependency 'rake'
|
22
24
|
end
|
data/lib/eat.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'singleton'
|
3
2
|
|
4
3
|
# http://weblog.jamisbuck.org/2007/2/7/infinity
|
5
4
|
unless defined?(::Infinity)
|
@@ -20,9 +19,7 @@ module Eat
|
|
20
19
|
# eat('http://brighterplanet.com', :timeout => 10) #=> '...'
|
21
20
|
# eat('http://brighterplanet.com', :limit => 1) #=> '.'
|
22
21
|
def eat(url, options = {})
|
23
|
-
|
24
|
-
limit = options[:limit] || options['limit'] || ::Infinity
|
25
|
-
openssl_verify_mode = options[:openssl_verify_mode] || options['openssl_verify_mode']
|
22
|
+
limit = options.fetch(:limit, ::Infinity)
|
26
23
|
|
27
24
|
uri = ::URI.parse url.to_s
|
28
25
|
|
@@ -42,26 +39,25 @@ module Eat
|
|
42
39
|
end
|
43
40
|
|
44
41
|
when 'http', 'https'
|
45
|
-
require '
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
42
|
+
require 'httpclient'
|
43
|
+
timeout = options.fetch(:timeout, 2)
|
44
|
+
openssl_verify_mode = options.fetch(:openssl_verify_mode, ::OpenSSL::SSL::VERIFY_PEER)
|
45
|
+
if openssl_verify_mode == 'none'
|
46
|
+
openssl_verify_mode = ::OpenSSL::SSL::VERIFY_NONE
|
47
|
+
end
|
48
|
+
http = ::HTTPClient.new
|
49
|
+
http.redirect_uri_callback = ::Proc.new { |uri, res| ::URI.parse(res.header['location'][0]) }
|
50
|
+
http.receive_timeout = timeout
|
51
|
+
if uri.scheme == 'https'
|
52
|
+
http.ssl_config.verify_mode = openssl_verify_mode
|
53
|
+
end
|
54
|
+
catch :stop do
|
55
|
+
http.get_content(uri.to_s) do |chunk|
|
56
|
+
throw :stop if read_so_far > limit
|
57
|
+
read_so_far += chunk.length
|
58
|
+
body << chunk
|
62
59
|
end
|
63
60
|
end
|
64
|
-
|
65
61
|
end
|
66
62
|
|
67
63
|
limit == ::Infinity ? body.join : body.join[0...limit]
|
data/lib/eat/version.rb
CHANGED
data/test/test_eat.rb
CHANGED
@@ -70,4 +70,8 @@ class TestEat < Test::Unit::TestCase
|
|
70
70
|
eat 'https://foo.bar.brighterplanet.com', :openssl_verify_mode => 'none'
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
def test_reads_compressed
|
75
|
+
assert eat('http://www.sears.com/shc/s/p_10153_12605_07692286000P?prdNo=8&blockNo=8&blockType=G8').include?('New Balance')
|
76
|
+
end
|
73
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httpclient
|
16
|
+
requirement: &2172837000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2172837000
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: test-unit
|
16
|
-
requirement: &
|
27
|
+
requirement: &2172836540 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2172836540
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &2172836120 !ruby/object:Gem::Requirement
|
17
39
|
none: false
|
18
40
|
requirements:
|
19
41
|
- - ! '>='
|
@@ -21,7 +43,7 @@ dependencies:
|
|
21
43
|
version: '0'
|
22
44
|
type: :development
|
23
45
|
prerelease: false
|
24
|
-
version_requirements: *
|
46
|
+
version_requirements: *2172836120
|
25
47
|
description: A (better?) replacement for open-uri. Gets the contents of local and
|
26
48
|
remote files as a String, no questions asked.
|
27
49
|
email:
|
@@ -60,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
82
|
version: '0'
|
61
83
|
requirements: []
|
62
84
|
rubyforge_project: eat
|
63
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.10
|
64
86
|
signing_key:
|
65
87
|
specification_version: 3
|
66
88
|
summary: ! 'Defines an #eat method that takes local and remote paths and returns the
|