class ConnectClient::Http::EmHttp
Public Class Methods
new(base_url, headers)
click to toggle source
# File lib/connect_client/http/event_endpoint.rb, line 72 def initialize(base_url, headers) require 'em-http-request' require_relative 'deferred_http_response' @headers = headers @base_url = base_url.chomp('/') end
Public Instance Methods
create_response(http_reponse, events)
click to toggle source
# File lib/connect_client/http/event_endpoint.rb, line 119 def create_response(http_reponse, events) status = http_reponse.response_header.status content_type = http_reponse.response_header['Content-Type'] if (http_reponse.error.to_s.empty?) ConnectClient::EventPushResponse.new status, content_type, http_reponse.response, events else ConnectClient::EventPushResponse.new status, content_type, http_reponse.error, events end end
push_events(path, body, events)
click to toggle source
# File lib/connect_client/http/event_endpoint.rb, line 80 def push_events(path, body, events) raise AsyncHttpError unless defined?(EventMachine) && EventMachine.reactor_running? use_syncrony = defined?(EM::Synchrony) if use_syncrony push_events_using_synchrony(path, body, events) else push_events_using_deferred(path, body, events) end end
push_events_using_deferred(path, body, events)
click to toggle source
# File lib/connect_client/http/event_endpoint.rb, line 92 def push_events_using_deferred(path, body, events) deferred = DeferredHttpResponse.new url_string = "#{@base_url}#{path}".chomp('/') http = EventMachine::HttpRequest.new(url_string).post(:body => body, :head => @headers) http_callback = Proc.new do begin response = create_response http, events deferred.succeed response rescue => error deferred.fail error end end http.callback &http_callback http.errback &http_callback deferred end
push_events_using_synchrony(path, body, events)
click to toggle source
# File lib/connect_client/http/event_endpoint.rb, line 111 def push_events_using_synchrony(path, body, events) url_string = "#{@base_url}#{path}".chomp('/') http = EventMachine::HttpRequest.new(url_string). post(:body => body, :head => @headers) create_response http, events end