Class: Satori::RTM::SubscriptionEvent
- Inherits:
-
Object
- Object
- Satori::RTM::SubscriptionEvent
- Defined in:
- lib/satori-rtm-sdk/model.rb
Overview
Event about new subscription data or subscription status change.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Returns an event data.
-
#type ⇒ :init, ...
readonly
Returns a type of event.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns
true
if event is an error PDU. -
#initialize(type, data) ⇒ SubscriptionEvent
constructor
A new instance of SubscriptionEvent.
Constructor Details
#initialize(type, data) ⇒ SubscriptionEvent
Returns a new instance of SubscriptionEvent
23 24 25 26 27 28 29 30 31 |
# File 'lib/satori-rtm-sdk/model.rb', line 23 def initialize(type, data) if type == :pdu @type = resolve_type(data[:action]) @data = data[:body] else @type = type @data = data end end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns an event data. In most cases it represent body
field
from incoming subscribe / subscription / unsubscribe PDUs. The type of PDU
is accessible by type
attribute. Information about fields in
data
could be found in RTM API specification.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/satori-rtm-sdk/model.rb', line 20 class SubscriptionEvent attr_reader :data, :type def initialize(type, data) if type == :pdu @type = resolve_type(data[:action]) @data = data[:body] else @type = type @data = data end end # Returns +true+ if event is an error PDU. # # @return [Boolean] +true+ if event is an error PDU, +false+ otherwise def error? type == :error end private def resolve_type(action) case action when 'rtm/subscribe/ok' :subscribed when 'rtm/unsubscribe/ok' :unsubscribed when 'rtm/subscription/info' :info when 'rtm/subscription/data' :data when 'rtm/subscription/error', 'rtm/subscribe/error', 'rtm/unsubscribe/error' :error end end end |
#type ⇒ :init, ... (readonly)
Returns a type of event.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/satori-rtm-sdk/model.rb', line 20 class SubscriptionEvent attr_reader :data, :type def initialize(type, data) if type == :pdu @type = resolve_type(data[:action]) @data = data[:body] else @type = type @data = data end end # Returns +true+ if event is an error PDU. # # @return [Boolean] +true+ if event is an error PDU, +false+ otherwise def error? type == :error end private def resolve_type(action) case action when 'rtm/subscribe/ok' :subscribed when 'rtm/unsubscribe/ok' :unsubscribed when 'rtm/subscription/info' :info when 'rtm/subscription/data' :data when 'rtm/subscription/error', 'rtm/subscribe/error', 'rtm/unsubscribe/error' :error end end end |
Instance Method Details
#error? ⇒ Boolean
Returns true
if event is an error PDU.
36 37 38 |
# File 'lib/satori-rtm-sdk/model.rb', line 36 def error? type == :error end |