Class: Ably::Realtime::Models::ProtocolMessage
- Inherits:
-
Object
- Object
- Ably::Realtime::Models::ProtocolMessage
- Includes:
- Modules::Conversions, Shared
- Defined in:
- lib/ably/realtime/models/protocol_message.rb
Overview
A message sent and received over the Realtime protocol. A ProtocolMessage always relates to a single channel only, but can contain multiple individual Messages or PresenceMessages. ProtocolMessages are serially numbered on a connection. See the / Ably client library developer documentation for further details on the members of a ProtocolMessage
Constant Summary collapse
- ACTIONS =
Actions which are sent by the Ably Realtime API
The values correspond to the ints which the API understands.
{ heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze
Instance Attribute Summary collapse
-
#action ⇒ Integer
readonly
Protocol Message action from list of ACTIONS.
-
#action_sym ⇒ Symbol
readonly
Protocol Message action as a symbol.
-
#channel ⇒ String
readonly
Channel name for messages.
-
#channel_serial ⇒ String
readonly
Contains a serial number for amessage on the current channel.
-
#connection_id ⇒ String
readonly
Contains a string connection ID.
-
#connection_serial ⇒ Bignum
readonly
Contains a serial number for a message on the current connection.
-
#count ⇒ Integer
readonly
The count field is used for ACK and NACK actions.
-
#error_info ⇒ ErrorInfo
readonly
Contains error information.
-
#json ⇒ Hash
readonly
Access the protocol message Hash object ruby’fied to use symbolized keys.
-
#message_serial ⇒ Bignum
readonly
Contains a serial number for a message sent from the client to the service.
-
#messages ⇒ Message
readonly
A ProtocolMessage with a
:messageaction contains one or more messages belonging to a channel. -
#presence ⇒ PresenceMessage
readonly
A ProtocolMessage with a
:presenceaction contains one or more presence updates belonging to a channel. -
#timestamp ⇒ Time
readonly
An optional timestamp, applied by the service in messages sent to the client, to indicate the system time at which the message was sent (milliseconds past epoch).
Class Method Summary collapse
-
.ack_required?(for_action) ⇒ Boolean
Indicates this protocol message action will generate an ACK response such as :message or :presence.
-
.action!(action_sym) ⇒ Object
Retrive an action integer value from a symbol and raise an exception if invalid.
-
.action_sym_for(action_int) ⇒ Object
Retrieve an action symbol by the integer value.
Instance Method Summary collapse
-
#ack_required? ⇒ Boolean
Indicates this protocol message will generate an ACK response when sent Examples of protocol messages required ACK include :message and :presence.
- #error ⇒ Object
-
#initialize(json_object) ⇒ ProtocolMessage
constructor
A new instance of ProtocolMessage.
- #to_json(*args) ⇒ Object
- #to_json_object ⇒ Object
Methods included from Shared
Constructor Details
#initialize(json_object) ⇒ ProtocolMessage
Returns a new instance of ProtocolMessage.
80 81 82 83 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 80 def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end |
Instance Attribute Details
#action ⇒ Integer (readonly)
Returns Protocol Message action from list of ACTIONS.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#action_sym ⇒ Symbol (readonly)
Returns Protocol Message action as a symbol.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#channel ⇒ String (readonly)
Returns Channel name for messages.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#channel_serial ⇒ String (readonly)
Returns Contains a serial number for amessage on the current channel.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#connection_id ⇒ String (readonly)
Returns Contains a string connection ID.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#connection_serial ⇒ Bignum (readonly)
Returns Contains a serial number for a message on the current connection.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#count ⇒ Integer (readonly)
Returns The count field is used for ACK and NACK actions. See message acknowledgement protocol.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#error_info ⇒ ErrorInfo (readonly)
Returns Contains error information.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#json ⇒ Hash (readonly)
Returns Access the protocol message Hash object ruby’fied to use symbolized keys.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#message_serial ⇒ Bignum (readonly)
Returns Contains a serial number for a message sent from the client to the service.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#messages ⇒ Message (readonly)
Returns A Ably::Realtime::Models::ProtocolMessage with a :message action contains one or more messages belonging to a channel.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#presence ⇒ PresenceMessage (readonly)
Returns A Ably::Realtime::Models::ProtocolMessage with a :presence action contains one or more presence updates belonging to a channel.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
#timestamp ⇒ Time (readonly)
Returns An optional timestamp, applied by the service in messages sent to the client, to indicate the system time at which the message was sent (milliseconds past epoch).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 36 class ProtocolMessage include Shared include Ably::Modules::Conversions # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTIONS = { heartbeat: 0, ack: 1, nack: 2, connect: 3, connected: 4, disconnect: 5, disconnected: 6, close: 7, closed: 8, error: 9, attach: 10, attached: 11, detach: 12, detached: 13, presence: 14, message: 15 }.freeze # Retrieve an action symbol by the integer value def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end # Retrive an action integer value from a symbol and raise an exception if invalid def self.action!(action_sym) ACTIONS.fetch(action_sym) end # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end def initialize(json_object) @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze) end %w( action count channel channel_serial connection_id connection_serial ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def action_sym self.class.action_sym_for(action) end def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def json[:msg_serial] end def ||= Array(json[:messages]).map do || Message.new(, self) end end def presence @presence ||= Array(json[:presence]).map do || PresenceMessage.new(, self) end end def json @json_object end # Indicates this protocol message will generate an ACK response when sent # Examples of protocol messages required ACK include :message and :presence def ack_required? self.class.ack_required?(action) end def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end def to_json(*args) to_json_object.to_json end end |
Class Method Details
.ack_required?(for_action) ⇒ Boolean
Indicates this protocol message action will generate an ACK response such as :message or :presence
75 76 77 78 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 75 def self.ack_required?(for_action) for_action = ACTIONS.fetch(for_action) if for_action.kind_of?(Symbol) [action!(:presence), action!(:message)].include?(for_action) end |
.action!(action_sym) ⇒ Object
Retrive an action integer value from a symbol and raise an exception if invalid
70 71 72 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 70 def self.action!(action_sym) ACTIONS.fetch(action_sym) end |
.action_sym_for(action_int) ⇒ Object
Retrieve an action symbol by the integer value
64 65 66 67 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 64 def self.action_sym_for(action_int) @actions_index_by_int ||= ACTIONS.invert.freeze @actions_index_by_int[action_int] end |
Instance Method Details
#ack_required? ⇒ Boolean
Indicates this protocol message will generate an ACK response when sent Examples of protocol messages required ACK include :message and :presence
129 130 131 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 129 def ack_required? self.class.ack_required?(action) end |
#error ⇒ Object
97 98 99 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 97 def error @error_info ||= ErrorInfo.new(json[:error]) if json[:error] end |
#to_json(*args) ⇒ Object
143 144 145 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 143 def to_json(*args) to_json_object.to_json end |
#to_json_object ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/ably/realtime/models/protocol_message.rb', line 133 def to_json_object raise RuntimeError, ":action is missing, cannot generate valid JSON for ProtocolMessage" unless action_sym raise RuntimeError, ":msg_serial is missing, cannot generate valid JSON for ProtocolMessage" if ack_required? && ! json.dup.tap do |json_object| json_object[:messages] = .map(&:to_json_object) unless .empty? json_object[:presence] = presence.map(&:to_json_object) unless presence.empty? end end |