lib/muxer/request.rb in muxer-0.0.3 vs lib/muxer/request.rb in muxer-0.0.4

- old
+ new

@@ -1,29 +1,40 @@ module Muxer class Request attr_accessor :url, :timeout, :headers - attr_reader :method + attr_reader :method, :completed, :error + alias_method :completed?, :completed def initialize - @method = :GET - @timeout = nil + @method = :get + @completed = false + @timeout = 10 @headers = {} + @request = nil + @error = nil end def method=(method) method = method.downcase.to_sym - @method = method.upcase if [:get, :post, :head, :options, :put, :delete].include? method + @method = method if [:get, :post, :head, :options, :put, :delete].include? method end def process! - http = EventMachine::HttpRequest.new(url) - http.public_send(method, - head: headers, + http = EventMachine::HttpRequest.new(url, connect_timeout: timeout, - inactivity_timeout: timeout + inactivity_timeout: timeout, ) + @request = http.public_send(method, + head: headers, + ) - + @request.callback { @completed = true } + @request.errback { @completed = @error = true} + self + end + + def response + @request.response end end end \ No newline at end of file