From 67cb57256ff8ee1d3703fbe9fb8b8a1adf39a473 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Tue, 11 Nov 2008 19:07:11 -0500 Subject: [PATCH] Switched from send to perform which sounds fancier. --- lib/httparty.rb | 12 ++++++------ lib/httparty/request.rb | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/httparty.rb b/lib/httparty.rb index 7e02cb9..e0dbd83 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -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 diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index bf205c3..59f5fe0 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -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