1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Merge branch '1.3.0'

Conflicts:
	history.md
	lib/restclient/exceptions.rb
This commit is contained in:
Julien Kirch 2010-02-10 19:06:59 +01:00
commit 196c9720ff
5 changed files with 41 additions and 7 deletions

View file

@ -1 +1 @@
1.3.0 1.3.1

View file

@ -6,6 +6,10 @@
The response change may be breaking in rare cases. The response change may be breaking in rare cases.
# 1.3.1
- added compatibility to enable responses in exception to act like Net::HTTPResponse
# 1.3.0 # 1.3.0
- a block can be used to process a request's result, this enable to handle custom error codes or paththrought (design by Cyril Rohr) - a block can be used to process a request's result, this enable to handle custom error codes or paththrought (design by Cyril Rohr)

View file

@ -1,6 +1,5 @@
module RestClient module RestClient
STATUSES = {100 => 'Continue', STATUSES = {100 => 'Continue',
101 => 'Switching Protocols', 101 => 'Switching Protocols',
200 => 'OK', 200 => 'OK',
@ -40,6 +39,18 @@ module RestClient
504 => 'Gateway Timeout', 504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'} 505 => 'HTTP Version Not Supported'}
# Compatibility : make the Response act like a Net::HTTPResponse when needed
module ResponseForException
def method_missing symbol, *args
if net_http_res.respond_to? symbol
warn "[warning] The response contained in an RestClient::Exception is now a RestClient::Response instead of a Net::HTTPResponse, please update your code"
net_http_res.send symbol, *args
else
super
end
end
end
# This is the base RestClient exception class. Rescue it if you want to # This is the base RestClient exception class. Rescue it if you want to
# catch any exception that your request might raise # catch any exception that your request might raise
# You can get the status code by e.http_code, or see anything about the # You can get the status code by e.http_code, or see anything about the
@ -51,6 +62,9 @@ module RestClient
def initialize response = nil def initialize response = nil
@response = response @response = response
# compatibility: this make the exception behave like a Net::HTTPResponse
response.extend ResponseForException
end end
def http_code def http_code

View file

@ -2,7 +2,7 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{rest-client} s.name = %q{rest-client}
s.version = "1.3.0" s.version = "1.3.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Adam Wiggins", "Julien Kirch"] s.authors = ["Adam Wiggins", "Julien Kirch"]
s.date = %q{2010-01-25} s.date = %q{2010-01-25}

View file

@ -1,5 +1,8 @@
require File.dirname(__FILE__) + '/base' require File.dirname(__FILE__) + '/base'
require 'webmock/rspec'
include WebMock
describe RestClient::Exception do describe RestClient::Exception do
it "sets the exception message to ErrorMessage" do it "sets the exception message to ErrorMessage" do
RestClient::ResourceNotFound.new.message.should == 'Resource Not Found' RestClient::ResourceNotFound.new.message.should == 'Resource Not Found'
@ -17,10 +20,11 @@ describe RestClient::RequestFailed do
end end
it "stores the http response on the exception" do it "stores the http response on the exception" do
response = "response"
begin begin
raise RestClient::RequestFailed, :response raise RestClient::RequestFailed, response
rescue RestClient::RequestFailed => e rescue RestClient::RequestFailed => e
e.response.should == :response e.response.should == response
end end
end end
@ -40,10 +44,11 @@ end
describe RestClient::ResourceNotFound do describe RestClient::ResourceNotFound do
it "also has the http response attached" do it "also has the http response attached" do
response = "response"
begin begin
raise RestClient::ResourceNotFound, :response raise RestClient::ResourceNotFound, response
rescue RestClient::ResourceNotFound => e rescue RestClient::ResourceNotFound => e
e.response.should == :response e.response.should == response
end end
end end
end end
@ -60,4 +65,15 @@ describe "backwards compatibility" do
it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
RestClient::Request::RequestFailed.should == RestClient::RequestFailed RestClient::Request::RequestFailed.should == RestClient::RequestFailed
end end
it "make the exception's response act like an Net::HTTPResponse" do
body = "body"
stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
begin
RestClient.get "www.example.com"
raise
rescue RestClient::ResourceNotFound => e
e.response.body.should == body
end
end
end end