Class: Keen::HTTP::Async
- Inherits:
-
Object
- Object
- Keen::HTTP::Async
- Defined in:
- lib/keen/http.rb
Instance Method Summary collapse
-
#initialize(base_url, options = {}) ⇒ Async
constructor
A new instance of Async.
- #post(options) ⇒ Object
Constructor Details
#initialize(base_url, options = {}) ⇒ Async
Returns a new instance of Async.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/keen/http.rb', line 49 def initialize(base_url, ={}) 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 @base_url = base_url @proxy_url, @proxy_type = .values_at(:proxy_url, :proxy_type) end |
Instance Method Details
#post(options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/keen/http.rb', line 60 def post() path, headers, body = .values_at( :path, :headers, :body) uri = "#{@base_url}#{path}" if @proxy_url proxy_uri = URI.parse(@proxy_url) = {:proxy => {:host => proxy_uri.host, :port => proxy_uri.port, :authorization => [proxy_uri.user, proxy_uri.password], :type => @proxy_type || "http"}} http_client = EventMachine::HttpRequest.new(uri, ) else http_client = EventMachine::HttpRequest.new(uri) end http_client.post( :body => body, :head => headers ) end |