0
@@ -17,6 +17,7 @@ module HTTParty
0
AllowedFormats = {:xml => 'text/xml', :json => 'application/json'}
0
+ SupportedHTTPMethods = [Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Put, Net::HTTP::Delete]
0
@@ -66,22 +67,22 @@ module HTTParty
0
def get(path, options={})
0
- send_request
'get', path, options
0
+ send_request
Net::HTTP::Get, path, options
0
def post(path, options={})
0
- send_request
'post', path, options
0
+ send_request
Net::HTTP::Post, path, options
0
def put(path, options={})
0
- send_request
'put', path, options
0
+ send_request
Net::HTTP::Put, path, options
0
def delete(path, options={})
0
- send_request
'delete', path, options
0
+ send_request
Net::HTTP::Delete, path, options
0
@@ -99,12 +100,12 @@ module HTTParty
0
# headers => hash of headers to send request with
0
# basic_auth => :username and :password to use as basic http authentication (overrides @auth class instance variable)
0
# Raises exception Net::XXX (http error code) if an http error occured
0
- def send_request(
method, path, options={}) #:nodoc:
0
+ def send_request(
klass, path, options={}) #:nodoc:
0
options = {:limit => 5}.merge(options)
0
options[:limit] = 0 if options.delete(:no_follow)
0
raise HTTParty::RedirectionTooDeep, 'HTTP redirects too deep' if options[:limit].to_i <= 0
0
- raise ArgumentError, 'only get, post, put and delete methods are supported' unless
%w[get post put delete].include?(method.to_s)
0
+ raise ArgumentError, 'only get, post, put and delete methods are supported' unless
SupportedHTTPMethods.include?(klass)
0
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
0
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].is_a?(Hash)
0
@@ -117,7 +118,6 @@ module HTTParty
0
existing_query + (options[:query].is_a?(Hash) ? default_params.merge(options[:query]).to_query : options[:query])
0
- klass = Net::HTTP.const_get method.to_s.downcase.capitalize
0
request = klass.new(uri.request_uri)
0
request.body = options[:body].is_a?(Hash) ? options[:body].to_query : options[:body] unless options[:body].blank?
0
basic_auth = options.delete(:basic_auth) || @auth
0
@@ -131,7 +131,7 @@ module HTTParty
0
parse_response(response.body)
0
when Net::HTTPRedirection
0
- send_request(
method, response['location'], options)
0
+ send_request(
klass, response['location'], options)
0
response.instance_eval { class << self; attr_accessor :body_parsed; end }
0
begin; response.body_parsed = parse_response(response.body); rescue; end
0
@@ -166,4 +166,4 @@ module HTTParty
0
AllowedFormats.each { |k, v| return k if mimetype.include?(v) }
0
\ No newline at end of file