lib/hyperclient/http.rb in hyperclient-0.0.5 vs lib/hyperclient/http.rb in hyperclient-0.0.6
- old
+ new
@@ -24,10 +24,11 @@
# 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)
+ enable_debug(options[:debug]) if options && options.include?(:debug)
end
# Public: Sends a GET request the the resource url.
#
# Returns: The parsed response.
@@ -96,8 +97,22 @@
# headers({'accept-encoding' => 'deflate, gzip'})
#
# Returns nothing.
def headers(headers)
self.class.send(:headers, headers)
+ end
+
+ # Internal: Enables HTTP debugging.
+ #
+ # stream - An object to stream the HTTP out to or just a truthy value. If
+ # it's truthy it will output to $stderr.
+ def enable_debug(stream)
+ return unless stream
+
+ if stream.respond_to?(:<<)
+ self.class.debug_output(stream)
+ else
+ self.class.debug_output
+ end
end
end
end