class AsyncConnectionAdapter::AsyncHTTPConnection

add a request method to EventMachine::HttpConnection to simulate how Net::HTTP works

Public Instance Methods

request(raw_request) click to toggle source
# File lib/resthome/httparty/async_connection_adapter.rb, line 19
def request(raw_request)
  options = {:head => {}}
  raw_request.each_header do |k, v|
    options[:head][k] = v
  end

  if raw_request.body
    options[:head]['Content-Length'] = raw_request.body.bytesize
    options[:head]['Content-Type'] ||= 'application/x-www-form-urlencoded'
    options[:body] = raw_request.body
  end

  case raw_request
  when Net::HTTP::Get
    AsyncHTTPResponse.new self.get options
  when Net::HTTP::Post
    AsyncHTTPResponse.new self.post options
  when Net::HTTP::Put
    AsyncHTTPResponse.new self.put options
  when Net::HTTP::Delete
    AsyncHTTPResponse.new self.delete options
  when Net::HTTP::Head
    AsyncHTTPResponse.new self.head options
  else
    raise "unknown request type #{raw_request}"
  end
end