0
@@ -28,10 +28,15 @@ module HTTParty
0
@base_uri = normalize_base_uri(base_uri)
0
+ # Warning: This is not thread safe most likely and
0
+ # only works if you use one set of credentials. I
0
+ # leave it because it is convenient on some occasions.
0
@auth = {:username => u, :password => p}
0
+ # Updates the default query string parameters
0
+ # that should be appended to each request.
0
def default_params(h={})
0
raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash)
0
@@ -83,14 +88,17 @@ module HTTParty
0
+ # FIXME: this method is doing way to much and needs to be split up
0
# options can be any or all of:
0
- # query => hash of keys/values to be converted to query string
0
- # body => string for raw post data
0
- # headers => hash of headers to send request with
0
+ # query => hash of keys/values to be converted to query string
0
+ # body => string for raw post data
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
def send_request(method, path, options={})
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, ':query must be a hash' if options[:query] && !options[:query].is_a?(Hash)
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
# we always want path that begins with /
0
path = path =~ /^(\/|https?:\/\/)/ ? path : "/#{path}"
0
@format ||= format_from_path(path)
0
@@ -100,9 +108,11 @@ module HTTParty
0
klass = Net::HTTP.const_get method.to_s.downcase.capitalize
0
request = klass.new(uri.request_uri)
0
request.body = options[:body] unless options[:body].blank?
0
+ basic_auth = options.delete(:basic_auth) || @auth
0
request.initialize_http_header headers.merge(options[:headers] || {})
0
- request.basic_auth(@auth[:username], @auth[:password]) if @auth
0
- response = http(uri).start() { |conn| conn.request(request) }
0
+ # note to self: self, do not put basic auth above headers because it removes basic auth
0
+ request.basic_auth(basic_auth[:username], basic_auth[:password]) if basic_auth
0
+ response = http(uri).request(request)
0
parse_response(response.body)