Class: Ably::Models::ProtocolMessage
- Inherits:
-
Object
- Object
- Ably::Models::ProtocolMessage
- Extended by:
- Ably::Modules::Enum
- Defined in:
- lib/submodules/ably-ruby/lib/ably/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
- ACTION =
Actions which are sent by the Ably Realtime API
The values correspond to the ints which the API understands.
ruby_enum('ACTION', 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, sync: 16 )
Instance Attribute Summary collapse
-
#action ⇒ ACTION
readonly
Protocol Message action Ably::Modules::Enum from list of ACTION.
-
#channel ⇒ String
readonly
Channel name for messages.
-
#channel_serial ⇒ String
readonly
Contains a serial number for a message on the current channel.
-
#connection_id ⇒ String
readonly
Contains a string public identifier for the connection.
-
#connection_key ⇒ String
readonly
Contains a string private connection key used to recover this connection.
-
#connection_serial ⇒ Bignum
readonly
Contains a serial number for a message sent from the server to the client.
-
#count ⇒ Integer
readonly
The count field is used for ACK and NACK actions.
-
#error_info ⇒ ErrorInfo
readonly
Contains error information.
-
#flags ⇒ Integer
readonly
Flags indicating special ProtocolMessage states.
-
#hash ⇒ 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 server.
-
#messages ⇒ Message
readonly
A ProtocolMessage with a ‘:message` action contains one or more messages belonging to a channel.
-
#presence ⇒ PresenceMessage
readonly
A ProtocolMessage with a ‘:presence` action 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.
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.
- #add_message(message) ⇒ Object
-
#as_json(*args) ⇒ Object
Return a JSON ready object from the underlying #hash using Ably naming conventions for keys.
- #error ⇒ Object
- #has_connection_serial? ⇒ Boolean
- #has_message_serial? ⇒ Boolean
- #has_presence_flag? ⇒ Boolean
- #has_serial? ⇒ Boolean
- #id! ⇒ Object
-
#initialize(hash_object, options = {}) ⇒ ProtocolMessage
constructor
ProtocolMessage initializer.
-
#invalid? ⇒ Boolean
private
True if the ProtocolMessage appears to be invalid, however this is not a guarantee.
- #serial ⇒ Object
- #to_s ⇒ Object
Methods included from Ably::Modules::SafeDeferrable
#callback, #errback, #fail, #succeed
Methods included from Ably::Modules::ModelCommon
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(hash_object, options = {}) ⇒ ProtocolMessage
Ably::Models::ProtocolMessage initializer
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 78 def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end |
Instance Attribute Details
#action ⇒ ACTION (readonly)
Returns Protocol Message action Ably::Modules::Enum from list of ACTION. Returns nil if action is unsupported by protocol.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#channel ⇒ String (readonly)
Returns Channel name for messages.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#channel_serial ⇒ String (readonly)
Returns Contains a serial number for a message on the current channel.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#connection_id ⇒ String (readonly)
Returns Contains a string public identifier for the connection.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#connection_key ⇒ String (readonly)
Returns Contains a string private connection key used to recover this connection.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#connection_serial ⇒ Bignum (readonly)
Returns Contains a serial number for a message sent from the server to the client.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#count ⇒ Integer (readonly)
Returns The count field is used for ACK and NACK actions. See message acknowledgement protocol.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#error_info ⇒ ErrorInfo (readonly)
Returns Contains error information.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#flags ⇒ Integer (readonly)
Returns Flags indicating special ProtocolMessage states.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#hash ⇒ Hash (readonly)
Returns Access the protocol message Hash object ruby’fied to use symbolized keys.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#message_serial ⇒ Bignum (readonly)
Returns Contains a serial number for a message sent from the client to the server.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#messages ⇒ Message (readonly)
Returns A Ably::Models::ProtocolMessage with a ‘:message` action contains one or more messages belonging to a channel.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
#presence ⇒ PresenceMessage (readonly)
Returns A Ably::Models::ProtocolMessage with a ‘:presence` action contains one or more presence updates belonging to a channel.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger 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).
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 38 class ProtocolMessage include Ably::Modules::ModelCommon include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API # understands. ACTION = ruby_enum('ACTION', 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, sync: 16 ) # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end # {ProtocolMessage} initializer # # @param hash_object [Hash] object with the underlying protocol message data # @param [Hash] options an options Hash for this initializer # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback # def initialize(hash_object, = {}) @logger = [:logger] # Logger expected for SafeDeferrable @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @hash_object.freeze end %w(id channel channel_serial connection_id connection_key).each do |attribute| define_method attribute do hash[attribute.to_sym] end end def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end def action ACTION(hash[:action]) rescue KeyError raise KeyError, "Action '#{hash[:action]}' is not supported by ProtocolMessage" end def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end def as_time_from_epoch(hash[:timestamp]) if hash[:timestamp] end def Integer(hash[:msg_serial]) rescue TypeError raise TypeError, "msg_serial '#{hash[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def connection_serial Integer(hash[:connection_serial]) rescue TypeError raise TypeError, "connection_serial '#{hash[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage" end def count [1, hash[:count].to_i].max end def && true rescue TypeError false end def has_connection_serial? connection_serial && true rescue TypeError false end def serial if has_connection_serial? connection_serial else end end def has_serial? has_connection_serial? || end def @messages ||= Array(hash[:messages]).map do || Ably::Models.Message(, protocol_message: self) end end def () << end def presence @presence ||= Array(hash[:presence]).map do || Ably::Models.PresenceMessage(, protocol_message: self) end end def flags Integer(hash[:flags]) rescue TypeError 0 end def has_presence_flag? flags & 1 == 1 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 hash @hash_object end # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end def to_s to_json end # True if the ProtocolMessage appears to be invalid, however this is not a guarantee # @return [Boolean] # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end private attr_reader :logger end |
Class Method Details
.ack_required?(for_action) ⇒ Boolean
Indicates this protocol message action will generate an ACK response such as :message or :presence
68 69 70 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 68 def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) 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
185 186 187 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 185 def ack_required? self.class.ack_required?(action) end |
#add_message(message) ⇒ Object
162 163 164 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 162 def () << end |
#as_json(*args) ⇒ Object
Return a JSON ready object from the underlying #hash using Ably naming conventions for keys
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 194 def as_json(*args) raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial? hash.dup.tap do |hash_object| hash_object['action'] = action.to_i hash_object['messages'] = .map(&:as_json) unless .empty? hash_object['presence'] = presence.map(&:as_json) unless presence.empty? end.as_json end |
#error ⇒ Object
107 108 109 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 107 def error @error_info ||= ErrorInfo.new(hash[:error]) if hash[:error] end |
#has_connection_serial? ⇒ Boolean
137 138 139 140 141 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 137 def has_connection_serial? connection_serial && true rescue TypeError false end |
#has_message_serial? ⇒ Boolean
131 132 133 134 135 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 131 def && true rescue TypeError false end |
#has_presence_flag? ⇒ Boolean
179 180 181 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 179 def has_presence_flag? flags & 1 == 1 end |
#has_serial? ⇒ Boolean
151 152 153 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 151 def has_serial? has_connection_serial? || end |
#id! ⇒ Object
96 97 98 99 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 96 def id! raise RuntimeError, 'ProtocolMessage #id is nil' unless id id end |
#invalid? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
True if the ProtocolMessage appears to be invalid, however this is not a guarantee
212 213 214 215 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 212 def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end |
#serial ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 143 def serial if has_connection_serial? connection_serial else end end |
#to_s ⇒ Object
205 206 207 |
# File 'lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb', line 205 def to_s to_json end |