Class: Shove::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/shove/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, headers = {}) ⇒ Request

Returns a new instance of Request.



6
7
8
9
# File 'lib/shove/request.rb', line 6

def initialize url, headers={}
  self.url = url
  self.headers = headers
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/shove/request.rb', line 4

def headers
  @headers
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/shove/request.rb', line 4

def url
  @url
end

Instance Method Details

#post(params = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shove/request.rb', line 11

def post params={}, &block
  if EM.reactor_running?
    http = EventMachine::HttpRequest.new(url).post(:body => params, :head => headers)
    if block
      http.errback { 
        block.call(Response.new(http.response_header.status, http.response, true))
      }
      http.callback {
        block.call(Response.new(http.response_header.status, http.response, false))
      }
    end
  else
    raise "EM requests only for now."
  end
end