Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup

  • Loading branch information...
commit e9f8739b631eef58acedbd1e7678be1c28c16fbf 1 parent def1d46
@sandro sandro authored
Showing with 12 additions and 20 deletions.
  1. +11 −19 lib/httparty/request.rb
  2. +1 −1  spec/support/stub_response.rb
View
30 lib/httparty/request.rb
@@ -66,7 +66,8 @@ def parser
def perform
validate
setup_raw_request
- get_response
+ self.last_response = http.request(@raw_request)
+ handle_deflation
handle_response
end
@@ -158,14 +159,6 @@ def setup_digest_auth
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 @@ def query_string(uri)
# 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 @@ def format_from_mimetype(mimetype)
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
2  spec/support/stub_response.rb
@@ -8,7 +8,7 @@ def stub_http_response_with(filename)
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
Please sign in to comment.
Something went wrong with that request. Please try again.