httparty 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- data/History +17 -0
- data/README.rdoc +3 -2
- data/bin/httparty +9 -3
- data/examples/crack.rb +19 -0
- data/examples/headers_and_user_agents.rb +6 -0
- data/examples/nokogiri_html_parser.rb +22 -0
- data/features/steps/remote_service_steps.rb +1 -1
- data/lib/httparty.rb +32 -28
- data/lib/httparty/parser.rb +2 -2
- data/lib/httparty/request.rb +23 -6
- data/lib/httparty/response.rb +1 -1
- data/lib/httparty/version.rb +1 -1
- data/spec/httparty/parser_spec.rb +10 -0
- data/spec/httparty/request_spec.rb +65 -1
- data/spec/httparty/response_spec.rb +7 -0
- data/spec/httparty_spec.rb +26 -1
- data/spec/support/stub_response.rb +13 -0
- metadata +41 -61
data/History
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
== 0.8.2 2012-04-12
|
2
|
+
* new
|
3
|
+
* add -r to make CLI return failure code if status >= 400
|
4
|
+
* allow blank username from CLI
|
5
|
+
* bug fixes
|
6
|
+
* return nil for null body
|
7
|
+
* automatically deflate responses with a Content-Encoding: x-gzip header
|
8
|
+
* Do not HEAD on POST request with digest authentication
|
9
|
+
* add support for proxy authentication
|
10
|
+
* fix posting data with CLI
|
11
|
+
* require rexml/document if xml format from CLI
|
12
|
+
* support for fragmented responses
|
13
|
+
|
14
|
+
== 0.8.1 2011-10-05
|
15
|
+
* bug fixes
|
16
|
+
* content-encoding header should be removed when automatically inflating the body
|
17
|
+
|
1
18
|
== 0.8.0 2011-09-13
|
2
19
|
* new
|
3
20
|
* switch to multi json/xml for parsing by default
|
data/README.rdoc
CHANGED
@@ -49,6 +49,7 @@ options. Below is an example of how easy it is.
|
|
49
49
|
|
50
50
|
* sudo gem install httparty
|
51
51
|
|
52
|
-
== Docs
|
52
|
+
== Help and Docs
|
53
53
|
|
54
|
-
|
54
|
+
* https://groups.google.com/forum/#!forum/httparty-gem
|
55
|
+
* http://rdoc.info/projects/jnunemaker/httparty
|
data/bin/httparty
CHANGED
@@ -32,9 +32,9 @@ OptionParser.new do |o|
|
|
32
32
|
"--data [BODY]",
|
33
33
|
"Data to put in request body (prefix with '@' for file)") do |d|
|
34
34
|
if d =~ /^@/
|
35
|
-
opts[:
|
35
|
+
opts[:body] = open(d[1..-1]).read
|
36
36
|
else
|
37
|
-
opts[:
|
37
|
+
opts[:body] = d
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -49,11 +49,15 @@ OptionParser.new do |o|
|
|
49
49
|
end
|
50
50
|
|
51
51
|
o.on("-u", "--user [CREDS]", "Use basic authentication. Value should be user:password") do |u|
|
52
|
-
abort "Invalid credentials format. Must be user:password" unless u =~
|
52
|
+
abort "Invalid credentials format. Must be user:password" unless u =~ /.*:.+/
|
53
53
|
user, password = u.split(':')
|
54
54
|
opts[:basic_auth] = { :username => user, :password => password }
|
55
55
|
end
|
56
56
|
|
57
|
+
o.on("-r", "--response-code", "Command fails if response code >= 400") do
|
58
|
+
opts[:response_code] = true
|
59
|
+
end
|
60
|
+
|
57
61
|
o.on("-h", "--help", "Show help documentation") do |h|
|
58
62
|
puts o
|
59
63
|
exit
|
@@ -100,9 +104,11 @@ else
|
|
100
104
|
puts YAML.dump(response.delegate)
|
101
105
|
end
|
102
106
|
when :xml
|
107
|
+
require 'rexml/document'
|
103
108
|
REXML::Document.new(response.body).write(STDOUT, 2)
|
104
109
|
puts
|
105
110
|
else
|
106
111
|
puts response
|
107
112
|
end
|
108
113
|
end
|
114
|
+
exit false if opts[:response_code] && response.code >= 400
|
data/examples/crack.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'crack'
|
3
|
+
|
4
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
require File.join(dir, 'httparty')
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
class Rep
|
9
|
+
include HTTParty
|
10
|
+
|
11
|
+
parser(
|
12
|
+
Proc.new do |body, format|
|
13
|
+
Crack::XML.parse(body)
|
14
|
+
end
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544')
|
19
|
+
pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => 46544})
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# To send custom user agents to identify your application to a web service (or mask as a specific browser for testing), send "User-Agent" as a hash to headers as shown below.
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
APPLICATION_NAME = "Httparty"
|
6
|
+
response = HTTParty.get('http://example.com', :headers => {"User-Agent" => APPLICATION_NAME})
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
|
5
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
require File.join(dir, 'httparty')
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
class HtmlParserIncluded < HTTParty::Parser
|
10
|
+
SupportedFormats.merge!('text/html' => :html)
|
11
|
+
|
12
|
+
def html
|
13
|
+
Nokogiri::HTML(body)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Page
|
18
|
+
include HTTParty
|
19
|
+
parser HtmlParserIncluded
|
20
|
+
end
|
21
|
+
|
22
|
+
pp Page.get('http://www.google.com')
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
|
15
15
|
Given /^that service takes (\d+) seconds to generate a response$/ do |time|
|
16
16
|
@server_response_time = time.to_i
|
17
|
-
@handler.preprocessor =
|
17
|
+
@handler.preprocessor = Proc.new { sleep time.to_i }
|
18
18
|
end
|
19
19
|
|
20
20
|
Given /^a remote deflate service$/ do
|
data/lib/httparty.rb
CHANGED
@@ -41,6 +41,8 @@ module HTTParty
|
|
41
41
|
# [:+body+:] Body of the request. If passed a Hash, will try to normalize it first, by default passing it to ActiveSupport::to_params. Any other kind of object will get used as-is.
|
42
42
|
# [:+http_proxyaddr+:] Address of proxy server to use.
|
43
43
|
# [:+http_proxyport+:] Port of proxy server to use.
|
44
|
+
# [:+http_proxyuser+:] User for proxy server authentication.
|
45
|
+
# [:+http_proxypass+:] Password for proxy server authentication.
|
44
46
|
# [:+limit+:] Maximum number of redirects to follow. Takes precedences over :+no_follow+.
|
45
47
|
# [:+query+:] Query string, or a Hash representing it. Normalized according to the same rules as :+body+. If you specify this on a POST, you must use a Hash. See also HTTParty::ClassMethods.default_params.
|
46
48
|
# [:+timeout+:] Timeout for opening connection and reading data.
|
@@ -67,11 +69,13 @@ module HTTParty
|
|
67
69
|
#
|
68
70
|
# class Foo
|
69
71
|
# include HTTParty
|
70
|
-
# http_proxy 'http://foo.com', 80
|
72
|
+
# http_proxy 'http://foo.com', 80, 'user', 'pass'
|
71
73
|
# end
|
72
|
-
def http_proxy(addr=nil, port = nil)
|
74
|
+
def http_proxy(addr=nil, port=nil, user=nil, pass=nil)
|
73
75
|
default_options[:http_proxyaddr] = addr
|
74
76
|
default_options[:http_proxyport] = port
|
77
|
+
default_options[:http_proxyuser] = user
|
78
|
+
default_options[:http_proxypass] = pass
|
75
79
|
end
|
76
80
|
|
77
81
|
# Allows setting a base uri to be used for each request.
|
@@ -339,8 +343,8 @@ module HTTParty
|
|
339
343
|
# # Simple get with full url and query parameters
|
340
344
|
# # ie: http://foo.com/resource.json?limit=10
|
341
345
|
# Foo.get('http://foo.com/resource.json', :query => {:limit => 10})
|
342
|
-
def get(path, options={})
|
343
|
-
perform_request Net::HTTP::Get, path, options
|
346
|
+
def get(path, options={}, &block)
|
347
|
+
perform_request Net::HTTP::Get, path, options, &block
|
344
348
|
end
|
345
349
|
|
346
350
|
# Allows making a post request to a url.
|
@@ -355,28 +359,28 @@ module HTTParty
|
|
355
359
|
# # Simple post with full url using :query option,
|
356
360
|
# # which gets set as form data on the request.
|
357
361
|
# Foo.post('http://foo.com/resources', :query => {:bar => 'baz'})
|
358
|
-
def post(path, options={})
|
359
|
-
perform_request Net::HTTP::Post, path, options
|
362
|
+
def post(path, options={}, &block)
|
363
|
+
perform_request Net::HTTP::Post, path, options, &block
|
360
364
|
end
|
361
365
|
|
362
366
|
# Perform a PUT request to a path
|
363
|
-
def put(path, options={})
|
364
|
-
perform_request Net::HTTP::Put, path, options
|
367
|
+
def put(path, options={}, &block)
|
368
|
+
perform_request Net::HTTP::Put, path, options, &block
|
365
369
|
end
|
366
370
|
|
367
371
|
# Perform a DELETE request to a path
|
368
|
-
def delete(path, options={})
|
369
|
-
perform_request Net::HTTP::Delete, path, options
|
372
|
+
def delete(path, options={}, &block)
|
373
|
+
perform_request Net::HTTP::Delete, path, options, &block
|
370
374
|
end
|
371
375
|
|
372
376
|
# Perform a HEAD request to a path
|
373
|
-
def head(path, options={})
|
374
|
-
perform_request Net::HTTP::Head, path, options
|
377
|
+
def head(path, options={}, &block)
|
378
|
+
perform_request Net::HTTP::Head, path, options, &block
|
375
379
|
end
|
376
380
|
|
377
381
|
# Perform an OPTIONS request to a path
|
378
|
-
def options(path, options={})
|
379
|
-
perform_request Net::HTTP::Options, path, options
|
382
|
+
def options(path, options={}, &block)
|
383
|
+
perform_request Net::HTTP::Options, path, options, &block
|
380
384
|
end
|
381
385
|
|
382
386
|
def default_options #:nodoc:
|
@@ -385,10 +389,10 @@ module HTTParty
|
|
385
389
|
|
386
390
|
private
|
387
391
|
|
388
|
-
def perform_request(http_method, path, options) #:nodoc:
|
392
|
+
def perform_request(http_method, path, options, &block) #:nodoc:
|
389
393
|
options = default_options.dup.merge(options)
|
390
394
|
process_cookies(options)
|
391
|
-
Request.new(http_method, path, options).perform
|
395
|
+
Request.new(http_method, path, options).perform(&block)
|
392
396
|
end
|
393
397
|
|
394
398
|
def process_cookies(options) #:nodoc:
|
@@ -419,28 +423,28 @@ module HTTParty
|
|
419
423
|
include HTTParty
|
420
424
|
end
|
421
425
|
|
422
|
-
def self.get(*args)
|
423
|
-
Basement.get(*args)
|
426
|
+
def self.get(*args, &block)
|
427
|
+
Basement.get(*args, &block)
|
424
428
|
end
|
425
429
|
|
426
|
-
def self.post(*args)
|
427
|
-
Basement.post(*args)
|
430
|
+
def self.post(*args, &block)
|
431
|
+
Basement.post(*args, &block)
|
428
432
|
end
|
429
433
|
|
430
|
-
def self.put(*args)
|
431
|
-
Basement.put(*args)
|
434
|
+
def self.put(*args, &block)
|
435
|
+
Basement.put(*args, &block)
|
432
436
|
end
|
433
437
|
|
434
|
-
def self.delete(*args)
|
435
|
-
Basement.delete(*args)
|
438
|
+
def self.delete(*args, &block)
|
439
|
+
Basement.delete(*args, &block)
|
436
440
|
end
|
437
441
|
|
438
|
-
def self.head(*args)
|
439
|
-
Basement.head(*args)
|
442
|
+
def self.head(*args, &block)
|
443
|
+
Basement.head(*args, &block)
|
440
444
|
end
|
441
445
|
|
442
|
-
def self.options(*args)
|
443
|
-
Basement.options(*args)
|
446
|
+
def self.options(*args, &block)
|
447
|
+
Basement.options(*args, &block)
|
444
448
|
end
|
445
449
|
end
|
446
450
|
|
data/lib/httparty/parser.rb
CHANGED
@@ -96,9 +96,9 @@ module HTTParty
|
|
96
96
|
private_class_method :new
|
97
97
|
|
98
98
|
# @return [Object] the parsed body
|
99
|
-
# @return [nil] when the response body is nil
|
99
|
+
# @return [nil] when the response body is nil, an empty string, spaces only or "null"
|
100
100
|
def parse
|
101
|
-
return nil if body.nil? || body.empty?
|
101
|
+
return nil if body.nil? || body.strip.empty? || body == "null"
|
102
102
|
if supports_format?
|
103
103
|
parse_supported_format
|
104
104
|
else
|
data/lib/httparty/request.rb
CHANGED
@@ -67,10 +67,23 @@ module HTTParty
|
|
67
67
|
options[:parser]
|
68
68
|
end
|
69
69
|
|
70
|
-
def perform
|
70
|
+
def perform(&block)
|
71
71
|
validate
|
72
72
|
setup_raw_request
|
73
|
-
|
73
|
+
|
74
|
+
self.last_response = http.request(@raw_request) do |http_response|
|
75
|
+
if block
|
76
|
+
chunks = []
|
77
|
+
|
78
|
+
http_response.read_body do |fragment|
|
79
|
+
chunks << fragment
|
80
|
+
block.call(fragment)
|
81
|
+
end
|
82
|
+
|
83
|
+
http_response.body = chunks.join
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
74
87
|
handle_deflation
|
75
88
|
handle_response
|
76
89
|
end
|
@@ -102,7 +115,7 @@ module HTTParty
|
|
102
115
|
end
|
103
116
|
|
104
117
|
def http
|
105
|
-
http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport])
|
118
|
+
http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass])
|
106
119
|
http.use_ssl = ssl_implied?
|
107
120
|
|
108
121
|
if options[:timeout] && (options[:timeout].is_a?(Integer) || options[:timeout].is_a?(Float))
|
@@ -160,7 +173,10 @@ module HTTParty
|
|
160
173
|
end
|
161
174
|
|
162
175
|
def setup_digest_auth
|
163
|
-
|
176
|
+
auth_request = http_method.new(uri.request_uri)
|
177
|
+
auth_request.initialize_http_header(options[:headers])
|
178
|
+
res = http.request(auth_request)
|
179
|
+
|
164
180
|
if res['www-authenticate'] != nil && res['www-authenticate'].length > 0
|
165
181
|
@raw_request.digest_auth(username, password, res)
|
166
182
|
end
|
@@ -180,7 +196,6 @@ module HTTParty
|
|
180
196
|
query_string_parts.size > 0 ? query_string_parts.join('&') : nil
|
181
197
|
end
|
182
198
|
|
183
|
-
# Raises exception Net::XXX (http error code) if an http error occured
|
184
199
|
def handle_response
|
185
200
|
if response_redirects?
|
186
201
|
options[:limit] -= 1
|
@@ -197,11 +212,13 @@ module HTTParty
|
|
197
212
|
# Inspired by Ruby 1.9
|
198
213
|
def handle_deflation
|
199
214
|
case last_response["content-encoding"]
|
200
|
-
when "gzip"
|
215
|
+
when "gzip", "x-gzip"
|
201
216
|
body_io = StringIO.new(last_response.body)
|
202
217
|
last_response.body.replace Zlib::GzipReader.new(body_io).read
|
218
|
+
last_response.delete('content-encoding')
|
203
219
|
when "deflate"
|
204
220
|
last_response.body.replace Zlib::Inflate.inflate(last_response.body)
|
221
|
+
last_response.delete('content-encoding')
|
205
222
|
end
|
206
223
|
end
|
207
224
|
|
data/lib/httparty/response.rb
CHANGED
data/lib/httparty/version.rb
CHANGED
@@ -87,6 +87,16 @@ describe HTTParty::Parser do
|
|
87
87
|
@parser.stub(:body => nil)
|
88
88
|
@parser.parse.should be_nil
|
89
89
|
end
|
90
|
+
|
91
|
+
it "returns nil for a 'null' body" do
|
92
|
+
@parser.stub(:body => "null")
|
93
|
+
@parser.parse.should be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns nil for a body with spaces only" do
|
97
|
+
@parser.stub(:body => " ")
|
98
|
+
@parser.parse.should be_nil
|
99
|
+
end
|
90
100
|
end
|
91
101
|
|
92
102
|
describe "#supports_format?" do
|
@@ -86,7 +86,7 @@ describe HTTParty::Request do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should use digest auth when configured" do
|
89
|
-
FakeWeb.register_uri(:
|
89
|
+
FakeWeb.register_uri(:get, "http://api.foo.com/v1",
|
90
90
|
:www_authenticate => 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false')
|
91
91
|
|
92
92
|
@request.options[:digest_auth] = {:username => 'foobar', :password => 'secret'}
|
@@ -95,6 +95,17 @@ describe HTTParty::Request do
|
|
95
95
|
raw_request = @request.instance_variable_get(:@raw_request)
|
96
96
|
raw_request.instance_variable_get(:@header)['Authorization'].should_not be_nil
|
97
97
|
end
|
98
|
+
|
99
|
+
it "should use the right http method for digest authentication" do
|
100
|
+
@post_request = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml)
|
101
|
+
FakeWeb.register_uri(:post, "http://api.foo.com/v1", {})
|
102
|
+
|
103
|
+
http = @post_request.send(:http)
|
104
|
+
@post_request.should_receive(:http).and_return(http)
|
105
|
+
http.should_not_receive(:head).and_return({'www-authenticate' => nil})
|
106
|
+
@post_request.options[:digest_auth] = {:username => 'foobar', :password => 'secret'}
|
107
|
+
@post_request.send(:setup_raw_request)
|
108
|
+
end
|
98
109
|
end
|
99
110
|
|
100
111
|
describe "#uri" do
|
@@ -216,6 +227,25 @@ describe HTTParty::Request do
|
|
216
227
|
@request.send(:http)
|
217
228
|
end
|
218
229
|
end
|
230
|
+
|
231
|
+
context 'with a proxy' do
|
232
|
+
it 'should use a proxy address and port' do
|
233
|
+
request = HTTParty::Request.new(Net::HTTP::Get, 'https://foobar.com',
|
234
|
+
:http_proxyaddr => '1.2.3.4', :http_proxyport => 8080)
|
235
|
+
http = request.send(:http)
|
236
|
+
http.proxy_address.should == '1.2.3.4'
|
237
|
+
http.proxy_port.should == 8080
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'should use a proxy user and password when provided' do
|
241
|
+
request = HTTParty::Request.new(Net::HTTP::Get, 'https://foobar.com',
|
242
|
+
:http_proxyaddr => '1.2.3.4', :http_proxyport => 8080,
|
243
|
+
:http_proxyuser => 'user', :http_proxypass => 'pass')
|
244
|
+
http = request.send(:http)
|
245
|
+
http.proxy_user.should == 'user'
|
246
|
+
http.proxy_pass.should == 'pass'
|
247
|
+
end
|
248
|
+
end
|
219
249
|
end
|
220
250
|
|
221
251
|
context "when setting timeout" do
|
@@ -487,6 +517,40 @@ describe HTTParty::Request do
|
|
487
517
|
end
|
488
518
|
end
|
489
519
|
|
520
|
+
describe "#handle_deflation" do
|
521
|
+
context "context-encoding" do
|
522
|
+
before do
|
523
|
+
@request.options[:format] = :html
|
524
|
+
@last_response = mock()
|
525
|
+
@last_response.stub!(:body).and_return('')
|
526
|
+
end
|
527
|
+
|
528
|
+
it "should inflate the gzipped body with content-encoding: gzip" do
|
529
|
+
@last_response.stub!(:[]).with("content-encoding").and_return("gzip")
|
530
|
+
@request.stub!(:last_response).and_return(@last_response)
|
531
|
+
Zlib::GzipReader.should_receive(:new).and_return(StringIO.new(''))
|
532
|
+
@request.last_response.should_receive(:delete).with('content-encoding')
|
533
|
+
@request.send(:handle_deflation)
|
534
|
+
end
|
535
|
+
|
536
|
+
it "should inflate the gzipped body with content-encoding: x-gzip" do
|
537
|
+
@last_response.stub!(:[]).with("content-encoding").and_return("x-gzip")
|
538
|
+
@request.stub!(:last_response).and_return(@last_response)
|
539
|
+
Zlib::GzipReader.should_receive(:new).and_return(StringIO.new(''))
|
540
|
+
@request.last_response.should_receive(:delete).with('content-encoding')
|
541
|
+
@request.send(:handle_deflation)
|
542
|
+
end
|
543
|
+
|
544
|
+
it "should inflate the deflated body" do
|
545
|
+
@last_response.stub!(:[]).with("content-encoding").and_return("deflate")
|
546
|
+
@request.stub!(:last_response).and_return(@last_response)
|
547
|
+
Zlib::Inflate.should_receive(:inflate).and_return('')
|
548
|
+
@request.last_response.should_receive(:delete).with('content-encoding')
|
549
|
+
@request.send(:handle_deflation)
|
550
|
+
end
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
490
554
|
context "with POST http method" do
|
491
555
|
it "should raise argument error if query is not a hash" do
|
492
556
|
lambda {
|
data/spec/httparty_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe HTTParty do
|
|
19
19
|
HTTParty::AllowedFormats.should == HTTParty::Parser::SupportedFormats
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe "pem" do
|
24
24
|
|
25
25
|
it 'should set the pem content' do
|
@@ -39,6 +39,22 @@ describe HTTParty do
|
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
+
describe 'http_proxy' do
|
43
|
+
it 'should set the address' do
|
44
|
+
@klass.http_proxy 'proxy.foo.com', 80
|
45
|
+
options = @klass.default_options
|
46
|
+
options[:http_proxyaddr].should == 'proxy.foo.com'
|
47
|
+
options[:http_proxyport].should == 80
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should set the proxy user and pass when they are provided' do
|
51
|
+
@klass.http_proxy 'proxy.foo.com', 80, 'user', 'pass'
|
52
|
+
options = @klass.default_options
|
53
|
+
options[:http_proxyuser].should == 'user'
|
54
|
+
options[:http_proxypass].should == 'pass'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
42
58
|
describe "base uri" do
|
43
59
|
before(:each) do
|
44
60
|
@klass.base_uri('api.foo.com/v1')
|
@@ -546,6 +562,15 @@ describe HTTParty do
|
|
546
562
|
HTTParty.get('http://www.google.com').should == file_fixture('google.html')
|
547
563
|
end
|
548
564
|
|
565
|
+
it "should be able to get chunked html" do
|
566
|
+
chunks = ["Chunk1", "Chunk2", "Chunk3", "Chunk4"]
|
567
|
+
stub_chunked_http_response_with(chunks)
|
568
|
+
|
569
|
+
HTTParty.get('http://www.google.com') do |fragment|
|
570
|
+
chunks.should include(fragment)
|
571
|
+
end.should == chunks.join
|
572
|
+
end
|
573
|
+
|
549
574
|
it "should be able parse response type json automatically" do
|
550
575
|
stub_http_response_with('twitter.json')
|
551
576
|
tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
|
@@ -13,6 +13,19 @@ module HTTParty
|
|
13
13
|
HTTParty::Request.should_receive(:new).and_return(http_request)
|
14
14
|
end
|
15
15
|
|
16
|
+
def stub_chunked_http_response_with(chunks)
|
17
|
+
response = Net::HTTPResponse.new("1.1", 200, nil)
|
18
|
+
response.stub(:chunked_data).and_return(chunks)
|
19
|
+
def response.read_body(&block)
|
20
|
+
@body || chunked_data.each(&block)
|
21
|
+
end
|
22
|
+
|
23
|
+
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => "html")
|
24
|
+
http_request.stub_chain(:http, :request).and_yield(response).and_return(response)
|
25
|
+
|
26
|
+
HTTParty::Request.should_receive(:new).and_return(http_request)
|
27
|
+
end
|
28
|
+
|
16
29
|
def stub_response(body, code = 200)
|
17
30
|
@request.options[:base_uri] ||= 'http://localhost'
|
18
31
|
unless defined?(@http) && @http
|
metadata
CHANGED
@@ -1,61 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
- 0
|
10
|
-
version: 0.8.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- John Nunemaker
|
14
9
|
- Sandro Turriate
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2012-04-12 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: multi_json
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &70278647636880 !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
33
23
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: multi_xml
|
37
24
|
prerelease: false
|
38
|
-
|
25
|
+
version_requirements: *70278647636880
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: multi_xml
|
28
|
+
requirement: &70278647636320 !ruby/object:Gem::Requirement
|
39
29
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
47
34
|
type: :runtime
|
48
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70278647636320
|
49
37
|
description: Makes http fun! Also, makes consuming restful web services dead easy.
|
50
|
-
email:
|
38
|
+
email:
|
51
39
|
- nunemaker@gmail.com
|
52
|
-
executables:
|
40
|
+
executables:
|
53
41
|
- httparty
|
54
42
|
extensions: []
|
55
|
-
|
56
43
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
44
|
+
files:
|
59
45
|
- .gitignore
|
60
46
|
- Gemfile
|
61
47
|
- History
|
@@ -66,9 +52,12 @@ files:
|
|
66
52
|
- cucumber.yml
|
67
53
|
- examples/aaws.rb
|
68
54
|
- examples/basic.rb
|
55
|
+
- examples/crack.rb
|
69
56
|
- examples/custom_parsers.rb
|
70
57
|
- examples/delicious.rb
|
71
58
|
- examples/google.rb
|
59
|
+
- examples/headers_and_user_agents.rb
|
60
|
+
- examples/nokogiri_html_parser.rb
|
72
61
|
- examples/rubyurl.rb
|
73
62
|
- examples/tripit_sign_in.rb
|
74
63
|
- examples/twitter.rb
|
@@ -129,38 +118,29 @@ files:
|
|
129
118
|
- website/index.html
|
130
119
|
homepage: http://httparty.rubyforge.org/
|
131
120
|
licenses: []
|
132
|
-
|
133
121
|
post_install_message: When you HTTParty, you must party hard!
|
134
122
|
rdoc_options: []
|
135
|
-
|
136
|
-
require_paths:
|
123
|
+
require_paths:
|
137
124
|
- lib
|
138
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
126
|
none: false
|
140
|
-
requirements:
|
141
|
-
- -
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
|
144
|
-
|
145
|
-
- 0
|
146
|
-
version: "0"
|
147
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
132
|
none: false
|
149
|
-
requirements:
|
150
|
-
- -
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
|
153
|
-
segments:
|
154
|
-
- 0
|
155
|
-
version: "0"
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
156
137
|
requirements: []
|
157
|
-
|
158
138
|
rubyforge_project:
|
159
|
-
rubygems_version: 1.8.
|
139
|
+
rubygems_version: 1.8.10
|
160
140
|
signing_key:
|
161
141
|
specification_version: 3
|
162
142
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|
163
|
-
test_files:
|
143
|
+
test_files:
|
164
144
|
- features/basic_authentication.feature
|
165
145
|
- features/command_line.feature
|
166
146
|
- features/deals_with_http_error_codes.feature
|