1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Switched from send to perform which sounds fancier.

This commit is contained in:
John Nunemaker 2008-11-11 19:07:11 -05:00
parent c67b6d4f01
commit 67cb57256f
2 changed files with 10 additions and 12 deletions

View file

@ -71,28 +71,28 @@ module HTTParty
# TODO: spec out this
def get(path, options={})
send_request Net::HTTP::Get, path, options
perform_request Net::HTTP::Get, path, options
end
# TODO: spec out this
def post(path, options={})
send_request Net::HTTP::Post, path, options
perform_request Net::HTTP::Post, path, options
end
# TODO: spec out this
def put(path, options={})
send_request Net::HTTP::Put, path, options
perform_request Net::HTTP::Put, path, options
end
# TODO: spec out this
def delete(path, options={})
send_request Net::HTTP::Delete, path, options
perform_request Net::HTTP::Delete, path, options
end
private
def send_request(http_method, path, options)
Request.send_request(http_method, path, default_options.merge(options))
def perform_request(http_method, path, options)
Request.perform_request(http_method, path, default_options.merge(options))
end
# Makes it so uri is sure to parse stuff like google.com with the http

View file

@ -2,8 +2,8 @@ module HTTParty
class Request
SupportedHTTPMethods = [Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Put, Net::HTTP::Delete]
def self.send_request(http_method, path, options={})
new(http_method, path, options).send_request
def self.perform_request(http_method, path, options={})
new(http_method, path, options).perform
end
attr_accessor :http_method, :path, :options
@ -28,7 +28,7 @@ module HTTParty
# headers => hash of headers to send request with
# basic_auth => :username and :password to use as basic http authentication (overrides basic_auth setting)
# Raises exception Net::XXX (http error code) if an http error occured
def send_request #:nodoc:
def perform #:nodoc:
raise HTTParty::RedirectionTooDeep, 'HTTP redirects too deep' if options[:limit].to_i <= 0
raise ArgumentError, 'only get, post, put and delete methods are supported' unless SupportedHTTPMethods.include?(http_method)
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].is_a?(Hash)
@ -36,7 +36,6 @@ module HTTParty
uri = path.relative? ? URI.parse("#{options[:base_uri]}#{path}") : path
query_string_parts = []
query_string_parts << uri.query unless uri.query.blank?
@ -63,13 +62,12 @@ module HTTParty
when Net::HTTPRedirection
options[:limit] -= 1
self.path = response['location']
send_request
perform
else
response.instance_eval { class << self; attr_accessor :body_parsed; end }
begin; response.body_parsed = parse_response(response.body); rescue; end
response.error! # raises exception corresponding to http error Net::XXX
end
end
private