Class: HangoutsJsonParser::Message
- Inherits:
-
Object
- Object
- HangoutsJsonParser::Message
- Defined in:
- lib/hangouts_json_parser/message.rb
Overview
A message sent in a Conversation
Instance Attribute Summary collapse
-
#attachments ⇒ Array<Attachment>
readonly
Attachments.
-
#sender ⇒ User
readonly
The User that sent this message.
-
#timestamp ⇒ Time
readonly
Timestamp.
Class Method Summary collapse
-
.from_event_data(data) ⇒ Object
Creates a message from event data.
Instance Method Summary collapse
-
#initialize(sender, timestamp, attachments) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(sender, timestamp, attachments) ⇒ Message
Returns a new instance of Message.
11 12 13 14 15 |
# File 'lib/hangouts_json_parser/message.rb', line 11 def initialize sender, , @sender = sender @timestamp = @attachments = end |
Instance Attribute Details
#attachments ⇒ Array<Attachment> (readonly)
Returns attachments.
9 10 11 |
# File 'lib/hangouts_json_parser/message.rb', line 9 def @attachments end |
#sender ⇒ User (readonly)
Returns the User that sent this message.
5 6 7 |
# File 'lib/hangouts_json_parser/message.rb', line 5 def sender @sender end |
#timestamp ⇒ Time (readonly)
Returns timestamp.
7 8 9 |
# File 'lib/hangouts_json_parser/message.rb', line 7 def @timestamp end |
Class Method Details
.from_event_data(data) ⇒ Object
Creates a message from event data
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hangouts_json_parser/message.rb', line 18 def self.from_event_data data # TODO: move type to const? raise "Event passed is not a message" unless data["event_type"].eql? "REGULAR_CHAT_MESSAGE" = (data.dig("chat_message", "message_content", "attachment") || []).map do |data| Attachment::Attachment. data end # Timestamp is in microseconds, convert to float seconds Message.new nil, Time.at(data["timestamp"].to_f / 1.0e06), end |