Class: MailSandbox::Observer::Http

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

Instance Method Summary collapse

Constructor Details

#initialize(url, method = :post) ⇒ Http

Returns a new instance of Http.



6
7
8
9
# File 'lib/mail_sandbox/observer/http.rb', line 6

def initialize(url, method = :post)
  @url = url
  @method = method
end

Instance Method Details

#update(message) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/mail_sandbox/observer/http.rb', line 11

def update(message)
  body = {:message => message.to_a}

  MailSandbox.logger.debug "Observer::Http send to #{@url} method #{@method} body #{body.to_s}"

  http = EventMachine::HttpRequest.new(@url).send @method, :body => body
  http.errback {  MailSandbox.logger.error 'Observer::Http error.'   }
  http.callback {  MailSandbox.logger.debug 'Observer::Http sended.'   }

end