Class: Keen::HTTP::Async

Inherits:
Object
  • Object
show all
Defined in:
lib/keen/http.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, options = {}) ⇒ Async

Returns a new instance of Async.



18
19
20
21
22
23
24
25
26
# File 'lib/keen/http.rb', line 18

def initialize(host, port, options={})
  if defined?(EventMachine) && EventMachine.reactor_running?
    require 'em-http-request'
  else
    raise Error, "An EventMachine loop must be running to use publish_async calls"
  end

  @host, @port, @http_options = host, port, options
end

Instance Method Details

#post(options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/keen/http.rb', line 28

def post(options)
  path, headers, body = options.values_at(
    :path, :headers, :body)
  uri = "https://#{@host}:#{@port}#{path}"
  http_client = EventMachine::HttpRequest.new(uri, @http_options)
  http_client.post(
    :body => body,
    :head => headers
  )
end