1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
This commit is contained in:
Sandro Turriate 2011-01-18 15:09:19 -05:00
parent def1d461e8
commit e9f8739b63
2 changed files with 12 additions and 20 deletions

View file

@ -66,7 +66,8 @@ module HTTParty
def perform
validate
setup_raw_request
get_response
self.last_response = http.request(@raw_request)
handle_deflation
handle_response
end
@ -158,14 +159,6 @@ module HTTParty
end
end
def perform_actual_request
http.request(@raw_request)
end
def get_response
self.last_response = perform_actual_request
end
def query_string(uri)
query_string_parts = []
query_string_parts << uri.query unless uri.query.nil?
@ -183,7 +176,6 @@ module HTTParty
# Raises exception Net::XXX (http error code) if an http error occured
def handle_response
handle_deflation
case last_response
when Net::HTTPMultipleChoice, # 300
Net::HTTPMovedPermanently, # 301
@ -241,15 +233,15 @@ module HTTParty
end
end
def validate
raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0
raise ArgumentError, 'only get, post, put, delete, head, and options methods are supported' unless SupportedHTTPMethods.include?(http_method)
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
raise ArgumentError, 'only one authentication method, :basic_auth or :digest_auth may be used at a time' if options[:basic_auth] && options[:digest_auth]
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].is_a?(Hash)
raise ArgumentError, ':digest_auth must be a hash' if options[:digest_auth] && !options[:digest_auth].is_a?(Hash)
raise ArgumentError, ':query must be hash if using HTTP Post' if post? && !options[:query].nil? && !options[:query].is_a?(Hash)
end
def validate
raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0
raise ArgumentError, 'only get, post, put, delete, head, and options methods are supported' unless SupportedHTTPMethods.include?(http_method)
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
raise ArgumentError, 'only one authentication method, :basic_auth or :digest_auth may be used at a time' if options[:basic_auth] && options[:digest_auth]
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].is_a?(Hash)
raise ArgumentError, ':digest_auth must be a hash' if options[:digest_auth] && !options[:digest_auth].is_a?(Hash)
raise ArgumentError, ':query must be hash if using HTTP Post' if post? && !options[:query].nil? && !options[:query].is_a?(Hash)
end
def post?
Net::HTTP::Post == http_method

View file

@ -8,7 +8,7 @@ module HTTParty
response.stub!(:body).and_return(data)
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
http_request.stub!(:perform_actual_request).and_return(response)
http_request.stub_chain(:http, :request).and_return(response)
HTTParty::Request.should_receive(:new).and_return(http_request)
end