httparty 0.13.1 → 0.13.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.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +3 -3
  3. data/History +74 -11
  4. data/README.md +4 -1
  5. data/Rakefile +1 -2
  6. data/bin/httparty +4 -4
  7. data/examples/README.md +64 -0
  8. data/examples/aaws.rb +3 -3
  9. data/examples/basic.rb +5 -5
  10. data/examples/crack.rb +1 -1
  11. data/examples/delicious.rb +5 -5
  12. data/examples/headers_and_user_agents.rb +1 -1
  13. data/examples/logging.rb +38 -0
  14. data/examples/rubyurl.rb +1 -1
  15. data/examples/stackexchange.rb +1 -1
  16. data/examples/tripit_sign_in.rb +5 -5
  17. data/examples/twitter.rb +5 -5
  18. data/examples/whoismyrep.rb +1 -1
  19. data/features/steps/httparty_steps.rb +2 -2
  20. data/httparty.gemspec +2 -0
  21. data/lib/httparty.rb +35 -17
  22. data/lib/httparty/connection_adapter.rb +4 -2
  23. data/lib/httparty/cookie_hash.rb +1 -1
  24. data/lib/httparty/hash_conversions.rb +12 -12
  25. data/lib/httparty/logger/apache_logger.rb +1 -1
  26. data/lib/httparty/logger/logger.rb +1 -1
  27. data/lib/httparty/net_digest_auth.rb +4 -1
  28. data/lib/httparty/request.rb +41 -21
  29. data/lib/httparty/version.rb +1 -1
  30. data/spec/httparty/connection_adapter_spec.rb +52 -36
  31. data/spec/httparty/cookie_hash_spec.rb +8 -8
  32. data/spec/httparty/logger/apache_logger_spec.rb +29 -14
  33. data/spec/httparty/net_digest_auth_spec.rb +11 -0
  34. data/spec/httparty/parser_spec.rb +10 -10
  35. data/spec/httparty/request_spec.rb +209 -30
  36. data/spec/httparty/response_spec.rb +41 -41
  37. data/spec/httparty/ssl_spec.rb +4 -4
  38. data/spec/httparty_spec.rb +78 -59
  39. data/spec/support/ssl_test_helper.rb +6 -6
  40. data/spec/support/stub_response.rb +2 -2
  41. data/website/index.html +3 -3
  42. metadata +15 -14
  43. data/spec/spec.opts +0 -2
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
3
  describe HTTParty::Request do
4
4
  before do
5
- @request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', :format => :xml)
5
+ @request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml)
6
6
  end
7
7
 
8
8
  describe "::NON_RAILS_QUERY_STRING_NORMALIZER" do
@@ -16,19 +16,19 @@ describe HTTParty::Request do
16
16
  context "when the query is an array" do
17
17
 
18
18
  it "doesn't include brackets" do
19
- query_string = normalizer[{:page => 1, :foo => %w(bar baz)}]
19
+ query_string = normalizer[{page: 1, foo: %w(bar baz)}]
20
20
  URI.unescape(query_string).should == "foo=bar&foo=baz&page=1"
21
21
  end
22
22
 
23
23
  it "URI encodes array values" do
24
- query_string = normalizer[{:people => ["Otis Redding", "Bob Marley", "Tim & Jon"], :page => 1, :xyzzy => 3}]
24
+ query_string = normalizer[{people: ["Otis Redding", "Bob Marley", "Tim & Jon"], page: 1, xyzzy: 3}]
25
25
  query_string.should == "page=1&people=Otis%20Redding&people=Bob%20Marley&people=Tim%20%26%20Jon&xyzzy=3"
26
26
  end
27
27
  end
28
28
 
29
29
  context "when the query is a hash" do
30
30
  it "correctly handles nil values" do
31
- query_string = normalizer[{:page => 1, :per_page => nil}]
31
+ query_string = normalizer[{page: 1, per_page: nil}]
32
32
  query_string.should == "page=1&per_page"
33
33
  end
34
34
  end
@@ -42,7 +42,7 @@ describe HTTParty::Request do
42
42
 
43
43
  it "sets parser to the optional parser" do
44
44
  my_parser = lambda {}
45
- request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', :parser => my_parser)
45
+ request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', parser: my_parser)
46
46
  request.parser.should == my_parser
47
47
  end
48
48
 
@@ -53,15 +53,32 @@ describe HTTParty::Request do
53
53
 
54
54
  it "sets connection_adapter to the optional connection_adapter" do
55
55
  my_adapter = lambda {}
56
- request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', :connection_adapter => my_adapter)
56
+ request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', connection_adapter: my_adapter)
57
57
  request.connection_adapter.should == my_adapter
58
58
  end
59
+
60
+ context "when basic authentication credentials provided in uri" do
61
+ context "when basic auth options wasn't set explicitly" do
62
+ it "sets basic auth from uri" do
63
+ request = HTTParty::Request.new(Net::HTTP::Get, 'http://user1:pass1@example.com')
64
+ request.options[:basic_auth].should == {:username => 'user1', :password => 'pass1'}
65
+ end
66
+ end
67
+
68
+ context "when basic auth options was set explicitly" do
69
+ it "uses basic auth from url anyway" do
70
+ basic_auth = {:username => 'user2', :password => 'pass2'}
71
+ request = HTTParty::Request.new(Net::HTTP::Get, 'http://user1:pass1@example.com', :basic_auth => basic_auth)
72
+ request.options[:basic_auth].should == {:username => 'user1', :password => 'pass1'}
73
+ end
74
+ end
75
+ end
59
76
  end
60
77
 
61
78
  describe "#format" do
62
79
  context "request yet to be made" do
63
80
  it "returns format option" do
64
- request = HTTParty::Request.new 'get', '/', :format => :xml
81
+ request = HTTParty::Request.new 'get', '/', format: :xml
65
82
  request.format.should == :xml
66
83
  end
67
84
 
@@ -73,7 +90,7 @@ describe HTTParty::Request do
73
90
 
74
91
  context "request has been made" do
75
92
  it "returns format option" do
76
- request = HTTParty::Request.new 'get', '/', :format => :xml
93
+ request = HTTParty::Request.new 'get', '/', format: :xml
77
94
  request.last_response = stub
78
95
  request.format.should == :xml
79
96
  end
@@ -91,16 +108,16 @@ describe HTTParty::Request do
91
108
 
92
109
  context "options" do
93
110
  it "should use basic auth when configured" do
94
- @request.options[:basic_auth] = {:username => 'foobar', :password => 'secret'}
111
+ @request.options[:basic_auth] = {username: 'foobar', password: 'secret'}
95
112
  @request.send(:setup_raw_request)
96
113
  @request.instance_variable_get(:@raw_request)['authorization'].should_not be_nil
97
114
  end
98
115
 
99
116
  it "should use digest auth when configured" do
100
117
  FakeWeb.register_uri(:get, "http://api.foo.com/v1",
101
- :www_authenticate => 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false')
118
+ www_authenticate: 'Digest realm="Log Viewer", qop="auth", nonce="2CA0EC6B0E126C4800E56BA0C0003D3C", opaque="5ccc069c403ebaf9f0171e9517f40e41", stale=false')
102
119
 
103
- @request.options[:digest_auth] = {:username => 'foobar', :password => 'secret'}
120
+ @request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
104
121
  @request.send(:setup_raw_request)
105
122
 
106
123
  raw_request = @request.instance_variable_get(:@raw_request)
@@ -108,13 +125,13 @@ describe HTTParty::Request do
108
125
  end
109
126
 
110
127
  it "should use the right http method for digest authentication" do
111
- @post_request = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml)
128
+ @post_request = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', format: :xml)
112
129
  FakeWeb.register_uri(:post, "http://api.foo.com/v1", {})
113
130
 
114
131
  http = @post_request.send(:http)
115
132
  @post_request.should_receive(:http).and_return(http)
116
133
  http.should_not_receive(:head).and_return({'www-authenticate' => nil})
117
- @post_request.options[:digest_auth] = {:username => 'foobar', :password => 'secret'}
134
+ @post_request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
118
135
  @post_request.send(:setup_raw_request)
119
136
  end
120
137
 
@@ -127,6 +144,32 @@ describe HTTParty::Request do
127
144
  end
128
145
 
129
146
  describe "#uri" do
147
+ context "redirects" do
148
+ it "returns correct path when the server sets the location header to a filename" do
149
+ @request.last_uri = URI.parse("http://example.com/foo/bar")
150
+ @request.path = URI.parse("bar?foo=bar")
151
+ @request.redirect = true
152
+
153
+ @request.uri.should == URI.parse("http://example.com/foo/bar?foo=bar")
154
+ end
155
+
156
+ it "returns correct path when the server sets the location header to an absolute path" do
157
+ @request.last_uri = URI.parse("http://example.com/foo/bar")
158
+ @request.path = URI.parse("/bar?foo=bar")
159
+ @request.redirect = true
160
+
161
+ @request.uri.should == URI.parse("http://example.com/bar?foo=bar")
162
+ end
163
+
164
+ it "returns correct path when the server sets the location header to a full uri" do
165
+ @request.last_uri = URI.parse("http://example.com/foo/bar")
166
+ @request.path = URI.parse("http://example.com/bar?foo=bar")
167
+ @request.redirect = true
168
+
169
+ @request.uri.should == URI.parse("http://example.com/bar?foo=bar")
170
+ end
171
+ end
172
+
130
173
  context "query strings" do
131
174
  it "does not add an empty query string when default_params are blank" do
132
175
  @request.options[:default_params] = {}
@@ -136,7 +179,7 @@ describe HTTParty::Request do
136
179
  it "respects the query string normalization proc" do
137
180
  empty_proc = lambda {|qs| ""}
138
181
  @request.options[:query_string_normalizer] = empty_proc
139
- @request.options[:query] = {:foo => :bar}
182
+ @request.options[:query] = {foo: :bar}
140
183
  URI.unescape(@request.uri.query).should == ""
141
184
  end
142
185
 
@@ -147,14 +190,14 @@ describe HTTParty::Request do
147
190
  end
148
191
 
149
192
  it "does not duplicate query string parameters when uri is called twice" do
150
- @request.options[:query] = {:foo => :bar}
193
+ @request.options[:query] = {foo: :bar}
151
194
  @request.uri
152
195
  @request.uri.query.should == "foo=bar"
153
196
  end
154
197
 
155
198
  context "when representing an array" do
156
199
  it "returns a Rails style query string" do
157
- @request.options[:query] = {:foo => %w(bar baz)}
200
+ @request.options[:query] = {foo: %w(bar baz)}
158
201
  URI.unescape(@request.uri.query).should == "foo[]=bar&foo[]=baz"
159
202
  end
160
203
  end
@@ -166,7 +209,7 @@ describe HTTParty::Request do
166
209
  context "when query_string_normalizer is set" do
167
210
  it "sets the body to the return value of the proc" do
168
211
  @request.options[:query_string_normalizer] = HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER
169
- @request.options[:body] = {:page => 1, :foo => %w(bar baz)}
212
+ @request.options[:body] = {page: 1, foo: %w(bar baz)}
170
213
  @request.send(:setup_raw_request)
171
214
  body = @request.instance_variable_get(:@raw_request).body
172
215
  URI.unescape(body).should == "foo=bar&foo=baz&page=1"
@@ -178,7 +221,7 @@ describe HTTParty::Request do
178
221
  it "should get a connection from the connection_adapter" do
179
222
  http = Net::HTTP.new('google.com')
180
223
  adapter = mock('adapter')
181
- request = HTTParty::Request.new(Net::HTTP::Get, 'https://api.foo.com/v1:443', :connection_adapter => adapter)
224
+ request = HTTParty::Request.new(Net::HTTP::Get, 'https://api.foo.com/v1:443', connection_adapter: adapter)
182
225
  adapter.should_receive(:call).with(request.uri, request.options).and_return(http)
183
226
  request.send(:http).should be http
184
227
  end
@@ -371,9 +414,9 @@ describe HTTParty::Request do
371
414
  end
372
415
 
373
416
  it "calls block given to perform with each redirect" do
374
- @request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', :format => :xml)
375
- FakeWeb.register_uri(:get, "http://test.com/redirect", :status => [300, "REDIRECT"], :location => "http://api.foo.com/v2")
376
- FakeWeb.register_uri(:get, "http://api.foo.com/v2", :body => "<hash><foo>bar</foo></hash>")
417
+ @request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', format: :xml)
418
+ FakeWeb.register_uri(:get, "http://test.com/redirect", status: [300, "REDIRECT"], location: "http://api.foo.com/v2")
419
+ FakeWeb.register_uri(:get, "http://api.foo.com/v2", body: "<hash><foo>bar</foo></hash>")
377
420
  body = ""
378
421
  response = @request.perform { |chunk| body += chunk }
379
422
  body.length.should == 27
@@ -393,10 +436,10 @@ describe HTTParty::Request do
393
436
  end
394
437
 
395
438
  it "handles multiple redirects and relative location headers on different hosts" do
396
- @request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', :format => :xml)
397
- FakeWeb.register_uri(:get, "http://test.com/redirect", :status => [300, "REDIRECT"], :location => "http://api.foo.com/v2")
398
- FakeWeb.register_uri(:get, "http://api.foo.com/v2", :status => [300, "REDIRECT"], :location => "/v3")
399
- FakeWeb.register_uri(:get, "http://api.foo.com/v3", :body => "<hash><foo>bar</foo></hash>")
439
+ @request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', format: :xml)
440
+ FakeWeb.register_uri(:get, "http://test.com/redirect", status: [300, "REDIRECT"], location: "http://api.foo.com/v2")
441
+ FakeWeb.register_uri(:get, "http://api.foo.com/v2", status: [300, "REDIRECT"], location: "/v3")
442
+ FakeWeb.register_uri(:get, "http://api.foo.com/v3", body: "<hash><foo>bar</foo></hash>")
400
443
  response = @request.perform
401
444
  response.request.base_uri.to_s.should == "http://api.foo.com"
402
445
  response.request.path.to_s.should == "/v3"
@@ -454,7 +497,7 @@ describe HTTParty::Request do
454
497
  @request.perform.should == 'Content for you'
455
498
  end
456
499
 
457
- describe "a request that redirects" do
500
+ describe "a request that 302 redirects" do
458
501
  before(:each) do
459
502
  @redirect = stub_response("", 302)
460
503
  @redirect['location'] = '/foo'
@@ -574,6 +617,142 @@ describe HTTParty::Request do
574
617
  end
575
618
  end
576
619
 
620
+ describe "a request that 303 redirects" do
621
+ before(:each) do
622
+ @redirect = stub_response("", 303)
623
+ @redirect['location'] = '/foo'
624
+
625
+ @ok = stub_response('<hash><foo>bar</foo></hash>', 200)
626
+ end
627
+
628
+ describe "once" do
629
+ before(:each) do
630
+ @http.stub!(:request).and_return(@redirect, @ok)
631
+ end
632
+
633
+ it "should be handled by GET transparently" do
634
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
635
+ end
636
+
637
+ it "should be handled by POST transparently" do
638
+ @request.http_method = Net::HTTP::Post
639
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
640
+ end
641
+
642
+ it "should be handled by DELETE transparently" do
643
+ @request.http_method = Net::HTTP::Delete
644
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
645
+ end
646
+
647
+ it "should be handled by MOVE transparently" do
648
+ @request.http_method = Net::HTTP::Move
649
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
650
+ end
651
+
652
+ it "should be handled by COPY transparently" do
653
+ @request.http_method = Net::HTTP::Copy
654
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
655
+ end
656
+
657
+ it "should be handled by PATCH transparently" do
658
+ @request.http_method = Net::HTTP::Patch
659
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
660
+ end
661
+
662
+ it "should be handled by PUT transparently" do
663
+ @request.http_method = Net::HTTP::Put
664
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
665
+ end
666
+
667
+ it "should be handled by HEAD transparently" do
668
+ @request.http_method = Net::HTTP::Head
669
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
670
+ end
671
+
672
+ it "should be handled by OPTIONS transparently" do
673
+ @request.http_method = Net::HTTP::Options
674
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
675
+ end
676
+
677
+ it "should keep track of cookies between redirects" do
678
+ @redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly'
679
+ @request.perform
680
+ @request.options[:headers]['Cookie'].should match(/foo=bar/)
681
+ @request.options[:headers]['Cookie'].should match(/name=value/)
682
+ end
683
+
684
+ it 'should update cookies with rediects' do
685
+ @request.options[:headers] = {'Cookie'=> 'foo=bar;'}
686
+ @redirect['Set-Cookie'] = 'foo=tar;'
687
+ @request.perform
688
+ @request.options[:headers]['Cookie'].should match(/foo=tar/)
689
+ end
690
+
691
+ it 'should keep cookies between rediects' do
692
+ @request.options[:headers] = {'Cookie'=> 'keep=me'}
693
+ @redirect['Set-Cookie'] = 'foo=tar;'
694
+ @request.perform
695
+ @request.options[:headers]['Cookie'].should match(/keep=me/)
696
+ end
697
+
698
+ it "should handle multiple Set-Cookie headers between redirects" do
699
+ @redirect.add_field 'set-cookie', 'foo=bar; name=value; HTTPOnly'
700
+ @redirect.add_field 'set-cookie', 'one=1; two=2; HTTPOnly'
701
+ @request.perform
702
+ @request.options[:headers]['Cookie'].should match(/foo=bar/)
703
+ @request.options[:headers]['Cookie'].should match(/name=value/)
704
+ @request.options[:headers]['Cookie'].should match(/one=1/)
705
+ @request.options[:headers]['Cookie'].should match(/two=2/)
706
+ end
707
+
708
+ it 'should make resulting request a get request if it not already' do
709
+ @request.http_method = Net::HTTP::Delete
710
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
711
+ @request.http_method.should == Net::HTTP::Get
712
+ end
713
+
714
+ it 'should make resulting request a get request if options[:maintain_method_across_redirects] is false' do
715
+ @request.options[:maintain_method_across_redirects] = false
716
+ @request.http_method = Net::HTTP::Delete
717
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
718
+ @request.http_method.should == Net::HTTP::Get
719
+ end
720
+
721
+ it 'should make resulting request a get request if options[:maintain_method_across_redirects] is true but options[:resend_on_redirect] is false' do
722
+ @request.options[:maintain_method_across_redirects] = true
723
+ @request.options[:resend_on_redirect] = false
724
+ @request.http_method = Net::HTTP::Delete
725
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
726
+ @request.http_method.should == Net::HTTP::Get
727
+ end
728
+
729
+ it 'should not make resulting request a get request if options[:maintain_method_across_redirects] and options[:resend_on_redirect] is true' do
730
+ @request.options[:maintain_method_across_redirects] = true
731
+ @request.options[:resend_on_redirect] = true
732
+ @request.http_method = Net::HTTP::Delete
733
+ @request.perform.should == {"hash" => {"foo" => "bar"}}
734
+ @request.http_method.should == Net::HTTP::Delete
735
+ end
736
+
737
+ it 'should log the redirection' do
738
+ logger_double = double
739
+ logger_double.should_receive(:info).twice
740
+ @request.options[:logger] = logger_double
741
+ @request.perform
742
+ end
743
+ end
744
+
745
+ describe "infinitely" do
746
+ before(:each) do
747
+ @http.stub!(:request).and_return(@redirect)
748
+ end
749
+
750
+ it "should raise an exception" do
751
+ lambda { @request.perform }.should raise_error(HTTParty::RedirectionTooDeep)
752
+ end
753
+ end
754
+ end
755
+
577
756
  describe "#handle_deflation" do
578
757
  context "context-encoding" do
579
758
  before do
@@ -611,7 +790,7 @@ describe HTTParty::Request do
611
790
  context "with POST http method" do
612
791
  it "should raise argument error if query is not a hash" do
613
792
  lambda {
614
- HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml, :query => 'astring').perform
793
+ HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', format: :xml, query: 'astring').perform
615
794
  }.should raise_error(ArgumentError)
616
795
  end
617
796
  end
@@ -619,19 +798,19 @@ describe HTTParty::Request do
619
798
  describe "argument validation" do
620
799
  it "should raise argument error if basic_auth and digest_auth are both present" do
621
800
  lambda {
622
- HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :basic_auth => {}, :digest_auth => {}).perform
801
+ HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', basic_auth: {}, digest_auth: {}).perform
623
802
  }.should raise_error(ArgumentError, "only one authentication method, :basic_auth or :digest_auth may be used at a time")
624
803
  end
625
804
 
626
805
  it "should raise argument error if basic_auth is not a hash" do
627
806
  lambda {
628
- HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :basic_auth => ["foo", "bar"]).perform
807
+ HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', basic_auth: ["foo", "bar"]).perform
629
808
  }.should raise_error(ArgumentError, ":basic_auth must be a hash")
630
809
  end
631
810
 
632
811
  it "should raise argument error if digest_auth is not a hash" do
633
812
  lambda {
634
- HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :digest_auth => ["foo", "bar"]).perform
813
+ HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', digest_auth: ["foo", "bar"]).perform
635
814
  }.should raise_error(ArgumentError, ":digest_auth must be a hash")
636
815
  end
637
816
  end
@@ -6,7 +6,7 @@ describe HTTParty::Response do
6
6
  @content_length = '1024'
7
7
  @request_object = HTTParty::Request.new Net::HTTP::Get, '/'
8
8
  @response_object = Net::HTTPOK.new('1.1', 200, 'OK')
9
- @response_object.stub(:body => "{foo:'bar'}")
9
+ @response_object.stub(body: "{foo:'bar'}")
10
10
  @response_object['last-modified'] = @last_modified
11
11
  @response_object['content-length'] = @content_length
12
12
  @parsed_response = lambda { {"foo" => "bar"} }
@@ -155,46 +155,46 @@ describe HTTParty::Response do
155
155
 
156
156
  context "for specific codes" do
157
157
  SPECIFIC_CODES = {
158
- :accepted? => Net::HTTPAccepted,
159
- :bad_gateway? => Net::HTTPBadGateway,
160
- :bad_request? => Net::HTTPBadRequest,
161
- :conflict? => Net::HTTPConflict,
162
- :continue? => Net::HTTPContinue,
163
- :created? => Net::HTTPCreated,
164
- :expectation_failed? => Net::HTTPExpectationFailed,
165
- :forbidden? => Net::HTTPForbidden,
166
- :found? => Net::HTTPFound,
167
- :gateway_time_out? => Net::HTTPGatewayTimeOut,
168
- :gone? => Net::HTTPGone,
169
- :internal_server_error? => Net::HTTPInternalServerError,
170
- :length_required? => Net::HTTPLengthRequired,
171
- :method_not_allowed? => Net::HTTPMethodNotAllowed,
172
- :moved_permanently? => Net::HTTPMovedPermanently,
173
- :multiple_choice? => Net::HTTPMultipleChoice,
174
- :no_content? => Net::HTTPNoContent,
175
- :non_authoritative_information? => Net::HTTPNonAuthoritativeInformation,
176
- :not_acceptable? => Net::HTTPNotAcceptable,
177
- :not_found? => Net::HTTPNotFound,
178
- :not_implemented? => Net::HTTPNotImplemented,
179
- :not_modified? => Net::HTTPNotModified,
180
- :ok? => Net::HTTPOK,
181
- :partial_content? => Net::HTTPPartialContent,
182
- :payment_required? => Net::HTTPPaymentRequired,
183
- :precondition_failed? => Net::HTTPPreconditionFailed,
184
- :proxy_authentication_required? => Net::HTTPProxyAuthenticationRequired,
185
- :request_entity_too_large? => Net::HTTPRequestEntityTooLarge,
186
- :request_time_out? => Net::HTTPRequestTimeOut,
187
- :request_uri_too_long? => Net::HTTPRequestURITooLong,
188
- :requested_range_not_satisfiable? => Net::HTTPRequestedRangeNotSatisfiable,
189
- :reset_content? => Net::HTTPResetContent,
190
- :see_other? => Net::HTTPSeeOther,
191
- :service_unavailable? => Net::HTTPServiceUnavailable,
192
- :switch_protocol? => Net::HTTPSwitchProtocol,
193
- :temporary_redirect? => Net::HTTPTemporaryRedirect,
194
- :unauthorized? => Net::HTTPUnauthorized,
195
- :unsupported_media_type? => Net::HTTPUnsupportedMediaType,
196
- :use_proxy? => Net::HTTPUseProxy,
197
- :version_not_supported? => Net::HTTPVersionNotSupported
158
+ accepted?: Net::HTTPAccepted,
159
+ bad_gateway?: Net::HTTPBadGateway,
160
+ bad_request?: Net::HTTPBadRequest,
161
+ conflict?: Net::HTTPConflict,
162
+ continue?: Net::HTTPContinue,
163
+ created?: Net::HTTPCreated,
164
+ expectation_failed?: Net::HTTPExpectationFailed,
165
+ forbidden?: Net::HTTPForbidden,
166
+ found?: Net::HTTPFound,
167
+ gateway_time_out?: Net::HTTPGatewayTimeOut,
168
+ gone?: Net::HTTPGone,
169
+ internal_server_error?: Net::HTTPInternalServerError,
170
+ length_required?: Net::HTTPLengthRequired,
171
+ method_not_allowed?: Net::HTTPMethodNotAllowed,
172
+ moved_permanently?: Net::HTTPMovedPermanently,
173
+ multiple_choice?: Net::HTTPMultipleChoice,
174
+ no_content?: Net::HTTPNoContent,
175
+ non_authoritative_information?: Net::HTTPNonAuthoritativeInformation,
176
+ not_acceptable?: Net::HTTPNotAcceptable,
177
+ not_found?: Net::HTTPNotFound,
178
+ not_implemented?: Net::HTTPNotImplemented,
179
+ not_modified?: Net::HTTPNotModified,
180
+ ok?: Net::HTTPOK,
181
+ partial_content?: Net::HTTPPartialContent,
182
+ payment_required?: Net::HTTPPaymentRequired,
183
+ precondition_failed?: Net::HTTPPreconditionFailed,
184
+ proxy_authentication_required?: Net::HTTPProxyAuthenticationRequired,
185
+ request_entity_too_large?: Net::HTTPRequestEntityTooLarge,
186
+ request_time_out?: Net::HTTPRequestTimeOut,
187
+ request_uri_too_long?: Net::HTTPRequestURITooLong,
188
+ requested_range_not_satisfiable?: Net::HTTPRequestedRangeNotSatisfiable,
189
+ reset_content?: Net::HTTPResetContent,
190
+ see_other?: Net::HTTPSeeOther,
191
+ service_unavailable?: Net::HTTPServiceUnavailable,
192
+ switch_protocol?: Net::HTTPSwitchProtocol,
193
+ temporary_redirect?: Net::HTTPTemporaryRedirect,
194
+ unauthorized?: Net::HTTPUnauthorized,
195
+ unsupported_media_type?: Net::HTTPUnsupportedMediaType,
196
+ use_proxy?: Net::HTTPUseProxy,
197
+ version_not_supported?: Net::HTTPVersionNotSupported
198
198
  }
199
199
 
200
200
  # Ruby 2.0, new name for this response.