Class: ScaleRb::ResponseHandler
- Inherits:
-
Object
- Object
- ScaleRb::ResponseHandler
- Defined in:
- lib/scale_rb/client/ws_client.rb
Instance Method Summary collapse
- #handle(response) ⇒ Object
-
#initialize ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
-
#register(id, callback) ⇒ Object
callback: a proc with response data as param.
Constructor Details
#initialize ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
148 149 150 |
# File 'lib/scale_rb/client/ws_client.rb', line 148 def initialize @callbacks = {} end |
Instance Method Details
#handle(response) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/scale_rb/client/ws_client.rb', line 157 def handle(response) id = response[:id] if @callbacks.key?(id) callback = @callbacks[id] callback.call(response) @callbacks.delete(id) else ScaleRb.logger.info "Received a message with unknown id: #{response}" end end |
#register(id, callback) ⇒ Object
callback: a proc with response data as param
153 154 155 |
# File 'lib/scale_rb/client/ws_client.rb', line 153 def register(id, callback) @callbacks[id] = callback end |