Sha256: 634663b4d65af9396be2f7950c98756d805f19d90e0cf0e6825255d9e86c44af

Contents?: true

Size: 1.35 KB

Versions: 17

Compression:

Stored size: 1.35 KB

Contents

# -*- coding: utf-8 -*-

module Handsoap
  module Http
    module Drivers
      class EventMachineDriver < AbstractDriver
        def self.load!
          require 'eventmachine'
          require 'em-http'
        end

        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
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
handsoap-1.4.0 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.3.0 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.2.2 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.8 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.7 lib/handsoap/http/drivers/event_machine_driver.rb
pgericson-handsoap-1.1.10 lib/handsoap/http/drivers/event_machine_driver.rb
pgericson-handsoap-1.1.9 lib/handsoap/http/drivers/event_machine_driver.rb
pgericson-handsoap-1.1.8 lib/handsoap/http/drivers/event_machine_driver.rb
pgericson-handsoap-1.1.7 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.6 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.5 lib/handsoap/http/drivers/event_machine_driver.rb
whenyouneedme-handsoap-1.1.4 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.4 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.3 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.2 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.1 lib/handsoap/http/drivers/event_machine_driver.rb
handsoap-1.1.0 lib/handsoap/http/drivers/event_machine_driver.rb