lib/httpi.rb in httpi-0.5.0 vs lib/httpi.rb in httpi-0.6.0
- old
+ new
@@ -67,10 +67,13 @@
#
# HTTPI.get request do |http|
# http.follow_redirect_count = 3 # HTTPClient example
# end
module HTTPI
+
+ REQUEST_METHODS = [:get, :post, :head, :put, :delete]
+
class << self
# Executes an HTTP GET request.
def get(request, adapter = nil)
request = Request.new :url => request if request.kind_of? String
@@ -117,9 +120,15 @@
with request, adapter do |adapter|
yield adapter.client if block_given?
adapter.delete request
end
+ end
+
+ # Executes an HTTP request for the given +method+.
+ def request(method, request, adapter = nil)
+ raise ArgumentError, "Invalid request method: #{method}" unless REQUEST_METHODS.include? method
+ send method, request, adapter
end
private
# Checks whether +args+ contains of an <tt>HTTPI::Request</tt> or a URL