httparty 0.5.2 → 0.6.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/History +18 -0
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/examples/aaws.rb +2 -2
- data/features/digest_authentication.feature +20 -0
- data/features/handles_compressed_responses.feature +19 -0
- data/features/steps/env.rb +9 -2
- data/features/steps/httparty_steps.rb +8 -0
- data/features/steps/mongrel_helper.rb +72 -35
- data/features/steps/remote_service_steps.rb +22 -5
- data/features/supports_timeout_option.feature +1 -0
- data/httparty.gemspec +15 -12
- data/lib/httparty.rb +47 -6
- data/lib/httparty/net_digest_auth.rb +35 -0
- data/lib/httparty/request.rb +121 -100
- data/lib/httparty/response.rb +55 -10
- data/spec/httparty/request_spec.rb +65 -2
- data/spec/httparty/response_spec.rb +53 -32
- data/spec/httparty_spec.rb +31 -1
- data/spec/spec_helper.rb +6 -2
- data/spec/support/stub_response.rb +1 -1
- metadata +62 -33
@@ -1,62 +1,83 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
3
|
describe HTTParty::Response do
|
4
|
+
before do
|
5
|
+
@last_modified = Date.new(2010, 1, 15).to_s
|
6
|
+
@content_length = '1024'
|
7
|
+
@response_object = {'foo' => 'bar'}
|
8
|
+
@response_object = Net::HTTPOK.new('1.1', 200, 'OK')
|
9
|
+
@response_object.stub(:body => "{foo:'bar'}")
|
10
|
+
@response_object['last-modified'] = @last_modified
|
11
|
+
@response_object['content-length'] = @content_length
|
12
|
+
@parsed_response = {"foo" => "bar"}
|
13
|
+
@response = HTTParty::Response.new(@response_object, @parsed_response)
|
14
|
+
end
|
15
|
+
|
4
16
|
describe "initialization" do
|
5
|
-
|
6
|
-
@
|
7
|
-
@body = "{foo:'bar'}"
|
8
|
-
@code = '200'
|
9
|
-
@message = 'OK'
|
10
|
-
@response = HTTParty::Response.new(@response_object, @body, @code, @message)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should set delegate" do
|
14
|
-
@response.delegate.should == @response_object
|
17
|
+
it "should set the Net::HTTP Response" do
|
18
|
+
@response.response.should == @response_object
|
15
19
|
end
|
16
|
-
|
20
|
+
|
17
21
|
it "should set body" do
|
18
|
-
@response.body.should == @body
|
22
|
+
@response.body.should == @response_object.body
|
19
23
|
end
|
20
|
-
|
24
|
+
|
21
25
|
it "should set code" do
|
22
|
-
@response.code.should.to_s == @code
|
26
|
+
@response.code.should.to_s == @response_object.code
|
23
27
|
end
|
24
28
|
|
25
29
|
it "should set code as a Fixnum" do
|
26
30
|
@response.code.should be_an_instance_of(Fixnum)
|
27
31
|
end
|
28
|
-
|
29
|
-
it "should set body" do
|
30
|
-
@response.body.should == @body
|
31
|
-
end
|
32
32
|
end
|
33
|
-
|
34
|
-
it "
|
35
|
-
response = HTTParty::Response.new(
|
36
|
-
response.headers.should == {'
|
33
|
+
|
34
|
+
it "returns response headers" do
|
35
|
+
response = HTTParty::Response.new(@response_object, @parsed_response)
|
36
|
+
response.headers.should == {'last-modified' => [@last_modified], 'content-length' => [@content_length]}
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should send missing methods to delegate" do
|
40
|
-
response = HTTParty::Response.new({'foo' => 'bar'}
|
40
|
+
response = HTTParty::Response.new(@response_object, {'foo' => 'bar'})
|
41
41
|
response['foo'].should == 'bar'
|
42
42
|
end
|
43
|
-
|
44
|
-
it "should be able to iterate
|
45
|
-
response = HTTParty::Response.new([{'foo' => 'bar'}, {'foo' => 'baz'}]
|
43
|
+
|
44
|
+
it "should be able to iterate if it is array" do
|
45
|
+
response = HTTParty::Response.new(@response_object, [{'foo' => 'bar'}, {'foo' => 'baz'}])
|
46
46
|
response.size.should == 2
|
47
|
-
|
47
|
+
expect {
|
48
48
|
response.each { |item| }
|
49
|
-
}.
|
49
|
+
}.to_not raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
it "allows headers to be accessed by mixed-case names in hash notation" do
|
53
|
+
response = HTTParty::Response.new(@response_object, @parsed_response)
|
54
|
+
response.headers['Content-LENGTH'].should == @content_length
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns a comma-delimited value when multiple values exist" do
|
58
|
+
@response_object.add_field 'set-cookie', 'csrf_id=12345; path=/'
|
59
|
+
@response_object.add_field 'set-cookie', '_github_ses=A123CdE; path=/'
|
60
|
+
response = HTTParty::Response.new(@response_object, @parsed_response)
|
61
|
+
response.headers['set-cookie'].should == "csrf_id=12345; path=/, _github_ses=A123CdE; path=/"
|
50
62
|
end
|
51
|
-
|
63
|
+
|
64
|
+
# Backwards-compatibility - previously, #headers returned a Hash
|
65
|
+
it "responds to hash methods" do
|
66
|
+
response = HTTParty::Response.new(@response_object, @parsed_response)
|
67
|
+
hash_methods = {}.methods - response.headers.methods
|
68
|
+
hash_methods.each do |method_name|
|
69
|
+
response.headers.respond_to?(method_name).should be_true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
52
73
|
xit "should allow hashes to be accessed with dot notation" do
|
53
74
|
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200, 'OK')
|
54
75
|
response.foo.should == 'bar'
|
55
76
|
end
|
56
|
-
|
77
|
+
|
57
78
|
xit "should allow nested hashes to be accessed with dot notation" do
|
58
79
|
response = HTTParty::Response.new({'foo' => {'bar' => 'baz'}}, "{foo: {bar:'baz'}}", 200, 'OK')
|
59
80
|
response.foo.should == {'bar' => 'baz'}
|
60
81
|
response.foo.bar.should == 'baz'
|
61
82
|
end
|
62
|
-
end
|
83
|
+
end
|
data/spec/httparty_spec.rb
CHANGED
@@ -203,6 +203,17 @@ describe HTTParty do
|
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
+
describe "default timeout" do
|
207
|
+
it "should default to nil" do
|
208
|
+
@klass.default_options[:timeout].should == nil
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should support updating" do
|
212
|
+
@klass.default_timeout 10
|
213
|
+
@klass.default_options[:timeout].should == 10
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
206
217
|
describe "debug_output" do
|
207
218
|
it "stores the given stream as a default_option" do
|
208
219
|
@klass.debug_output $stdout
|
@@ -222,6 +233,13 @@ describe HTTParty do
|
|
222
233
|
end
|
223
234
|
end
|
224
235
|
|
236
|
+
describe "digest http authentication" do
|
237
|
+
it "should work" do
|
238
|
+
@klass.digest_auth 'foobar', 'secret'
|
239
|
+
@klass.default_options[:digest_auth].should == {:username => 'foobar', :password => 'secret'}
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
225
243
|
describe "parser" do
|
226
244
|
let(:parser) do
|
227
245
|
Proc.new{ |data, format| CustomParser.parse(data) }
|
@@ -243,7 +261,7 @@ describe HTTParty do
|
|
243
261
|
@klass.format :json
|
244
262
|
class MyParser < HTTParty::Parser
|
245
263
|
SupportedFormats = {}
|
246
|
-
end
|
264
|
+
end unless defined?(MyParser)
|
247
265
|
expect do
|
248
266
|
@klass.parser MyParser
|
249
267
|
end.to raise_error(HTTParty::UnsupportedFormat)
|
@@ -316,6 +334,18 @@ describe HTTParty do
|
|
316
334
|
end
|
317
335
|
end
|
318
336
|
|
337
|
+
describe "#maintain_method_across_redirects" do
|
338
|
+
it "sets maintain_method_across_redirects to true by default" do
|
339
|
+
@klass.maintain_method_across_redirects
|
340
|
+
@klass.default_options[:maintain_method_across_redirects].should be_true
|
341
|
+
end
|
342
|
+
|
343
|
+
it "sets the maintain_method_across_redirects option to false" do
|
344
|
+
@klass.maintain_method_across_redirects false
|
345
|
+
@klass.default_options[:maintain_method_across_redirects].should be_false
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
319
349
|
describe "with explicit override of automatic redirect handling" do
|
320
350
|
before do
|
321
351
|
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', :format => :xml, :no_follow => true)
|
data/spec/spec_helper.rb
CHANGED
@@ -2,8 +2,6 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'httparty')
|
|
2
2
|
require 'spec/autorun'
|
3
3
|
require 'fakeweb'
|
4
4
|
|
5
|
-
FakeWeb.allow_net_connect = false
|
6
|
-
|
7
5
|
def file_fixture(filename)
|
8
6
|
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
|
9
7
|
end
|
@@ -12,4 +10,10 @@ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].e
|
|
12
10
|
|
13
11
|
Spec::Runner.configure do |config|
|
14
12
|
config.include HTTParty::StubResponse
|
13
|
+
config.before(:suite) do
|
14
|
+
FakeWeb.allow_net_connect = false
|
15
|
+
end
|
16
|
+
config.after(:suite) do
|
17
|
+
FakeWeb.allow_net_connect = true
|
18
|
+
end
|
15
19
|
end
|
@@ -14,7 +14,7 @@ module HTTParty
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def stub_response(body, code = 200)
|
17
|
-
unless @http
|
17
|
+
unless defined?(@http) && @http
|
18
18
|
@http = Net::HTTP.new('localhost', 80)
|
19
19
|
@request.stub!(:http).and_return(@http)
|
20
20
|
@request.stub!(:uri).and_return(URI.parse("http://foo.com/foobar"))
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 0.6.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- John Nunemaker
|
@@ -10,69 +15,88 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2010-
|
18
|
+
date: 2010-06-13 00:00:00 -04:00
|
14
19
|
default_executable: httparty
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: crack
|
18
|
-
|
19
|
-
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
25
|
requirements:
|
22
26
|
- - "="
|
23
27
|
- !ruby/object:Gem::Version
|
24
|
-
|
25
|
-
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
- 7
|
32
|
+
version: 0.1.7
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
26
35
|
- !ruby/object:Gem::Dependency
|
27
36
|
name: activesupport
|
28
|
-
|
29
|
-
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
39
|
requirements:
|
32
40
|
- - ~>
|
33
41
|
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 3
|
34
45
|
version: "2.3"
|
35
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
36
48
|
- !ruby/object:Gem::Dependency
|
37
49
|
name: cucumber
|
38
|
-
|
39
|
-
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
52
|
requirements:
|
42
53
|
- - ~>
|
43
54
|
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 7
|
58
|
+
version: "0.7"
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id003
|
46
61
|
- !ruby/object:Gem::Dependency
|
47
62
|
name: fakeweb
|
48
|
-
|
49
|
-
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - ~>
|
53
67
|
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 1
|
70
|
+
- 2
|
54
71
|
version: "1.2"
|
55
|
-
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
56
74
|
- !ruby/object:Gem::Dependency
|
57
75
|
name: mongrel
|
58
|
-
|
59
|
-
|
60
|
-
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
prerelease: false
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
61
78
|
requirements:
|
62
79
|
- - ~>
|
63
80
|
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 1
|
83
|
+
- 1
|
64
84
|
version: "1.1"
|
65
|
-
|
85
|
+
type: :development
|
86
|
+
version_requirements: *id005
|
66
87
|
- !ruby/object:Gem::Dependency
|
67
88
|
name: rspec
|
68
|
-
|
69
|
-
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
prerelease: false
|
90
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
71
91
|
requirements:
|
72
|
-
- -
|
92
|
+
- - ~>
|
73
93
|
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 3
|
97
|
+
version: "1.3"
|
98
|
+
type: :development
|
99
|
+
version_requirements: *id006
|
76
100
|
description: Makes http fun! Also, makes consuming restful web services dead easy.
|
77
101
|
email: nunemaker@gmail.com
|
78
102
|
executables:
|
@@ -102,6 +126,8 @@ files:
|
|
102
126
|
- features/basic_authentication.feature
|
103
127
|
- features/command_line.feature
|
104
128
|
- features/deals_with_http_error_codes.feature
|
129
|
+
- features/digest_authentication.feature
|
130
|
+
- features/handles_compressed_responses.feature
|
105
131
|
- features/handles_multiple_formats.feature
|
106
132
|
- features/steps/env.rb
|
107
133
|
- features/steps/httparty_response_steps.rb
|
@@ -116,6 +142,7 @@ files:
|
|
116
142
|
- lib/httparty/core_extensions.rb
|
117
143
|
- lib/httparty/exceptions.rb
|
118
144
|
- lib/httparty/module_inheritable_attributes.rb
|
145
|
+
- lib/httparty/net_digest_auth.rb
|
119
146
|
- lib/httparty/parser.rb
|
120
147
|
- lib/httparty/request.rb
|
121
148
|
- lib/httparty/response.rb
|
@@ -148,18 +175,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
175
|
requirements:
|
149
176
|
- - ">="
|
150
177
|
- !ruby/object:Gem::Version
|
178
|
+
segments:
|
179
|
+
- 0
|
151
180
|
version: "0"
|
152
|
-
version:
|
153
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
182
|
requirements:
|
155
183
|
- - ">="
|
156
184
|
- !ruby/object:Gem::Version
|
185
|
+
segments:
|
186
|
+
- 0
|
157
187
|
version: "0"
|
158
|
-
version:
|
159
188
|
requirements: []
|
160
189
|
|
161
190
|
rubyforge_project: httparty
|
162
|
-
rubygems_version: 1.3.
|
191
|
+
rubygems_version: 1.3.6
|
163
192
|
signing_key:
|
164
193
|
specification_version: 3
|
165
194
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|