Skip to content

Commit

Permalink
inserting method arg
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Oct 20, 2010
1 parent 1434f15 commit a22b8fd
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 19 deletions.
1 change: 0 additions & 1 deletion lib/restfulie/client/http/follow_link.rb
Expand Up @@ -26,7 +26,6 @@ def request!(method, path, *args)#:nodoc:
response = delegate(:request!, method, path, *args)
rescue Error::Redirection => e
response = e.response
debugger
if follow_codes.include?(response.code)
location = response.headers['location'] || response.headers['Location']
raise Error::AutoFollowWithoutLocationError.new(self, response) unless location
Expand Down
6 changes: 2 additions & 4 deletions lib/restfulie/client/http/request_adapter.rb
Expand Up @@ -104,14 +104,12 @@ def request!(method, path, *args)
response = Restfulie::Client.cache_provider.get([@host, path], http_request, method)
return response if response
response = http_request.send(method, path, *args)
debugger if path=="/test/701"
response = ResponseHandler.handle(method, path, response)
rescue Exception => e
Restfulie::Common::Logger.logger.error(e)
raise Error::ServerNotAvailableError.new(self, Response.new(method, path, 503, nil, {}), e )
response = e
end

Restfulie::Client::Response::EnhanceResponse.new(response_handler).parse(@host, path, http_request, self, response)
Restfulie::Client::Response::EnhanceResponse.new(response_handler).parse(@host, path, http_request, self, response, method)

end

Expand Down
8 changes: 5 additions & 3 deletions lib/restfulie/client/response/cache_handler.rb
Expand Up @@ -7,9 +7,11 @@ def initialize(requester)
@requester = requester
end

def parse(host, path, http_request, request, response)
Restfulie::Client.cache_provider.put([host, path], http_request, response)
@requester.parse(host, path, http_request, request, response)
def parse(host, path, http_request, request, response, method)
unless response.kind_of? Exception
Restfulie::Client.cache_provider.put([host, path], http_request, response)
end
@requester.parse(host, path, http_request, request, response, method)
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/restfulie/client/response/catch_and_throw.rb
Expand Up @@ -2,7 +2,11 @@ module Restfulie
module Client
module Response
class CatchAndThrow
def parse(host, path, http_request, request, response)
def parse(host, path, http_request, request, response, method)
if response.kind_of? Exception
Restfulie::Common::Logger.logger.error(response)
raise Restfulie::Client::HTTP::Error::ServerNotAvailableError.new(request, Response.new(method, path, 503, nil, {}), response )
end
case response.code
when 100..299
response
Expand Down
4 changes: 2 additions & 2 deletions lib/restfulie/client/response/created_redirect.rb
Expand Up @@ -8,8 +8,8 @@ def initialize(config, requester)
@requester = requester
end

def parse(host, path, http_request, request, response)
result = @requester.parse(host, path, http_request, request, response)
def parse(host, path, http_request, request, response, method)
result = @requester.parse(host, path, http_request, request, response, method)
response = result.respond_to?(:response) ? result.response : result
if response.respond_to?(:code) && response.code == 201
request = Restfulie.at(response.headers['location'])
Expand Down
4 changes: 2 additions & 2 deletions lib/restfulie/client/response/enhance_response.rb
Expand Up @@ -6,8 +6,8 @@ def initialize(requester)
@requester = requester
end

def parse(host, path, http_request, request, response)
resp = @requester.parse(host, path, http_request, request, response)
def parse(host, path, http_request, request, response, method)
resp = @requester.parse(host, path, http_request, request, response, method)
unless resp.kind_of? ::Restfulie::Client::HTTP::ResponseHolder
resp.extend(::Restfulie::Client::HTTP::ResponseHolder)
resp.response = response
Expand Down
4 changes: 2 additions & 2 deletions lib/restfulie/client/response/ignore_error.rb
Expand Up @@ -7,9 +7,9 @@ def initialize(requester)
@requester = requester
end

def parse(host, path, http_request, request, response)
def parse(host, path, http_request, request, response, method)
begin
@requester.parse(host, path, http_request, request, response)
@requester.parse(host, path, http_request, request, response, method)
rescue Restfulie::Client::HTTP::Error::RESTError => se
se
end
Expand Down
4 changes: 2 additions & 2 deletions lib/restfulie/client/response/unmarshall_handler.rb
Expand Up @@ -12,8 +12,8 @@ def initialize(config, requester)
# first checks if its a 201, redirecting to the resource location.
# otherwise check if its a raw request, returning the content itself.
# finally, tries to parse the content with a mediatype handler or returns the response itself.
def parse(host, path, http_request, request, response)
response = @requester.parse(host, path, http_request, request, response)
def parse(host, path, http_request, request, response, method)
response = @requester.parse(host, path, http_request, request, response, method)
if @config.raw?
response
elsif (!response.body.nil?) && !response.body.empty?
Expand Down
6 changes: 4 additions & 2 deletions tests/spec/requests/http/adapter_spec.rb
Expand Up @@ -340,10 +340,12 @@ class FakeResponse < ::Restfulie::Client::HTTP::Response
end

it "receives error when 503 code is returned" do
@client.at(nil).get.should respond_with_status(503)
debugger
Restfulie.at("http://localhost:2222/").get.should respond_with_status(503)
end

it "raise Error::ServerNotAvailableError error when 503 code is returned" do
lambda { @client.at(nil,nil).get! }.should raise_exception ::Restfulie::Client::HTTP::Error::ServerNotAvailableError
lambda { Restfulie.at("http://localhost:2222/").get! }.should raise_exception ::Restfulie::Client::HTTP::Error::ServerNotAvailableError
end

it "receives error when 502..599 code is returned" do
Expand Down

0 comments on commit a22b8fd

Please sign in to comment.