1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Added message to the response object.

This commit is contained in:
John Nunemaker 2009-04-23 11:28:36 -04:00
parent c69fe04ce1
commit 309cd09ebe
6 changed files with 23 additions and 13 deletions

View file

@ -1,4 +1,8 @@
== 0.4.2 209-03-30
== 0.4.5 2009-04-23
* 1 minor update
* added message to the response object
== 0.4.2 2009-03-30
* 2 minor changes
* response code now returns an integer instead of a string (jqr)
* rubyforge project setup for crack so i'm now depending on that instead of jnunemaker-crack

View file

@ -4,8 +4,8 @@ require 'pp'
# You can also use post, put, delete in the same fashion
response = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
puts response.body, response.code, response.headers.inspect
puts response.body, response.code, response.message, response.headers.inspect
response.each do |item|
puts item['user']['screen_name']
end
end

View file

@ -99,7 +99,7 @@ module HTTParty
perform
else
parsed_response = parse_response(response.body)
Response.new(parsed_response, response.body, response.code, response.to_hash)
Response.new(parsed_response, response.body, response.code, response.message, response.to_hash)
end
end

View file

@ -1,12 +1,13 @@
module HTTParty
class Response < BlankSlate #:nodoc:
attr_accessor :body, :code, :headers
attr_accessor :body, :code, :message, :headers
attr_reader :delegate
def initialize(delegate, body, code, headers={})
def initialize(delegate, body, code, message, headers={})
@delegate = delegate
@body = body
@code = code.to_i
@message = message
@headers = headers
end

View file

@ -1,3 +1,3 @@
module HTTParty #:nodoc:
Version = '0.4.2'
Version = '0.4.3'
end

View file

@ -6,7 +6,8 @@ describe HTTParty::Response do
@response_object = {'foo' => 'bar'}
@body = "{foo:'bar'}"
@code = '200'
@response = HTTParty::Response.new(@response_object, @body, @code)
@message = 'OK'
@response = HTTParty::Response.new(@response_object, @body, @code, @message)
end
it "should set delegate" do
@ -24,20 +25,24 @@ describe HTTParty::Response do
it "should set code as a Fixnum" do
@response.code.should be_an_instance_of(Fixnum)
end
it "should set body" do
@response.body.should == @body
end
end
it "should be able to set headers during initialization" do
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200, {'foo' => 'bar'})
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200, 'OK', {'foo' => 'bar'})
response.headers.should == {'foo' => 'bar'}
end
it "should send missing methods to delegate" do
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200)
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200, 'OK')
response['foo'].should == 'bar'
end
it "should be able to iterate delegate if it is array" do
response = HTTParty::Response.new([{'foo' => 'bar'}, {'foo' => 'baz'}], "[{foo:'bar'}, {foo:'baz'}]", 200)
response = HTTParty::Response.new([{'foo' => 'bar'}, {'foo' => 'baz'}], "[{foo:'bar'}, {foo:'baz'}]", 200, 'OK')
response.size.should == 2
lambda {
response.each { |item| }
@ -45,12 +50,12 @@ describe HTTParty::Response do
end
xit "should allow hashes to be accessed with dot notation" do
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200)
response = HTTParty::Response.new({'foo' => 'bar'}, "{foo:'bar'}", 200, 'OK')
response.foo.should == 'bar'
end
xit "should allow nested hashes to be accessed with dot notation" do
response = HTTParty::Response.new({'foo' => {'bar' => 'baz'}}, "{foo: {bar:'baz'}}", 200)
response = HTTParty::Response.new({'foo' => {'bar' => 'baz'}}, "{foo: {bar:'baz'}}", 200, 'OK')
response.foo.should == {'bar' => 'baz'}
response.foo.bar.should == 'baz'
end