lib/muxer/request.rb in muxer-0.2.1 vs lib/muxer/request.rb in muxer-0.3.0

- old
+ new

@@ -1,6 +1,25 @@ module Muxer + # Muxer::Request is designed to wrap the requests that Muxer uses + # to parallelize the web requests and handle timeouts. + # + # @!attribute url + # @return [String] URL to use + # @!attribute timeout + # @return [Number] Seconds for the timeout + # @!attribute headers + # @return [Hash] Request headers to use with the request + # @!attribute params + # @return [Hash] request parameters + # @!attribute redirects + # @return [Integer] How many redirects to follow + # @!attribute method + # @return [Symbol] HTTP method to use + # @!attribute completed + # @return [Boolean] Is the request completed + # @!attribute error + # @return [Boolean] Have we had an error? class Request attr_accessor :url, :timeout, :headers, :params, :redirects attr_reader :method, :completed, :error alias_method :completed?, :completed @@ -12,16 +31,29 @@ @params = {} @request = nil @error = nil end + # sets the HTTP method of the request as long as the method + # is one off the standard http methods. The method can be sent + # in as a string or a symbol. + # The valid options are: + # :get, :post, :head, :options, :put, :delete + # + # @param method [string, symbol] HTTP Method of the request + # @return true def method=(method) method = method.downcase.to_sym @method = method if [:get, :post, :head, :options, :put, :delete].include? method + true end + # process! executes the web request. It cannot be called from + # outside of an EventMachine loop. + # + # @return self def process! http = EventMachine::HttpRequest.new(url, connect_timeout: timeout, inactivity_timeout: timeout, ) @@ -33,9 +65,10 @@ @request.callback { @completed = true } @request.errback { @completed = @error = true} self end + # response is the actual http request's response. def response if @request @request.response end end \ No newline at end of file