lib/hyperclient/http.rb in hyperclient-0.0.4 vs lib/hyperclient/http.rb in hyperclient-0.0.5
- old
+ new
@@ -23,10 +23,11 @@
# resource - A Resource instance. A Resource is given instead of the url
# since the resource url could change during its live.
def initialize(resource, options = {})
@resource = resource
authenticate(options[:auth]) if options && options.include?(:auth)
+ headers(options[:headers]) if options && options.include?(:headers)
end
# Public: Sends a GET request the the resource url.
#
# Returns: The parsed response.
@@ -72,19 +73,31 @@
def delete
self.class.delete(url)
end
private
- # Internal: Sets the authenitcation method for HTTParty.
+ # Internal: Sets the authentication method for HTTParty.
#
# options - An options Hash to set the authentication options.
# :type - A String or Symbol to set the authentication type.
# Can be either :digest or :basic.
# :credentials - An Array of Strings with the user and password.
#
# Returns nothing.
def authenticate(options)
auth_method = options[:type].to_s + '_auth'
self.class.send(auth_method, *options[:credentials])
+ end
+
+ # Internal: Adds default headers for all the requests.
+ #
+ # headers - A Hash with the header.
+ #
+ # Example:
+ # headers({'accept-encoding' => 'deflate, gzip'})
+ #
+ # Returns nothing.
+ def headers(headers)
+ self.class.send(:headers, headers)
end
end
end