httparty 0.7.8 → 0.8.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/Gemfile +5 -3
- data/History +21 -15
- data/README.rdoc +1 -1
- data/features/steps/env.rb +0 -1
- data/httparty.gemspec +2 -7
- data/lib/httparty.rb +3 -6
- data/lib/httparty/core_extensions.rb +0 -22
- data/lib/httparty/hash_conversions.rb +51 -0
- data/lib/httparty/parser.rb +2 -2
- data/lib/httparty/request.rb +9 -5
- data/lib/httparty/version.rb +1 -3
- data/spec/httparty/parser_spec.rb +4 -4
- data/spec/httparty/request_spec.rb +22 -1
- metadata +16 -82
data/Gemfile
CHANGED
data/History
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.8.0 2011-09-13
|
2
|
+
* new
|
3
|
+
* switch to multi json/xml for parsing by default
|
4
|
+
* bug fixes
|
5
|
+
* fix redirects to relative uri's
|
6
|
+
|
1
7
|
== 0.7.8 2011-06-06
|
2
8
|
* bug fix
|
3
9
|
* Make response honor respond to
|
@@ -125,11 +131,11 @@
|
|
125
131
|
* :query no longer sets form data. Use body and set content type to application/x-www-form-urlencoded if you need it. :query was wrong for that.
|
126
132
|
* Fixed a bug in the cookies class method that caused cookies to be forgotten after the first request.
|
127
133
|
* Also, some general cleanup of tests and such.
|
128
|
-
|
134
|
+
|
129
135
|
== 0.4.3 2009-04-23
|
130
136
|
* 1 minor update
|
131
137
|
* added message to the response object
|
132
|
-
|
138
|
+
|
133
139
|
== 0.4.2 2009-03-30
|
134
140
|
* 2 minor changes
|
135
141
|
* response code now returns an integer instead of a string (jqr)
|
@@ -138,36 +144,36 @@
|
|
138
144
|
== 0.4.1 2009-03-29
|
139
145
|
* 1 minor fix
|
140
146
|
* gem 'jnunemaker-crack' instead of gem 'crack'
|
141
|
-
|
147
|
+
|
142
148
|
== 0.4.0 2009-03-29
|
143
149
|
* 1 minor change
|
144
150
|
* Switched xml and json parsing to crack (same code as before just moved to gem for easier reuse in other projects)
|
145
|
-
|
151
|
+
|
146
152
|
== 0.3.1 2009-02-10
|
147
153
|
* 1 minor fix, 1 minor enhancement
|
148
154
|
* Fixed unescaping umlauts (siebertm)
|
149
155
|
* Added yaml response parsing (Miha Filej)
|
150
|
-
|
156
|
+
|
151
157
|
== 0.3.0 2009-01-31
|
152
158
|
* 1 major enhancement, 1 bug fix
|
153
159
|
* JSON gem no longer a requirement. It was conflicting with rails json stuff so I just stole ActiveSupport's json decoding and bundled it with HTTParty.
|
154
160
|
* Fixed bug where query strings were being duplicated on redirects
|
155
161
|
* Added a bunch of specs and moved some code around.
|
156
|
-
|
162
|
+
|
157
163
|
== 0.2.10 2009-01-29
|
158
164
|
* 1 minor enhancement
|
159
165
|
* Made encoding on query parameters treat everything except URI::PATTERN::UNRESERVED as UNSAFE to force encoding of '+' character (Julian Russell)
|
160
|
-
|
166
|
+
|
161
167
|
== 0.2.9 2009-01-29
|
162
168
|
* 3 minor enhancements
|
163
169
|
* Added a 'headers' accessor to the response with a hash of any HTTP headers. (Don Peterson)
|
164
170
|
* Add support for a ":cookies" option to be used at the class level, or as an option on any individual call. It should be passed a hash, which will be converted to the proper format and added to the request headers when the call is made. (Don Peterson)
|
165
171
|
* Refactored several specs and added a full suite of cucumber features (Don Peterson)
|
166
|
-
|
172
|
+
|
167
173
|
== 0.2.8 2009-01-28
|
168
174
|
* 1 major fix
|
169
175
|
* fixed major bug with response where it wouldn't iterate or really work at all with parsed responses
|
170
|
-
|
176
|
+
|
171
177
|
== 0.2.7 2009-01-28
|
172
178
|
* 2 minor fixes, 2 minor enhancements, 2 major enhancements
|
173
179
|
* fixed undefined method add_node for nil class error that occasionally happened (juliocesar)
|
@@ -180,11 +186,11 @@
|
|
180
186
|
== 0.2.6 2009-01-05
|
181
187
|
* 1 minor bug fix
|
182
188
|
* added explicit require of time as Time#parse failed outside of rails (willcodeforfoo)
|
183
|
-
|
189
|
+
|
184
190
|
== 0.2.5 2009-01-05
|
185
191
|
* 1 major enhancement
|
186
192
|
* Add command line interface to HTTParty (Alex Vollmer)
|
187
|
-
|
193
|
+
|
188
194
|
== 0.2.4 2008-12-23
|
189
195
|
* 1 bug fix
|
190
196
|
* Fixed that mimetype detection was failing if no mimetype was returned from service (skippy)
|
@@ -206,7 +212,7 @@
|
|
206
212
|
|
207
213
|
== 0.1.8 2008-11-30
|
208
214
|
* 3 major enhancements
|
209
|
-
* Moved base_uri normalization into request class and out of httparty module, fixing
|
215
|
+
* Moved base_uri normalization into request class and out of httparty module, fixing
|
210
216
|
the problem where base_uri was not always being normalized.
|
211
217
|
* Stupid simple support for HTTParty.get/post/put/delete. (jqr)
|
212
218
|
* Switched gem management to Echoe from newgem.
|
@@ -214,16 +220,16 @@
|
|
214
220
|
== 0.1.7 2008-11-30
|
215
221
|
* 1 major enhancement
|
216
222
|
* fixed multiple class definitions overriding each others options
|
217
|
-
|
223
|
+
|
218
224
|
== 0.1.6 2008-11-26
|
219
225
|
* 1 major enhancement
|
220
226
|
* now passing :query to set_form_data if post request to avoid content length errors
|
221
|
-
|
227
|
+
|
222
228
|
== 0.1.5 2008-11-14
|
223
229
|
* 2 major enhancements
|
224
230
|
* Refactored send request method out into its own object.
|
225
231
|
* Added :html format if you just want to do that.
|
226
|
-
|
232
|
+
|
227
233
|
== 0.1.4 2008-11-08
|
228
234
|
* 3 major enhancements:
|
229
235
|
* Removed some cruft
|
data/README.rdoc
CHANGED
data/features/steps/env.rb
CHANGED
data/httparty.gemspec
CHANGED
@@ -12,13 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
13
13
|
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
|
14
14
|
|
15
|
-
s.add_dependency '
|
16
|
-
|
17
|
-
s.add_development_dependency "activesupport", "~> 2.3"
|
18
|
-
s.add_development_dependency "cucumber", "~> 0.7"
|
19
|
-
s.add_development_dependency "fakeweb", "~> 1.2"
|
20
|
-
s.add_development_dependency "rspec", "~> 1.3"
|
21
|
-
s.add_development_dependency "mongrel", "1.2.0.pre2"
|
15
|
+
s.add_dependency 'multi_json'
|
16
|
+
s.add_dependency 'multi_xml'
|
22
17
|
|
23
18
|
s.post_install_message = "When you HTTParty, you must party hard!"
|
24
19
|
|
data/lib/httparty.rb
CHANGED
@@ -3,7 +3,8 @@ require 'net/http'
|
|
3
3
|
require 'net/https'
|
4
4
|
require 'uri'
|
5
5
|
require 'zlib'
|
6
|
-
require '
|
6
|
+
require 'multi_xml'
|
7
|
+
require 'multi_json'
|
7
8
|
|
8
9
|
require 'httparty/module_inheritable_attributes'
|
9
10
|
require 'httparty/cookie_hash'
|
@@ -441,15 +442,11 @@ module HTTParty
|
|
441
442
|
def self.options(*args)
|
442
443
|
Basement.options(*args)
|
443
444
|
end
|
444
|
-
|
445
445
|
end
|
446
446
|
|
447
447
|
require 'httparty/core_extensions'
|
448
|
+
require 'httparty/hash_conversions'
|
448
449
|
require 'httparty/exceptions'
|
449
450
|
require 'httparty/parser'
|
450
451
|
require 'httparty/request'
|
451
452
|
require 'httparty/response'
|
452
|
-
|
453
|
-
if Crack::VERSION != HTTParty::CRACK_DEPENDENCY
|
454
|
-
warn "warning: HTTParty depends on version #{HTTParty::CRACK_DEPENDENCY} of crack, not #{Crack::VERSION}."
|
455
|
-
end
|
@@ -7,25 +7,3 @@ module HTTParty
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
11
|
-
# 1.8.6 has mistyping of transitive in if statement
|
12
|
-
require "rexml/document"
|
13
|
-
module REXML #:nodoc:
|
14
|
-
class Document < Element #:nodoc:
|
15
|
-
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
|
16
|
-
if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
|
17
|
-
output = Output.new( output, xml_decl.encoding )
|
18
|
-
end
|
19
|
-
formatter = if indent > -1
|
20
|
-
if transitive
|
21
|
-
REXML::Formatters::Transitive.new( indent, ie_hack )
|
22
|
-
else
|
23
|
-
REXML::Formatters::Pretty.new( indent, ie_hack )
|
24
|
-
end
|
25
|
-
else
|
26
|
-
REXML::Formatters::Default.new( ie_hack )
|
27
|
-
end
|
28
|
-
formatter.write( self, output )
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module HTTParty
|
2
|
+
module HashConversions
|
3
|
+
# @return <String> This hash as a query string
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# { :name => "Bob",
|
7
|
+
# :address => {
|
8
|
+
# :street => '111 Ruby Ave.',
|
9
|
+
# :city => 'Ruby Central',
|
10
|
+
# :phones => ['111-111-1111', '222-222-2222']
|
11
|
+
# }
|
12
|
+
# }.to_params
|
13
|
+
# #=> "name=Bob&address[city]=Ruby Central&address[phones][]=111-111-1111&address[phones][]=222-222-2222&address[street]=111 Ruby Ave."
|
14
|
+
def self.to_params(hash)
|
15
|
+
params = hash.map { |k,v| normalize_param(k,v) }.join
|
16
|
+
params.chop! # trailing &
|
17
|
+
params
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param key<Object> The key for the param.
|
21
|
+
# @param value<Object> The value for the param.
|
22
|
+
#
|
23
|
+
# @return <String> This key value pair as a param
|
24
|
+
#
|
25
|
+
# @example normalize_param(:name, "Bob Jones") #=> "name=Bob%20Jones&"
|
26
|
+
def self.normalize_param(key, value)
|
27
|
+
param = ''
|
28
|
+
stack = []
|
29
|
+
|
30
|
+
if value.is_a?(Array)
|
31
|
+
param << value.map { |element| normalize_param("#{key}[]", element) }.join
|
32
|
+
elsif value.is_a?(Hash)
|
33
|
+
stack << [key,value]
|
34
|
+
else
|
35
|
+
param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&"
|
36
|
+
end
|
37
|
+
|
38
|
+
stack.each do |parent, hash|
|
39
|
+
hash.each do |key, value|
|
40
|
+
if value.is_a?(Hash)
|
41
|
+
stack << ["#{parent}[#{key}]", value]
|
42
|
+
else
|
43
|
+
param << normalize_param("#{parent}[#{key}]", value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
param
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/httparty/parser.rb
CHANGED
data/lib/httparty/request.rb
CHANGED
@@ -18,12 +18,12 @@ module HTTParty
|
|
18
18
|
elsif value.is_a?(Array)
|
19
19
|
value.map {|v| "#{key}=#{URI.encode(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"}
|
20
20
|
else
|
21
|
-
|
21
|
+
HashConversions.to_params(key => value)
|
22
22
|
end
|
23
23
|
end.flatten.sort.join('&')
|
24
24
|
end
|
25
25
|
|
26
|
-
attr_accessor :http_method, :path, :options, :last_response, :redirect
|
26
|
+
attr_accessor :http_method, :path, :options, :last_response, :redirect, :last_uri
|
27
27
|
|
28
28
|
def initialize(http_method, path, o={})
|
29
29
|
self.http_method = http_method
|
@@ -41,7 +41,7 @@ module HTTParty
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def uri
|
44
|
-
new_uri = path.relative? ? URI.parse("#{
|
44
|
+
new_uri = path.relative? ? URI.parse("#{base_uri}#{path}") : path
|
45
45
|
|
46
46
|
# avoid double query string on redirects [#12]
|
47
47
|
unless redirect
|
@@ -52,7 +52,11 @@ module HTTParty
|
|
52
52
|
raise UnsupportedURIScheme, "'#{new_uri}' Must be HTTP or HTTPS"
|
53
53
|
end
|
54
54
|
|
55
|
-
new_uri
|
55
|
+
@last_uri = new_uri
|
56
|
+
end
|
57
|
+
|
58
|
+
def base_uri
|
59
|
+
redirect ? "#{@last_uri.scheme}://#{@last_uri.host}" : options[:base_uri]
|
56
60
|
end
|
57
61
|
|
58
62
|
def format
|
@@ -139,7 +143,7 @@ module HTTParty
|
|
139
143
|
if query_string_normalizer
|
140
144
|
query_string_normalizer.call(query)
|
141
145
|
else
|
142
|
-
|
146
|
+
HashConversions.to_params(query)
|
143
147
|
end
|
144
148
|
end
|
145
149
|
|
data/lib/httparty/version.rb
CHANGED
@@ -129,13 +129,13 @@ describe HTTParty::Parser do
|
|
129
129
|
HTTParty::Parser.new('body', nil)
|
130
130
|
end
|
131
131
|
|
132
|
-
it "parses xml with
|
133
|
-
|
132
|
+
it "parses xml with MultiXml" do
|
133
|
+
MultiXml.should_receive(:parse).with('body')
|
134
134
|
subject.send(:xml)
|
135
135
|
end
|
136
136
|
|
137
|
-
it "parses json with
|
138
|
-
|
137
|
+
it "parses json with MultiJson" do
|
138
|
+
MultiJson.should_receive(:decode).with('body')
|
139
139
|
subject.send(:json)
|
140
140
|
end
|
141
141
|
|
@@ -326,7 +326,12 @@ describe HTTParty::Request do
|
|
326
326
|
redirect['location'] = 'http://foo.com/foo'
|
327
327
|
ok = stub_response('<hash><foo>bar</foo></hash>', 200)
|
328
328
|
@http.stub!(:request).and_return(redirect, ok)
|
329
|
-
@request.perform
|
329
|
+
response = @request.perform
|
330
|
+
response.request.base_uri.to_s.should == "http://foo.com"
|
331
|
+
response.request.path.to_s.should == "http://foo.com/foo"
|
332
|
+
response.request.uri.request_uri.should == "/foo"
|
333
|
+
response.request.uri.to_s.should == "http://foo.com/foo"
|
334
|
+
response.should == {"hash" => {"foo" => "bar"}}
|
330
335
|
end
|
331
336
|
|
332
337
|
it "redirects if a 300 contains a relative location header" do
|
@@ -335,7 +340,23 @@ describe HTTParty::Request do
|
|
335
340
|
ok = stub_response('<hash><foo>bar</foo></hash>', 200)
|
336
341
|
@http.stub!(:request).and_return(redirect, ok)
|
337
342
|
response = @request.perform
|
343
|
+
response.request.base_uri.to_s.should == "http://api.foo.com"
|
344
|
+
response.request.path.to_s.should == "/foo/bar"
|
338
345
|
response.request.uri.request_uri.should == "/foo/bar"
|
346
|
+
response.request.uri.to_s.should == "http://api.foo.com/foo/bar"
|
347
|
+
response.should == {"hash" => {"foo" => "bar"}}
|
348
|
+
end
|
349
|
+
|
350
|
+
it "handles multiple redirects and relative location headers on different hosts" do
|
351
|
+
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', :format => :xml)
|
352
|
+
FakeWeb.register_uri(:get, "http://test.com/redirect", :status => [300, "REDIRECT"], :location => "http://api.foo.com/v2")
|
353
|
+
FakeWeb.register_uri(:get, "http://api.foo.com/v2", :status => [300, "REDIRECT"], :location => "/v3")
|
354
|
+
FakeWeb.register_uri(:get, "http://api.foo.com/v3", :body => "<hash><foo>bar</foo></hash>")
|
355
|
+
response = @request.perform
|
356
|
+
response.request.base_uri.to_s.should == "http://api.foo.com"
|
357
|
+
response.request.path.to_s.should == "/v3"
|
358
|
+
response.request.uri.request_uri.should == "/v3"
|
359
|
+
response.request.uri.to_s.should == "http://api.foo.com/v3"
|
339
360
|
response.should == {"hash" => {"foo" => "bar"}}
|
340
361
|
end
|
341
362
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 7
|
9
8
|
- 8
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Nunemaker
|
@@ -16,102 +16,36 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-09-13 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: multi_json
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 3
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
|
33
|
-
- 8
|
34
|
-
version: 0.1.8
|
32
|
+
version: "0"
|
35
33
|
type: :runtime
|
36
34
|
version_requirements: *id001
|
37
35
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
36
|
+
name: multi_xml
|
39
37
|
prerelease: false
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 5
|
46
|
-
segments:
|
47
|
-
- 2
|
48
|
-
- 3
|
49
|
-
version: "2.3"
|
50
|
-
type: :development
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: cucumber
|
54
|
-
prerelease: false
|
55
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - ~>
|
41
|
+
- - ">="
|
59
42
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
43
|
+
hash: 3
|
61
44
|
segments:
|
62
45
|
- 0
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
version_requirements: *id003
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: fakeweb
|
69
|
-
prerelease: false
|
70
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
|
-
requirements:
|
73
|
-
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 11
|
76
|
-
segments:
|
77
|
-
- 1
|
78
|
-
- 2
|
79
|
-
version: "1.2"
|
80
|
-
type: :development
|
81
|
-
version_requirements: *id004
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: rspec
|
84
|
-
prerelease: false
|
85
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
|
-
requirements:
|
88
|
-
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
hash: 9
|
91
|
-
segments:
|
92
|
-
- 1
|
93
|
-
- 3
|
94
|
-
version: "1.3"
|
95
|
-
type: :development
|
96
|
-
version_requirements: *id005
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: mongrel
|
99
|
-
prerelease: false
|
100
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
|
-
requirements:
|
103
|
-
- - "="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
hash: 1923831981
|
106
|
-
segments:
|
107
|
-
- 1
|
108
|
-
- 2
|
109
|
-
- 0
|
110
|
-
- pre
|
111
|
-
- 2
|
112
|
-
version: 1.2.0.pre2
|
113
|
-
type: :development
|
114
|
-
version_requirements: *id006
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
115
49
|
description: Makes http fun! Also, makes consuming restful web services dead easy.
|
116
50
|
email:
|
117
51
|
- nunemaker@gmail.com
|
@@ -157,6 +91,7 @@ files:
|
|
157
91
|
- lib/httparty/cookie_hash.rb
|
158
92
|
- lib/httparty/core_extensions.rb
|
159
93
|
- lib/httparty/exceptions.rb
|
94
|
+
- lib/httparty/hash_conversions.rb
|
160
95
|
- lib/httparty/module_inheritable_attributes.rb
|
161
96
|
- lib/httparty/net_digest_auth.rb
|
162
97
|
- lib/httparty/parser.rb
|
@@ -221,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
156
|
requirements: []
|
222
157
|
|
223
158
|
rubyforge_project:
|
224
|
-
rubygems_version: 1.
|
159
|
+
rubygems_version: 1.8.9
|
225
160
|
signing_key:
|
226
161
|
specification_version: 3
|
227
162
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|
@@ -266,4 +201,3 @@ test_files:
|
|
266
201
|
- spec/support/ssl_test_helper.rb
|
267
202
|
- spec/support/ssl_test_server.rb
|
268
203
|
- spec/support/stub_response.rb
|
269
|
-
has_rdoc:
|