Class: Handsoap::Http::Drivers::EventMachineDriver
- Inherits:
-
AbstractDriver
- Object
- AbstractDriver
- Handsoap::Http::Drivers::EventMachineDriver
- Defined in:
- lib/handsoap/http/drivers/event_machine_driver.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from AbstractDriver
#initialize, #parse_headers, #parse_http_part, #parse_multipart, #parse_multipart_boundary
Constructor Details
This class inherits a constructor from Handsoap::Http::Drivers::AbstractDriver
Class Method Details
.load! ⇒ Object
7 8 9 10 |
# File 'lib/handsoap/http/drivers/event_machine_driver.rb', line 7 def self.load! require 'eventmachine' require 'em-http' end |
Instance Method Details
#send_http_request_async(request) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/handsoap/http/drivers/event_machine_driver.rb', line 12 def send_http_request_async(request) emr = EventMachine::HttpRequest.new(request.url) if request.username && request.password # TODO: Verify that this is actually supported? request.headers['authorization'] = [request.username, request.password] end case request.http_method when :get emdef = emr.get(:head => request.headers) when :post emdef = emr.post(:head => request.headers, :body => request.body) when :put emdef = emr.put(:head => request.headers, :body => request.body) when :delete emdef = emr.delete else raise "Unsupported request method #{request.http_method}" end deferred = Handsoap::Deferred.new emdef.callback do http_response = parse_http_part(emdef.response_header, emdef.response, emdef.response_header.status) deferred.trigger_callback http_response end emdef.errback do deferred.trigger_errback emdef end deferred end |