Class: Asap::Netty::HttpResponseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/asap/netty/http_response_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback) ⇒ HttpResponseHandler

Returns a new instance of HttpResponseHandler.



6
7
8
9
# File 'lib/asap/netty/http_response_handler.rb', line 6

def initialize(callback)
  super()
  @callback = callback
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



4
5
6
# File 'lib/asap/netty/http_response_handler.rb', line 4

def callback
  @callback
end

Instance Method Details

#messageReceived(ctxt, e) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/asap/netty/http_response_handler.rb', line 11

def messageReceived(ctxt, e)
  response = e.get_message
  if response.get_status.get_code == 200
    callback.call(response.get_content.to_string(org.jboss.netty.util.CharsetUtil::UTF_8))
  else
    raise "Request failed with #{response.get_status.get_code}"
  end
end