httparty 0.10.2 → 0.11.0
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/.travis.yml +1 -0
- data/Gemfile +1 -1
- data/features/steps/httparty_response_steps.rb +15 -1
- data/lib/httparty.rb +9 -0
- data/lib/httparty/cookie_hash.rb +1 -1
- data/lib/httparty/net_digest_auth.rb +1 -1
- data/lib/httparty/request.rb +6 -5
- data/lib/httparty/response.rb +6 -1
- data/lib/httparty/version.rb +1 -1
- data/spec/httparty/cookie_hash_spec.rb +6 -0
- data/spec/httparty/net_digest_auth_spec.rb +1 -1
- data/spec/httparty/request_spec.rb +20 -0
- data/spec/httparty/response_spec.rb +8 -1
- data/spec/httparty_spec.rb +9 -3
- metadata +4 -4
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# Not needed anymore in ruby 2.0, but needed to resolve constants
|
2
|
+
# in nested namespaces. This is taken from rails :)
|
3
|
+
def constantize(camel_cased_word)
|
4
|
+
names = camel_cased_word.split('::')
|
5
|
+
names.shift if names.empty? || names.first.empty?
|
6
|
+
|
7
|
+
constant = Object
|
8
|
+
names.each do |name|
|
9
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
10
|
+
end
|
11
|
+
constant
|
12
|
+
end
|
13
|
+
|
14
|
+
|
1
15
|
Then /it should return an? (\w+)$/ do |class_string|
|
2
16
|
@response_from_httparty.should be_an_instance_of(class_string.class)
|
3
17
|
end
|
@@ -22,5 +36,5 @@ end
|
|
22
36
|
|
23
37
|
Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception|
|
24
38
|
@exception_from_httparty.should_not be_nil
|
25
|
-
@exception_from_httparty.
|
39
|
+
@exception_from_httparty.should be_a constantize(exception)
|
26
40
|
end
|
data/lib/httparty.rb
CHANGED
@@ -434,6 +434,11 @@ module HTTParty
|
|
434
434
|
perform_request Net::HTTP::Move, path, options, &block
|
435
435
|
end
|
436
436
|
|
437
|
+
# Perform a COPY request to a path
|
438
|
+
def copy(path, options={}, &block)
|
439
|
+
perform_request Net::HTTP::Copy, path, options, &block
|
440
|
+
end
|
441
|
+
|
437
442
|
# Perform a HEAD request to a path
|
438
443
|
def head(path, options={}, &block)
|
439
444
|
perform_request Net::HTTP::Head, path, options, &block
|
@@ -508,6 +513,10 @@ module HTTParty
|
|
508
513
|
Basement.move(*args, &block)
|
509
514
|
end
|
510
515
|
|
516
|
+
def self.copy(*args, &block)
|
517
|
+
Basement.move(*args, &block)
|
518
|
+
end
|
519
|
+
|
511
520
|
def self.head(*args, &block)
|
512
521
|
Basement.head(*args, &block)
|
513
522
|
end
|
data/lib/httparty/cookie_hash.rb
CHANGED
@@ -17,6 +17,6 @@ class HTTParty::CookieHash < Hash #:nodoc:
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_cookie_string
|
20
|
-
delete_if { |k, v| CLIENT_COOKIES.include?(k.to_s) }.collect { |k, v| "#{k}=#{v}" }.join("; ")
|
20
|
+
delete_if { |k, v| CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join("; ")
|
21
21
|
end
|
22
22
|
end
|
data/lib/httparty/request.rb
CHANGED
@@ -8,7 +8,8 @@ module HTTParty
|
|
8
8
|
Net::HTTP::Delete,
|
9
9
|
Net::HTTP::Head,
|
10
10
|
Net::HTTP::Options,
|
11
|
-
Net::HTTP::Move
|
11
|
+
Net::HTTP::Move,
|
12
|
+
Net::HTTP::Copy
|
12
13
|
]
|
13
14
|
|
14
15
|
SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic]
|
@@ -53,7 +54,7 @@ module HTTParty
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def uri
|
56
|
-
new_uri = path.relative? ? URI.parse("#{base_uri}#{path}") : path
|
57
|
+
new_uri = path.relative? ? URI.parse("#{base_uri}#{path}") : path.clone
|
57
58
|
|
58
59
|
# avoid double query string on redirects [#12]
|
59
60
|
unless redirect
|
@@ -102,7 +103,7 @@ module HTTParty
|
|
102
103
|
end
|
103
104
|
|
104
105
|
handle_deflation
|
105
|
-
handle_response(chunked_body)
|
106
|
+
handle_response(chunked_body, &block)
|
106
107
|
end
|
107
108
|
|
108
109
|
private
|
@@ -171,14 +172,14 @@ module HTTParty
|
|
171
172
|
query_string_parts.size > 0 ? query_string_parts.join('&') : nil
|
172
173
|
end
|
173
174
|
|
174
|
-
def handle_response(body)
|
175
|
+
def handle_response(body, &block)
|
175
176
|
if response_redirects?
|
176
177
|
options[:limit] -= 1
|
177
178
|
self.path = last_response['location']
|
178
179
|
self.redirect = true
|
179
180
|
self.http_method = Net::HTTP::Get unless options[:maintain_method_across_redirects]
|
180
181
|
capture_cookies(last_response)
|
181
|
-
perform
|
182
|
+
perform(&block)
|
182
183
|
else
|
183
184
|
body = body || last_response.body
|
184
185
|
Response.new(self, last_response, lambda { parse_response(body) }, :body => body)
|
data/lib/httparty/response.rb
CHANGED
@@ -9,7 +9,7 @@ module HTTParty
|
|
9
9
|
def initialize(request, response, parsed_block, options={})
|
10
10
|
@request = request
|
11
11
|
@response = response
|
12
|
-
@body =
|
12
|
+
@body = options[:body] || response.body
|
13
13
|
@parsed_block = parsed_block
|
14
14
|
@headers = Headers.new(response.to_hash)
|
15
15
|
end
|
@@ -40,6 +40,11 @@ module HTTParty
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
# Support old multiple_choice? method from pre 2.0.0 era.
|
44
|
+
if ::RUBY_VERSION >= "2.0.0"
|
45
|
+
alias_method :multiple_choice?, :multiple_choices?
|
46
|
+
end
|
47
|
+
|
43
48
|
def respond_to?(name)
|
44
49
|
return true if [:request, :response, :parsed_response, :body, :headers].include?(name)
|
45
50
|
parsed_response.respond_to?(name) || response.respond_to?(name)
|
data/lib/httparty/version.rb
CHANGED
@@ -66,5 +66,11 @@ describe HTTParty::CookieHash do
|
|
66
66
|
@s = @cookie_hash.to_cookie_string
|
67
67
|
@s.should_not match(/path=\//)
|
68
68
|
end
|
69
|
+
|
70
|
+
it "should not include client side only cookies even when attributes use camal case" do
|
71
|
+
@cookie_hash.add_cookies(:Path => "/")
|
72
|
+
@s = @cookie_hash.to_cookie_string
|
73
|
+
@s.should_not match(/Path=\//)
|
74
|
+
end
|
69
75
|
end
|
70
76
|
end
|
@@ -133,6 +133,12 @@ describe HTTParty::Request do
|
|
133
133
|
URI.unescape(@request.uri.query).should == ""
|
134
134
|
end
|
135
135
|
|
136
|
+
it "does not duplicate query string parameters when uri is called twice" do
|
137
|
+
@request.options[:query] = {:foo => :bar}
|
138
|
+
@request.uri
|
139
|
+
@request.uri.query.should == "foo=bar"
|
140
|
+
end
|
141
|
+
|
136
142
|
context "when representing an array" do
|
137
143
|
it "returns a Rails style query string" do
|
138
144
|
@request.options[:query] = {:foo => %w(bar baz)}
|
@@ -256,6 +262,15 @@ describe HTTParty::Request do
|
|
256
262
|
response.should == {"hash" => {"foo" => "bar"}}
|
257
263
|
end
|
258
264
|
|
265
|
+
it "calls block given to perform with each redirect" do
|
266
|
+
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', :format => :xml)
|
267
|
+
FakeWeb.register_uri(:get, "http://test.com/redirect", :status => [300, "REDIRECT"], :location => "http://api.foo.com/v2")
|
268
|
+
FakeWeb.register_uri(:get, "http://api.foo.com/v2", :body => "<hash><foo>bar</foo></hash>")
|
269
|
+
body = ""
|
270
|
+
response = @request.perform { |chunk| body += chunk }
|
271
|
+
body.length.should == 27
|
272
|
+
end
|
273
|
+
|
259
274
|
it "redirects if a 300 contains a relative location header" do
|
260
275
|
redirect = stub_response '', 300
|
261
276
|
redirect['location'] = '/foo/bar'
|
@@ -363,6 +378,11 @@ describe HTTParty::Request do
|
|
363
378
|
@request.perform.should == {"hash" => {"foo" => "bar"}}
|
364
379
|
end
|
365
380
|
|
381
|
+
it "should be handled by COPY transparently" do
|
382
|
+
@request.http_method = Net::HTTP::Copy
|
383
|
+
@request.perform.should == {"hash" => {"foo" => "bar"}}
|
384
|
+
end
|
385
|
+
|
366
386
|
it "should be handled by PATCH transparently" do
|
367
387
|
@request.http_method = Net::HTTP::Patch
|
368
388
|
@request.perform.should == {"hash" => {"foo" => "bar"}}
|
@@ -195,7 +195,14 @@ describe HTTParty::Response do
|
|
195
195
|
:unsupported_media_type? => Net::HTTPUnsupportedMediaType,
|
196
196
|
:use_proxy? => Net::HTTPUseProxy,
|
197
197
|
:version_not_supported? => Net::HTTPVersionNotSupported
|
198
|
-
}
|
198
|
+
}
|
199
|
+
|
200
|
+
# Ruby 2.0, new name for this response.
|
201
|
+
if RUBY_VERSION >= "2.0.0"
|
202
|
+
SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices
|
203
|
+
end
|
204
|
+
|
205
|
+
SPECIFIC_CODES.each do |method, klass|
|
199
206
|
it "responds to #{method}" do
|
200
207
|
net_response = response_mock(klass)
|
201
208
|
response = HTTParty::Response.new(@request_object, net_response, '')
|
data/spec/httparty_spec.rb
CHANGED
@@ -497,6 +497,12 @@ describe HTTParty do
|
|
497
497
|
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
498
498
|
end
|
499
499
|
|
500
|
+
it "should fail with redirected COPY" do
|
501
|
+
lambda do
|
502
|
+
@klass.copy('/foo', :no_follow => true)
|
503
|
+
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
|
504
|
+
end
|
505
|
+
|
500
506
|
it "should fail with redirected PUT" do
|
501
507
|
lambda do
|
502
508
|
@klass.put('/foo', :no_follow => true)
|
@@ -593,11 +599,11 @@ describe HTTParty do
|
|
593
599
|
end
|
594
600
|
|
595
601
|
it 'should dup the proc on the child class' do
|
596
|
-
imaginary_option = lambda {
|
602
|
+
imaginary_option = lambda { 2 * 3.14 }
|
597
603
|
@parent.default_options[:imaginary_option] = imaginary_option
|
598
|
-
@parent.default_options[:imaginary_option].should
|
604
|
+
@parent.default_options[:imaginary_option].call.should == imaginary_option.call
|
599
605
|
@child1.default_options[:imaginary_option]
|
600
|
-
@child1.default_options[:imaginary_option].should == imaginary_option
|
606
|
+
@child1.default_options[:imaginary_option].call.should == imaginary_option.call
|
601
607
|
@child1.default_options[:imaginary_option].should_not be_equal imaginary_option
|
602
608
|
end
|
603
609
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
segments:
|
147
147
|
- 0
|
148
|
-
hash:
|
148
|
+
hash: -4402844038872120399
|
149
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
segments:
|
156
156
|
- 0
|
157
|
-
hash:
|
157
|
+
hash: -4402844038872120399
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
160
|
rubygems_version: 1.8.23
|