Class: ScaleRb::SubscriptionHandler
- Inherits:
-
Object
- Object
- ScaleRb::SubscriptionHandler
- Defined in:
- lib/scale_rb/client/ws_client.rb
Instance Method Summary collapse
- #handle(notification) ⇒ Object
-
#initialize ⇒ SubscriptionHandler
constructor
A new instance of SubscriptionHandler.
- #subscribe(subscription_id, callback) ⇒ Object
- #unsubscribe(subscription_id) ⇒ Object
Constructor Details
#initialize ⇒ SubscriptionHandler
Returns a new instance of SubscriptionHandler.
170 171 172 |
# File 'lib/scale_rb/client/ws_client.rb', line 170 def initialize @callbacks = {} end |
Instance Method Details
#handle(notification) ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/scale_rb/client/ws_client.rb', line 182 def handle(notification) subscription_id = notification.dig(:params, :subscription) return if subscription_id.nil? return unless @callbacks.key?(subscription_id) @callbacks[subscription_id].call(notification) end |
#subscribe(subscription_id, callback) ⇒ Object
174 175 176 |
# File 'lib/scale_rb/client/ws_client.rb', line 174 def subscribe(subscription_id, callback) @callbacks[subscription_id] = callback end |
#unsubscribe(subscription_id) ⇒ Object
178 179 180 |
# File 'lib/scale_rb/client/ws_client.rb', line 178 def unsubscribe(subscription_id) @callbacks.delete(subscription_id) end |