Class: Swirl::EC2

Inherits:
Object
  • Object
show all
Defined in:
lib/em-swirl.rb

Instance Method Summary collapse

Instance Method Details

#post(body, &blk) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/em-swirl.rb', line 6

def post(body, &blk)
  headers = { "Content-Type" => "application/x-www-form-urlencoded" }

  http = EM::HttpRequest.new(@url.to_s)
  req  = http.post(:head => headers, :body => body)

  req.callback do
    begin
      blk.call(req.response_header.status, req.response)
    rescue => e
      req.fail(e)
    end
  end

  def req.error(&blk)
    errback(&blk)
  end

  req
end