Class: HangoutsJsonParser::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/hangouts_json_parser/message.rb

Overview

A message sent in a Conversation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, timestamp, attachments
	@sender = sender
	@timestamp = timestamp
	@attachments = attachments
end

Instance Attribute Details

#attachmentsArray<Attachment> (readonly)

Returns attachments.

Returns:



9
10
11
# File 'lib/hangouts_json_parser/message.rb', line 9

def attachments
  @attachments
end

#senderUser (readonly)

Returns the User that sent this message.

Returns:

  • (User)

    the User that sent this message



5
6
7
# File 'lib/hangouts_json_parser/message.rb', line 5

def sender
  @sender
end

#timestampTime (readonly)

Returns timestamp.

Returns:

  • (Time)

    timestamp



7
8
9
# File 'lib/hangouts_json_parser/message.rb', line 7

def timestamp
  @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"

	attachments = (data.dig("chat_message", "message_content", "attachment") || []).map do |data|
		Attachment::Attachment.from_message_attachment data
	end

	# Timestamp is in microseconds, convert to float seconds
	Message.new nil, Time.at(data["timestamp"].to_f / 1.0e06), attachments
end