rest-client 1.4.2 → 1.5.0.a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rest-client might be problematic. Click here for more details.

@@ -17,6 +17,28 @@ of specifying actions: get, put, post, delete.
17
17
 
18
18
  RestClient.delete 'http://example.com/resource'
19
19
 
20
+ response = RestClient.get 'http://example.com/resource'
21
+ response.code
22
+ ➔ 200
23
+ response.cookies
24
+ ➔ {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
25
+ response.headers
26
+ ➔ {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ...
27
+ response.to_str
28
+ ➔ \n<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n \"http://www.w3.org/TR/html4/strict.dtd\">\n\n<html ....
29
+
30
+ RestClient.post( url,
31
+ {
32
+ :transfer => {
33
+ :path => '/foo/bar',
34
+ :owner => 'that_guy',
35
+ :group => 'those_guys'
36
+ },
37
+ :upload => {
38
+ :file => File.new(path)
39
+ }
40
+ })
41
+
20
42
  == Multipart
21
43
 
22
44
  Yeah, that's right! This does multipart sends for you!
@@ -226,6 +248,12 @@ Example:
226
248
 
227
249
  RestClient.get 'http://example.com'
228
250
 
251
+ == More
252
+
253
+ Need caching, more advanced logging or any ability provided by a rack middleware ?
254
+
255
+ Have a look at rest-client-components http://github.com/crohr/rest-client-components
256
+
229
257
  == Meta
230
258
 
231
259
  Written by Adam Wiggins, major modifications by Blake Mizerany, maintained by Julien Kirch
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.2
1
+ 1.5.0.a
data/history.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 1.5.0
2
+
3
+ - the response is now a string with the Response module
4
+ - added AbstractResponse.to_i to improve semantic
5
+ - multipart Payloads ignores the name attribute if it's not set (patch provided by Tekin Suleyman)
6
+ - correctly takes into account user headers whose keys are strings (path provided by Cyril Rohr)
7
+ - use binary mode for payload temp file
8
+ - concatenate cookies with ';'
9
+ - fixed deeper parameter handling
10
+ - do not quote the boundary in the Content-Type header (patch provided by W. Andrew Loe III)
11
+
1
12
  # 1.4.2
2
13
 
3
14
  - fixed RestClient.add_before_execution_proc (patch provided by Nicholas Wieland)
@@ -1,14 +1,9 @@
1
1
  module RestClient
2
2
 
3
- class AbstractResponse
3
+ module AbstractResponse
4
4
 
5
5
  attr_reader :net_http_res, :args
6
6
 
7
- def initialize net_http_res, args
8
- @net_http_res = net_http_res
9
- @args = args
10
- end
11
-
12
7
  # HTTP status code
13
8
  def code
14
9
  @code ||= @net_http_res.code.to_i
@@ -17,7 +12,7 @@ module RestClient
17
12
  # A hash of the headers, beautified with symbols and underscores.
18
13
  # e.g. "Content-type" will become :content_type.
19
14
  def headers
20
- @headers ||= self.class.beautify_headers(@net_http_res.to_hash)
15
+ @headers ||= AbstractResponse.beautify_headers(@net_http_res.to_hash)
21
16
  end
22
17
 
23
18
  # The raw headers.
@@ -63,7 +58,11 @@ module RestClient
63
58
  end
64
59
  end
65
60
 
66
- def inspect
61
+ def to_i
62
+ code
63
+ end
64
+
65
+ def description
67
66
  "#{code} #{STATUSES[code]} | #{(headers[:content_type] || '').gsub(/;.*$/, '')} #{size} bytes\n"
68
67
  end
69
68
 
@@ -52,7 +52,7 @@ module RestClient
52
52
  end
53
53
 
54
54
  # Flatten parameters by converting hashes of hashes to flat hashes
55
- # {keys1 => {keys2 => value}} will be transformed into {keys1[key2] => value}
55
+ # {keys1 => {keys2 => value}} will be transformed into [keys1[key2], value]
56
56
  def flatten_params(params, parent_key = nil)
57
57
  result = []
58
58
  params.each do |key, value|
@@ -60,9 +60,7 @@ module RestClient
60
60
  if value.is_a? Hash
61
61
  result += flatten_params(value, calculated_key)
62
62
  elsif value.is_a? Array
63
- value.each do |elem|
64
- result << ["#{calculated_key}[]", elem]
65
- end
63
+ result += flatten_params_array(value, calculated_key)
66
64
  else
67
65
  result << [calculated_key, value]
68
66
  end
@@ -70,6 +68,20 @@ module RestClient
70
68
  result
71
69
  end
72
70
 
71
+ def flatten_params_array value, calculated_key
72
+ result = []
73
+ value.each do |elem|
74
+ if elem.is_a? Hash
75
+ result += flatten_params(elem, calculated_key)
76
+ elsif elem.is_a? Array
77
+ result += flatten_params_array(elem, calculated_key)
78
+ else
79
+ result << ["#{calculated_key}[]", elem]
80
+ end
81
+ end
82
+ result
83
+ end
84
+
73
85
  def headers
74
86
  { 'Content-Length' => size.to_s }
75
87
  end
@@ -91,7 +103,7 @@ module RestClient
91
103
  end
92
104
 
93
105
  def short_inspect
94
- (size > 100 ? "#{size} byte(s) length" : inspect)
106
+ (size > 500 ? "#{size} byte(s) length" : inspect)
95
107
  end
96
108
 
97
109
  end
@@ -116,6 +128,7 @@ module RestClient
116
128
  b = "--#{boundary}"
117
129
 
118
130
  @stream = Tempfile.new("RESTClient.Stream.#{rand(1000)}")
131
+ @stream.binmode
119
132
  @stream.write(b + EOL)
120
133
 
121
134
  if params.is_a? Hash
@@ -149,7 +162,9 @@ module RestClient
149
162
 
150
163
  def create_file_field(s, k, v)
151
164
  begin
152
- s.write("Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{v.respond_to?(:original_filename) ? v.original_filename : File.basename(v.path)}\"#{EOL}")
165
+ s.write("Content-Disposition: form-data;")
166
+ s.write(" name=\"#{k}\";") unless (k.nil? || k=='')
167
+ s.write(" filename=\"#{v.respond_to?(:original_filename) ? v.original_filename : File.basename(v.path)}\"#{EOL}")
153
168
  s.write("Content-Type: #{v.respond_to?(:content_type) ? v.content_type : mime_for(v.path)}#{EOL}")
154
169
  s.write(EOL)
155
170
  while data = v.read(8124)
@@ -170,7 +185,7 @@ module RestClient
170
185
  end
171
186
 
172
187
  def headers
173
- super.merge({'Content-Type' => %Q{multipart/form-data; boundary="#{boundary}"}})
188
+ super.merge({'Content-Type' => %Q{multipart/form-data; boundary=#{boundary}}})
174
189
  end
175
190
 
176
191
  def close
@@ -9,12 +9,15 @@ module RestClient
9
9
  # In addition, if you do not use the response as a string, you can access
10
10
  # a Tempfile object at res.file, which contains the path to the raw
11
11
  # downloaded request body.
12
- class RawResponse < AbstractResponse
12
+ class RawResponse
13
+
14
+ include AbstractResponse
13
15
 
14
16
  attr_reader :file
15
17
 
16
18
  def initialize tempfile, net_http_res, args
17
- super net_http_res, args
19
+ @net_http_res = net_http_res
20
+ @args = args
18
21
  @file = tempfile
19
22
  end
20
23
 
@@ -57,28 +57,9 @@ module RestClient
57
57
 
58
58
  def make_headers user_headers
59
59
  unless @cookies.empty?
60
- user_headers[:cookie] = @cookies.map {|(key, val)| "#{key.to_s}=#{val}" }.sort.join(",")
60
+ user_headers[:cookie] = @cookies.map {|(key, val)| "#{key.to_s}=#{val}" }.sort.join(';')
61
61
  end
62
-
63
- headers = default_headers.merge(user_headers).inject({}) do |final, (key, value)|
64
- target_key = key.to_s.gsub(/_/, '-').capitalize
65
- if 'CONTENT-TYPE' == target_key.upcase
66
- target_value = value.to_s
67
- final[target_key] = MIME::Types.type_for_extension target_value
68
- elsif 'ACCEPT' == target_key.upcase
69
- # Accept can be composed of several comma-separated values
70
- if value.is_a? Array
71
- target_values = value
72
- else
73
- target_values = value.to_s.split ','
74
- end
75
- final[target_key] = target_values.map{ |ext| MIME::Types.type_for_extension(ext.to_s.strip)}.join(', ')
76
- else
77
- final[target_key] = value.to_s
78
- end
79
- final
80
- end
81
-
62
+ headers = stringify_headers(default_headers).merge(stringify_headers(user_headers))
82
63
  headers.merge!(@payload.headers) if @payload
83
64
  headers
84
65
  end
@@ -195,7 +176,7 @@ module RestClient
195
176
  # We don't decode raw requests
196
177
  response = RawResponse.new(@tf, res, args)
197
178
  else
198
- response = Response.new(Request.decode(res['content-encoding'], res.body), res, args)
179
+ response = Response.create(Request.decode(res['content-encoding'], res.body), res, args)
199
180
  end
200
181
 
201
182
  if block_given?
@@ -223,7 +204,7 @@ module RestClient
223
204
  out = []
224
205
  out << "RestClient.#{method} #{url.inspect}"
225
206
  out << payload.short_inspect if payload
226
- out << processed_headers.inspect.gsub(/^\{/, '').gsub(/\}$/, '')
207
+ out << processed_headers.to_a.sort.map{|(k,v)| [k.inspect, v.inspect].join("=>")}.join(", ")
227
208
  RestClient.log << out.join(', ') + "\n"
228
209
  end
229
210
  end
@@ -235,9 +216,32 @@ module RestClient
235
216
  end
236
217
  end
237
218
 
219
+ # Return a hash of headers whose keys are capitalized strings
220
+ def stringify_headers headers
221
+ headers.inject({}) do |result, (key, value)|
222
+ target_key = key.to_s.split(/_/).map{|w| w.capitalize}.join('-')
223
+ if 'CONTENT-TYPE' == target_key.upcase
224
+ target_value = value.to_s
225
+ result[target_key] = MIME::Types.type_for_extension target_value
226
+ elsif 'ACCEPT' == target_key.upcase
227
+ # Accept can be composed of several comma-separated values
228
+ if value.is_a? Array
229
+ target_values = value
230
+ else
231
+ target_values = value.to_s.split ','
232
+ end
233
+ result[target_key] = target_values.map{ |ext| MIME::Types.type_for_extension(ext.to_s.strip)}.join(', ')
234
+ else
235
+ result[target_key] = value.to_s
236
+ end
237
+ result
238
+ end
239
+ end
240
+
238
241
  def default_headers
239
242
  { :accept => '*/*; q=0.5, application/xml', :accept_encoding => 'gzip, deflate' }
240
243
  end
244
+
241
245
  end
242
246
  end
243
247
 
@@ -2,44 +2,22 @@ module RestClient
2
2
 
3
3
  # A Response from RestClient, you can access the response body, the code or the headers.
4
4
  #
5
- class Response < AbstractResponse
5
+ module Response
6
6
 
7
- attr_reader :body
7
+ include AbstractResponse
8
8
 
9
- WARNING_MESSAGE = '[warning] The Response is no more a String and the Response content is now accessed through Response.body, please update your code'
9
+ attr_accessor :body, :net_http_res, :args
10
10
 
11
- def initialize body, net_http_res, args
12
- super net_http_res, args
13
- @body = body || ""
11
+ def body
12
+ self
14
13
  end
15
14
 
16
- def method_missing symbol, *args
17
- if body.respond_to? symbol
18
- warn WARNING_MESSAGE
19
- body.send symbol, *args
20
- else
21
- super
22
- end
23
- end
24
-
25
- def == o
26
- if super
27
- true
28
- else
29
- equal_body = (body == o)
30
- if equal_body
31
- warn WARNING_MESSAGE
32
- end
33
- equal_body
34
- end
35
- end
36
-
37
- def to_s
38
- body.to_s
39
- end
40
-
41
- def size
42
- body.size
15
+ def Response.create body, net_http_res, args
16
+ result = body || ''
17
+ result.extend Response
18
+ result.net_http_res = net_http_res
19
+ result.args = args
20
+ result
43
21
  end
44
22
 
45
23
  end
@@ -1,9 +1,24 @@
1
1
  require File.dirname(__FILE__) + '/base'
2
2
 
3
3
  describe RestClient::AbstractResponse do
4
+
5
+ class MyAbstractResponse
6
+
7
+ include RestClient::AbstractResponse
8
+
9
+ attr_accessor :size
10
+
11
+ def initialize net_http_res, args
12
+ @net_http_res = net_http_res
13
+ @args = args
14
+ end
15
+
16
+
17
+ end
18
+
4
19
  before do
5
20
  @net_http_res = mock('net http response')
6
- @response = RestClient::AbstractResponse.new(@net_http_res, {})
21
+ @response = MyAbstractResponse.new(@net_http_res, {})
7
22
  end
8
23
 
9
24
  it "fetches the numeric response code" do
@@ -11,13 +26,19 @@ describe RestClient::AbstractResponse do
11
26
  @response.code.should == 200
12
27
  end
13
28
 
29
+ it "has a nice description" do
30
+ @net_http_res.should_receive(:to_hash).and_return({'Content-Type' => 'application/pdf'})
31
+ @net_http_res.should_receive(:code).and_return('200')
32
+ @response.description == '200 OK | application/pdf bytes\n'
33
+ end
34
+
14
35
  it "beautifies the headers by turning the keys to symbols" do
15
- h = RestClient::Response.beautify_headers('content-type' => [ 'x' ])
36
+ h = RestClient::AbstractResponse.beautify_headers('content-type' => [ 'x' ])
16
37
  h.keys.first.should == :content_type
17
38
  end
18
39
 
19
40
  it "beautifies the headers by turning the values to strings instead of one-element arrays" do
20
- h = RestClient::Response.beautify_headers('x' => [ 'text/html' ] )
41
+ h = RestClient::AbstractResponse.beautify_headers('x' => [ 'text/html' ] )
21
42
  h.values.first.should == 'text/html'
22
43
  end
23
44
 
@@ -11,7 +11,7 @@ describe RestClient::Payload do
11
11
  RestClient::Payload::UrlEncoded.new({:foo => 'bar'}).to_s.
12
12
  should == "foo=bar"
13
13
  ["foo=bar&baz=qux", "baz=qux&foo=bar"].should include(
14
- RestClient::Payload::UrlEncoded.new({:foo => 'bar', :baz => 'qux'}).to_s)
14
+ RestClient::Payload::UrlEncoded.new({:foo => 'bar', :baz => 'qux'}).to_s)
15
15
  end
16
16
 
17
17
  it "should properly handle hashes as parameter" do
@@ -26,6 +26,16 @@ describe RestClient::Payload do
26
26
  parameters.should include("foo[bar]=baz", "foo[baz]=qux")
27
27
  end
28
28
 
29
+ it "should handle attributes inside a an array inside an hash" do
30
+ parameters = RestClient::Payload::UrlEncoded.new({"foo" => [{"bar" => 'baz'}, {"bar" => 'qux'}]}).to_s
31
+ parameters.should include("foo[bar]=baz", "foo[bar]=qux")
32
+ end
33
+
34
+ it "should handle attributes inside a an array inside an array inside an hash" do
35
+ parameters = RestClient::Payload::UrlEncoded.new({"foo" => [ [{"bar" => 'baz'}, {"bar" => 'qux'}]]}).to_s
36
+ parameters.should include("foo[bar]=baz", "foo[bar]=qux")
37
+ end
38
+
29
39
  it "should form properly use symbols as parameters" do
30
40
  RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s.
31
41
  should == "foo=bar"
@@ -46,7 +56,7 @@ describe RestClient::Payload do
46
56
  it "should use standard enctype as default content-type" do
47
57
  m = RestClient::Payload::Multipart.new({})
48
58
  m.stub!(:boundary).and_return(123)
49
- m.headers['Content-Type'].should == 'multipart/form-data; boundary="123"'
59
+ m.headers['Content-Type'].should == 'multipart/form-data; boundary=123'
50
60
  end
51
61
 
52
62
  it "should form properly separated multipart data" do
@@ -77,6 +87,19 @@ Content-Type: image/jpeg\r
77
87
  EOS
78
88
  end
79
89
 
90
+ it "should ignore the name attribute when it's not set" do
91
+ f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
92
+ m = RestClient::Payload::Multipart.new({nil => f})
93
+ m.to_s.should == <<-EOS
94
+ --#{m.boundary}\r
95
+ Content-Disposition: form-data; filename="master_shake.jpg"\r
96
+ Content-Type: image/jpeg\r
97
+ \r
98
+ #{IO.read(f.path)}\r
99
+ --#{m.boundary}--\r
100
+ EOS
101
+ end
102
+
80
103
  it "should detect optional (original) content type and filename" do
81
104
  f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
82
105
  f.instance_eval "def content_type; 'text/plain'; end"
@@ -99,7 +99,7 @@ describe RestClient::Request do
99
99
  URI.stub!(:parse).and_return(mock('uri', :user => nil, :password => nil))
100
100
  @request = RestClient::Request.new(:method => 'get', :url => 'example.com', :cookies => {:session_id => '1', :user_id => "someone" })
101
101
  @request.should_receive(:default_headers).and_return({'foo' => 'bar'})
102
- headers = @request.make_headers({}).should == { 'Foo' => 'bar', 'Cookie' => 'session_id=1,user_id=someone'}
102
+ headers = @request.make_headers({}).should == { 'Foo' => 'bar', 'Cookie' => 'session_id=1;user_id=someone'}
103
103
  end
104
104
 
105
105
  it "determines the Net::HTTP class to instantiate by the method name" do
@@ -108,12 +108,12 @@ describe RestClient::Request do
108
108
 
109
109
  describe "user headers" do
110
110
  it "merges user headers with the default headers" do
111
- @request.should_receive(:default_headers).and_return({ '1' => '2' })
112
- headers = @request.make_headers('3' => '4')
113
- headers.should have_key('1')
114
- headers['1'].should == '2'
115
- headers.should have_key('3')
116
- headers['3'].should == '4'
111
+ @request.should_receive(:default_headers).and_return({ :accept => '*/*; q=0.5, application/xml', :accept_encoding => 'gzip, deflate' })
112
+ headers = @request.make_headers("Accept" => "application/json", :accept_encoding => 'gzip')
113
+ headers.should have_key "Accept-Encoding"
114
+ headers["Accept-Encoding"].should == "gzip"
115
+ headers.should have_key "Accept"
116
+ headers["Accept"].should == "application/json"
117
117
  end
118
118
 
119
119
  it "prefers the user header when the same header exists in the defaults" do
@@ -126,18 +126,18 @@ describe RestClient::Request do
126
126
 
127
127
  describe "header symbols" do
128
128
 
129
- it "converts header symbols from :content_type to 'Content-type'" do
129
+ it "converts header symbols from :content_type to 'Content-Type'" do
130
130
  @request.should_receive(:default_headers).and_return({})
131
131
  headers = @request.make_headers(:content_type => 'abc')
132
- headers.should have_key('Content-type')
133
- headers['Content-type'].should == 'abc'
132
+ headers.should have_key('Content-Type')
133
+ headers['Content-Type'].should == 'abc'
134
134
  end
135
135
 
136
136
  it "converts content-type from extension to real content-type" do
137
137
  @request.should_receive(:default_headers).and_return({})
138
138
  headers = @request.make_headers(:content_type => 'json')
139
- headers.should have_key('Content-type')
140
- headers['Content-type'].should == 'application/json'
139
+ headers.should have_key('Content-Type')
140
+ headers['Content-Type'].should == 'application/json'
141
141
  end
142
142
 
143
143
  it "converts accept from extension(s) to real content-type(s)" do
@@ -282,29 +282,25 @@ describe RestClient::Request do
282
282
  it "logs a get request" do
283
283
  log = RestClient.log = []
284
284
  RestClient::Request.new(:method => :get, :url => 'http://url').log_request
285
- ['RestClient.get "http://url", "Accept-encoding"=>"gzip, deflate", "Accept"=>"*/*; q=0.5, application/xml"' + "\n",
286
- 'RestClient.get "http://url", "Accept"=>"*/*; q=0.5, application/xml", "Accept-encoding"=>"gzip, deflate"' + "\n"].should include(log[0])
285
+ log[0].should == %Q{RestClient.get "http://url", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate"\n}
287
286
  end
288
287
 
289
288
  it "logs a post request with a small payload" do
290
289
  log = RestClient.log = []
291
290
  RestClient::Request.new(:method => :post, :url => 'http://url', :payload => 'foo').log_request
292
- ['RestClient.post "http://url", "foo", "Accept-encoding"=>"gzip, deflate", "Content-Length"=>"3", "Accept"=>"*/*; q=0.5, application/xml"' + "\n",
293
- 'RestClient.post "http://url", "foo", "Accept"=>"*/*; q=0.5, application/xml", "Accept-encoding"=>"gzip, deflate", "Content-Length"=>"3"' + "\n"].should include(log[0])
291
+ log[0].should == %Q{RestClient.post "http://url", "foo", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"3"\n}
294
292
  end
295
293
 
296
294
  it "logs a post request with a large payload" do
297
295
  log = RestClient.log = []
298
296
  RestClient::Request.new(:method => :post, :url => 'http://url', :payload => ('x' * 1000)).log_request
299
- ['RestClient.post "http://url", 1000 byte(s) length, "Accept-encoding"=>"gzip, deflate", "Content-Length"=>"1000", "Accept"=>"*/*; q=0.5, application/xml"' + "\n",
300
- 'RestClient.post "http://url", 1000 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-encoding"=>"gzip, deflate", "Content-Length"=>"1000"' + "\n"].should include(log[0])
297
+ log[0].should == %Q{RestClient.post "http://url", 1000 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"1000"\n}
301
298
  end
302
299
 
303
300
  it "logs input headers as a hash" do
304
301
  log = RestClient.log = []
305
302
  RestClient::Request.new(:method => :get, :url => 'http://url', :headers => { :accept => 'text/plain' }).log_request
306
- ['RestClient.get "http://url", "Accept-encoding"=>"gzip, deflate", "Accept"=>"text/plain"' + "\n",
307
- 'RestClient.get "http://url", "Accept"=>"text/plain", "Accept-encoding"=>"gzip, deflate"' + "\n"].should include(log[0])
303
+ log[0].should == %Q{RestClient.get "http://url", "Accept"=>"text/plain", "Accept-Encoding"=>"gzip, deflate"\n}
308
304
  end
309
305
 
310
306
  it "logs a response including the status code, content type, and result body size in bytes" do
@@ -5,16 +5,18 @@ include WebMock
5
5
 
6
6
  describe RestClient::Response do
7
7
  before do
8
- @net_http_res = mock('net http response', :to_hash => {"Status" => ["200 OK"]})
9
- @response = RestClient::Response.new('abc', @net_http_res, {})
8
+ @net_http_res = mock('net http response', :to_hash => {"Status" => ["200 OK"]}, :code => 200)
9
+ @response = RestClient::Response.create('abc', @net_http_res, {})
10
10
  end
11
11
 
12
12
  it "behaves like string" do
13
13
  @response.should.to_s == 'abc'
14
+ @response.to_str.should == 'abc'
15
+ @response.to_i.should == 200
14
16
  end
15
17
 
16
18
  it "accepts nil strings and sets it to empty for the case of HEAD" do
17
- RestClient::Response.new(nil, @net_http_res, {}).should.to_s == ""
19
+ RestClient::Response.create(nil, @net_http_res, {}).should.to_s == ""
18
20
  end
19
21
 
20
22
  it "test headers and raw headers" do
@@ -25,14 +27,14 @@ describe RestClient::Response do
25
27
  describe "cookie processing" do
26
28
  it "should correctly deal with one Set-Cookie header with one cookie inside" do
27
29
  net_http_res = mock('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT"]})
28
- response = RestClient::Response.new('abc', net_http_res, {})
30
+ response = RestClient::Response.create('abc', net_http_res, {})
29
31
  response.headers[:set_cookie].should == ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT"]
30
32
  response.cookies.should == { "main_page" => "main_page_no_rewrite" }
31
33
  end
32
34
 
33
35
  it "should correctly deal with multiple cookies [multiple Set-Cookie headers]" do
34
36
  net_http_res = mock('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT", "remember_me=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", "user=somebody; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]})
35
- response = RestClient::Response.new('abc', net_http_res, {})
37
+ response = RestClient::Response.create('abc', net_http_res, {})
36
38
  response.headers[:set_cookie].should == ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT", "remember_me=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", "user=somebody; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]
37
39
  response.cookies.should == {
38
40
  "main_page" => "main_page_no_rewrite",
@@ -43,7 +45,7 @@ describe RestClient::Response do
43
45
 
44
46
  it "should correctly deal with multiple cookies [one Set-Cookie header with multiple cookies]" do
45
47
  net_http_res = mock('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT, remember_me=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT, user=somebody; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]})
46
- response = RestClient::Response.new('abc', net_http_res, {})
48
+ response = RestClient::Response.create('abc', net_http_res, {})
47
49
  response.cookies.should == {
48
50
  "main_page" => "main_page_no_rewrite",
49
51
  "remember_me" => "",
@@ -56,7 +58,7 @@ describe RestClient::Response do
56
58
  it "should return itself for normal codes" do
57
59
  (200..206).each do |code|
58
60
  net_http_res = mock('net http response', :code => '200')
59
- response = RestClient::Response.new('abc', net_http_res, {})
61
+ response = RestClient::Response.create('abc', net_http_res, {})
60
62
  response.return!
61
63
  end
62
64
  end
@@ -65,7 +67,7 @@ describe RestClient::Response do
65
67
  RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code|
66
68
  unless (200..206).include? code
67
69
  net_http_res = mock('net http response', :code => code.to_i)
68
- response = RestClient::Response.new('abc', net_http_res, {})
70
+ response = RestClient::Response.create('abc', net_http_res, {})
69
71
  lambda { response.return!}.should raise_error
70
72
  end
71
73
  end
@@ -83,13 +85,13 @@ describe RestClient::Response do
83
85
 
84
86
  it "doesn't follow a redirection when the request is a post" do
85
87
  net_http_res = mock('net http response', :code => 301)
86
- response = RestClient::Response.new('abc', net_http_res, {:method => :post})
88
+ response = RestClient::Response.create('abc', net_http_res, {:method => :post})
87
89
  lambda { response.return!}.should raise_error(RestClient::MovedPermanently)
88
90
  end
89
91
 
90
92
  it "doesn't follow a redirection when the request is a put" do
91
93
  net_http_res = mock('net http response', :code => 301)
92
- response = RestClient::Response.new('abc', net_http_res, {:method => :put})
94
+ response = RestClient::Response.create('abc', net_http_res, {:method => :put})
93
95
  lambda { response.return!}.should raise_error(RestClient::MovedPermanently)
94
96
  end
95
97
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-client
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 1
7
- - 4
8
- - 2
9
- version: 1.4.2
7
+ - 5
8
+ - 0
9
+ - a
10
+ version: 1.5.0.a
10
11
  platform: ruby
11
12
  authors:
12
13
  - Adam Wiggins