lib/httpi.rb in httpi-0.8.0 vs lib/httpi.rb in httpi-0.9.0
- old
+ new
@@ -22,11 +22,11 @@
# == POST
#
# request = HTTPI::Request.new
# request.url = "http://example.com"
# request.body = "<some>xml</some>"
-#
+#
# HTTPI.post request, :httpclient
#
# === Shortcuts
#
# HTTPI.post "http://example.com", "<some>xml</some>", :curb
@@ -43,11 +43,11 @@
# == PUT
#
# request = HTTPI::Request.new
# request.url = "http://example.com"
# request.body = "<some>xml</some>"
-#
+#
# HTTPI.put request, :httpclient
#
# === Shortcuts
#
# HTTPI.put "http://example.com", "<some>xml</some>", :curb
@@ -78,51 +78,51 @@
class << self
# Executes an HTTP GET request.
def get(request, adapter = nil)
request = Request.new :url => request if request.kind_of? String
-
+
with_adapter :get, request, adapter do |adapter|
yield adapter.client if block_given?
adapter.get request
end
end
# Executes an HTTP POST request.
def post(*args)
request, adapter = request_and_adapter_from(args)
-
+
with_adapter :post, request, adapter do |adapter|
yield adapter.client if block_given?
adapter.post request
end
end
# Executes an HTTP HEAD request.
def head(request, adapter = nil)
request = Request.new :url => request if request.kind_of? String
-
+
with_adapter :head, request, adapter do |adapter|
yield adapter.client if block_given?
adapter.head request
end
end
# Executes an HTTP PUT request.
def put(*args)
request, adapter = request_and_adapter_from(args)
-
+
with_adapter :put, request, adapter do |adapter|
yield adapter.client if block_given?
adapter.put request
end
end
# Executes an HTTP DELETE request.
def delete(request, adapter = nil)
request = Request.new :url => request if request.kind_of? String
-
+
with_adapter :delete, request, adapter do |adapter|
yield adapter.client if block_given?
adapter.delete request
end
end
@@ -157,11 +157,12 @@
@log_level ||= DEFAULT_LOG_LEVEL
end
# Logs given +messages+.
def log(*messages)
- logger.send log_level, messages.join(" ") if log?
+ level = Symbol === messages.first ? messages.shift : log_level
+ logger.send level, messages.join(" ") if log?
end
# Reset the default config.
def reset_config!
@log = nil
@@ -180,13 +181,12 @@
end
# Expects a request +method+, a +request+ and an +adapter+ (defaults to
# <tt>Adapter.use</tt>) and yields an instance of the adapter to a given block.
def with_adapter(method, request, adapter)
- adapter ||= Adapter.use
- adapter, adapter_class = Adapter.find adapter
-
- HTTPI.logger.debug "HTTPI executes HTTP #{method.to_s.upcase} using the #{adapter} adapter"
+ adapter, adapter_class = Adapter.load adapter
+
+ log :debug, "HTTPI executes HTTP #{method.to_s.upcase} using the #{adapter} adapter"
yield adapter_class.new(request)
end
end
end