Class: Ably::Realtime::Models::Message
- Inherits:
-
Object
- Object
- Ably::Realtime::Models::Message
- Includes:
- Modules::Conversions, Shared
- Defined in:
- lib/ably/realtime/models/message.rb
Overview
A class representing an individual message to be sent or received via the Ably Realtime service.
Instance Attribute Summary collapse
-
#ably_timestamp ⇒ Time
readonly
Timestamp when the message was received by the Ably the service for publishing.
-
#client_id ⇒ String
readonly
The id of the publisher of this message.
-
#data ⇒ Object
readonly
The message payload.
-
#json ⇒ Hash
readonly
Access the protocol message Hash object ruby’fied to use symbolized keys.
-
#message_id ⇒ String
readonly
A globally unique message ID.
-
#name ⇒ String
readonly
The event name, if available.
-
#sender_timestamp ⇒ Time
readonly
Timestamp when the message was sent according to the publisher client.
Instance Method Summary collapse
-
#initialize(json_object, protocol_message) ⇒ Message
constructor
A new instance of Message.
- #to_json(*args) ⇒ Object
- #to_json_object ⇒ Object
Methods included from Shared
Constructor Details
#initialize(json_object, protocol_message) ⇒ Message
Returns a new instance of Message.
24 25 26 27 28 |
# File 'lib/ably/realtime/models/message.rb', line 24 def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end |
Instance Attribute Details
#ably_timestamp ⇒ Time (readonly)
Returns Timestamp when the message was received by the Ably the service for publishing.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/ably/realtime/models/message.rb', line 20 class Message include Shared include Ably::Modules::Conversions def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end %w( name client_id ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def data @data ||= json[:data].freeze end def "#{connection_id}:#{message_serial}:#{protocol_message_index}" end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def . end def json @json_object end def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end def to_json(*args) to_json_object.to_json end private attr_reader :protocol_message def ..index(self) end def connection_id .connection_id end def . end end |
#client_id ⇒ String (readonly)
Returns The id of the publisher of this message.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/ably/realtime/models/message.rb', line 20 class Message include Shared include Ably::Modules::Conversions def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end %w( name client_id ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def data @data ||= json[:data].freeze end def "#{connection_id}:#{message_serial}:#{protocol_message_index}" end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def . end def json @json_object end def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end def to_json(*args) to_json_object.to_json end private attr_reader :protocol_message def ..index(self) end def connection_id .connection_id end def . end end |
#data ⇒ Object (readonly)
Returns The message payload. See the documentation for supported datatypes.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/ably/realtime/models/message.rb', line 20 class Message include Shared include Ably::Modules::Conversions def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end %w( name client_id ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def data @data ||= json[:data].freeze end def "#{connection_id}:#{message_serial}:#{protocol_message_index}" end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def . end def json @json_object end def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end def to_json(*args) to_json_object.to_json end private attr_reader :protocol_message def ..index(self) end def connection_id .connection_id end def . end end |
#json ⇒ Hash (readonly)
Returns Access the protocol message Hash object ruby’fied to use symbolized keys.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/ably/realtime/models/message.rb', line 20 class Message include Shared include Ably::Modules::Conversions def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end %w( name client_id ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def data @data ||= json[:data].freeze end def "#{connection_id}:#{message_serial}:#{protocol_message_index}" end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def . end def json @json_object end def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end def to_json(*args) to_json_object.to_json end private attr_reader :protocol_message def ..index(self) end def connection_id .connection_id end def . end end |
#message_id ⇒ String (readonly)
Returns A globally unique message ID.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/ably/realtime/models/message.rb', line 20 class Message include Shared include Ably::Modules::Conversions def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end %w( name client_id ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def data @data ||= json[:data].freeze end def "#{connection_id}:#{message_serial}:#{protocol_message_index}" end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def . end def json @json_object end def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end def to_json(*args) to_json_object.to_json end private attr_reader :protocol_message def ..index(self) end def connection_id .connection_id end def . end end |
#name ⇒ String (readonly)
Returns The event name, if available.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/ably/realtime/models/message.rb', line 20 class Message include Shared include Ably::Modules::Conversions def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end %w( name client_id ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def data @data ||= json[:data].freeze end def "#{connection_id}:#{message_serial}:#{protocol_message_index}" end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def . end def json @json_object end def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end def to_json(*args) to_json_object.to_json end private attr_reader :protocol_message def ..index(self) end def connection_id .connection_id end def . end end |
#sender_timestamp ⇒ Time (readonly)
Returns Timestamp when the message was sent according to the publisher client.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/ably/realtime/models/message.rb', line 20 class Message include Shared include Ably::Modules::Conversions def initialize(json_object, ) = @raw_json_object = json_object @json_object = IdiomaticRubyWrapper(@raw_json_object.clone.freeze, stop_at: [:data]) end %w( name client_id ).each do |attribute| define_method attribute do json[attribute.to_sym] end end def data @data ||= json[:data].freeze end def "#{connection_id}:#{message_serial}:#{protocol_message_index}" end def as_time_from_epoch(json[:timestamp]) if json[:timestamp] end def . end def json @json_object end def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end def to_json(*args) to_json_object.to_json end private attr_reader :protocol_message def ..index(self) end def connection_id .connection_id end def . end end |
Instance Method Details
#to_json(*args) ⇒ Object
64 65 66 |
# File 'lib/ably/realtime/models/message.rb', line 64 def to_json(*args) to_json_object.to_json end |
#to_json_object ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ably/realtime/models/message.rb', line 56 def to_json_object raise RuntimeError, ":name is missing, cannot generate valid JSON for Message" unless name json.dup.tap do |json_object| json_object[:timestamp] = as_since_epoch(Time.now) unless end end |