mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Cleanup
This commit is contained in:
parent
def1d461e8
commit
e9f8739b63
2 changed files with 12 additions and 20 deletions
|
@ -66,7 +66,8 @@ module HTTParty
|
||||||
def perform
|
def perform
|
||||||
validate
|
validate
|
||||||
setup_raw_request
|
setup_raw_request
|
||||||
get_response
|
self.last_response = http.request(@raw_request)
|
||||||
|
handle_deflation
|
||||||
handle_response
|
handle_response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -158,14 +159,6 @@ module HTTParty
|
||||||
end
|
end
|
||||||
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)
|
def query_string(uri)
|
||||||
query_string_parts = []
|
query_string_parts = []
|
||||||
query_string_parts << uri.query unless uri.query.nil?
|
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
|
# Raises exception Net::XXX (http error code) if an http error occured
|
||||||
def handle_response
|
def handle_response
|
||||||
handle_deflation
|
|
||||||
case last_response
|
case last_response
|
||||||
when Net::HTTPMultipleChoice, # 300
|
when Net::HTTPMultipleChoice, # 300
|
||||||
Net::HTTPMovedPermanently, # 301
|
Net::HTTPMovedPermanently, # 301
|
||||||
|
@ -241,15 +233,15 @@ module HTTParty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0
|
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, '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, ':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, '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, ':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, ':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)
|
raise ArgumentError, ':query must be hash if using HTTP Post' if post? && !options[:query].nil? && !options[:query].is_a?(Hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def post?
|
def post?
|
||||||
Net::HTTP::Post == http_method
|
Net::HTTP::Post == http_method
|
||||||
|
|
|
@ -8,7 +8,7 @@ module HTTParty
|
||||||
response.stub!(:body).and_return(data)
|
response.stub!(:body).and_return(data)
|
||||||
|
|
||||||
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
|
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)
|
HTTParty::Request.should_receive(:new).and_return(http_request)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue