hangouts_json_parser 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/hangouts_json_parser.gemspec +2 -0
- data/lib/hangouts_json_parser.rb +15 -0
- data/lib/hangouts_json_parser/attachment.rb +28 -0
- data/lib/hangouts_json_parser/attachment/location.rb +30 -0
- data/lib/hangouts_json_parser/attachment/photo.rb +46 -0
- data/lib/hangouts_json_parser/conversation.rb +31 -0
- data/lib/hangouts_json_parser/message.rb +30 -0
- data/lib/hangouts_json_parser/user.rb +11 -0
- data/lib/hangouts_json_parser/version.rb +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 943423545cffd1c72445339df7b291598985165b
|
4
|
+
data.tar.gz: 0efc4089999bdad0128670d4158cf71c5819acf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fb7156fea27fe4e9ca7f6469ee292140be16eaf1ba0b0cee7bd40b0f4600d44207b8747e8143b96216e17517375ca71e0b4135201bdd779b9fdd0c7b568e800
|
7
|
+
data.tar.gz: bec713062ba76b29c6a541df29ce9a36f4885103594f2ed4eb689b377ec10908bb7658cc53b739f4423d3c0f383eddac2d7d6228dede2ac7b5e19429d2492c6b
|
data/.gitignore
CHANGED
data/lib/hangouts_json_parser.rb
CHANGED
@@ -1,7 +1,22 @@
|
|
1
|
+
require "ruby_dig"
|
2
|
+
|
1
3
|
require "hangouts_json_parser/version"
|
2
4
|
require "hangouts_json_parser/user"
|
5
|
+
require "hangouts_json_parser/attachment"
|
6
|
+
require "hangouts_json_parser/attachment/location"
|
7
|
+
require "hangouts_json_parser/attachment/photo"
|
8
|
+
require "hangouts_json_parser/message"
|
3
9
|
require "hangouts_json_parser/conversation"
|
4
10
|
|
5
11
|
# Parse JSON formatted Hangouts data into more useful data structures
|
6
12
|
module HangoutsJsonParser
|
13
|
+
# Parses conversation state into an array of Conversations
|
14
|
+
#
|
15
|
+
# @param state [Array<Hash>] converstation_state from the Takeout data
|
16
|
+
# @return [Array<Conversation>] all conversations in the state
|
17
|
+
def self.parse_conversation_state state
|
18
|
+
state.map do |s|
|
19
|
+
Conversation.from_state s['conversation_state']
|
20
|
+
end
|
21
|
+
end
|
7
22
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module HangoutsJsonParser
|
2
|
+
# All possible attachments
|
3
|
+
module Attachment
|
4
|
+
# An attachment to a chat message
|
5
|
+
class Attachment
|
6
|
+
# Creates an attachment from message data
|
7
|
+
# @param data [Hash] attachment data
|
8
|
+
# @return [Attachment] new Attachment
|
9
|
+
def self.from_message_attachment data
|
10
|
+
raise "Data passed is not an attachment" if data.dig("embed_item", "type").nil?
|
11
|
+
|
12
|
+
case data.dig("embed_item", "type")
|
13
|
+
when Photo.type
|
14
|
+
Photo.from_message_attachment data
|
15
|
+
when Location.type
|
16
|
+
Location.from_message_attachment data
|
17
|
+
else
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Array] type identifier of this attachment
|
23
|
+
def self.type
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module HangoutsJsonParser
|
2
|
+
module Attachment
|
3
|
+
# A location attachment
|
4
|
+
class Location < Attachment
|
5
|
+
#TODO: Extract all data from this object
|
6
|
+
#This one actually looks like it holds other types of attachments, that might be worth looking in to
|
7
|
+
|
8
|
+
# @return [String] url to the location on Google Maps
|
9
|
+
attr_reader :url
|
10
|
+
|
11
|
+
def initialize url
|
12
|
+
@url = url
|
13
|
+
end
|
14
|
+
|
15
|
+
# Creates a Location from message data
|
16
|
+
# @param data [Hash] attachment data
|
17
|
+
# @return [Location] new Location
|
18
|
+
def self.from_message_attachment data
|
19
|
+
raise "Attachment passed is not a location" unless data.dig("embed_item", "type").eql? Location.type
|
20
|
+
|
21
|
+
Location.new data.dig("embed_item", "id")
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Array] type identifier of this attachment
|
25
|
+
def self.type
|
26
|
+
["PLACE_V2", "THING_V2", "THING"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module HangoutsJsonParser
|
2
|
+
module Attachment
|
3
|
+
# A photo attachment
|
4
|
+
class Photo < Attachment
|
5
|
+
# @return [String] photo ID
|
6
|
+
attr_reader :id
|
7
|
+
# @return [String] album ID that the photo is in
|
8
|
+
attr_reader :album
|
9
|
+
# @return [String] link to the photo on Google+
|
10
|
+
attr_reader :photo_link
|
11
|
+
# @return [String] URL to thumbnail of the image
|
12
|
+
attr_reader :thumbnail
|
13
|
+
# @return [String] URL of the image
|
14
|
+
attr_reader :url
|
15
|
+
|
16
|
+
def initialize id, album, photo_link, thumbnail, url
|
17
|
+
@album = album
|
18
|
+
@id = id
|
19
|
+
@photo_link = photo_link
|
20
|
+
@thumbnail = thumbnail
|
21
|
+
@url = url
|
22
|
+
end
|
23
|
+
|
24
|
+
# Creates a Photo from message data
|
25
|
+
# @param data [Hash] attachment data
|
26
|
+
# @return [Photo] new Photo
|
27
|
+
def self.from_message_attachment data
|
28
|
+
raise "Attachment passed is not a photo" unless data.dig("embed_item", "type").eql? Photo.type
|
29
|
+
|
30
|
+
photo = data.dig("embed_item", "embeds.PlusPhoto.plus_photo")
|
31
|
+
raise "Photo data not found" if photo.nil?
|
32
|
+
|
33
|
+
Photo.new photo["photo_id"],
|
34
|
+
photo["album_id"],
|
35
|
+
photo.dig("thumbnail", "url"),
|
36
|
+
photo.dig("thumbnail", "image_url"),
|
37
|
+
photo["url"]
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Array] type identifier of this attachment
|
41
|
+
def self.type
|
42
|
+
["PLUS_PHOTO"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -7,5 +7,36 @@ module HangoutsJsonParser
|
|
7
7
|
attr_reader :type
|
8
8
|
# @return [Array<User>] the Users that are participating in this chat
|
9
9
|
attr_reader :participants
|
10
|
+
# @return [Array<Message>] the Messages in this chat
|
11
|
+
attr_reader :messages
|
12
|
+
|
13
|
+
def initialize id, type, participants, messages
|
14
|
+
@id = id
|
15
|
+
@type = type
|
16
|
+
@participants = participants
|
17
|
+
@messages = messages
|
18
|
+
end
|
19
|
+
|
20
|
+
# Creates a Conversation based on a conversation_state object
|
21
|
+
# @param state [Hash] conversation_state
|
22
|
+
# @return [Conversation] resulting Conversation
|
23
|
+
def self.from_state state
|
24
|
+
Conversation.new state['conversation']['id']['id'],
|
25
|
+
type_from_string(state['conversation']['type']),
|
26
|
+
state['conversation']['participant_data'].map(&User.method(:from_participant_data)),
|
27
|
+
state['event'].select{ |e| e["event_type"].eql? "REGULAR_CHAT_MESSAGE" }.map(&Message.method(:from_event_data))
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def self.type_from_string str
|
32
|
+
case str
|
33
|
+
when "STICKY_ONE_TO_ONE"
|
34
|
+
:private
|
35
|
+
when "GROUP"
|
36
|
+
:group
|
37
|
+
else
|
38
|
+
:unknown
|
39
|
+
end
|
40
|
+
end
|
10
41
|
end
|
11
42
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module HangoutsJsonParser
|
2
|
+
# A message sent in a Conversation
|
3
|
+
class Message
|
4
|
+
# @return [User] the User that sent this message
|
5
|
+
attr_reader :sender
|
6
|
+
# @return [Time] timestamp
|
7
|
+
attr_reader :timestamp
|
8
|
+
# @return [Array<Attachment>] attachments
|
9
|
+
attr_reader :attachments
|
10
|
+
|
11
|
+
def initialize sender, timestamp, attachments
|
12
|
+
@sender = sender
|
13
|
+
@timestamp = timestamp
|
14
|
+
@attachments = attachments
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a message from event data
|
18
|
+
def self.from_event_data data
|
19
|
+
# TODO: move type to const?
|
20
|
+
raise "Event passed is not a message" unless data["event_type"].eql? "REGULAR_CHAT_MESSAGE"
|
21
|
+
|
22
|
+
attachments = (data.dig("chat_message", "message_content", "attachment") || []).map do |data|
|
23
|
+
Attachment::Attachment.from_message_attachment data
|
24
|
+
end
|
25
|
+
|
26
|
+
# Timestamp is in microseconds, convert to float seconds
|
27
|
+
Message.new nil, Time.at(data["timestamp"].to_f / 1.0e06), attachments
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -10,5 +10,16 @@ module HangoutsJsonParser
|
|
10
10
|
def profile
|
11
11
|
"https://plus.google.com/#{id}"
|
12
12
|
end
|
13
|
+
|
14
|
+
def initialize id, name
|
15
|
+
@id = id
|
16
|
+
@name = name
|
17
|
+
end
|
18
|
+
|
19
|
+
# Creates a user from participant data
|
20
|
+
def self.from_participant_data data
|
21
|
+
# TODO: Use the Google+ API to actually look up this person?
|
22
|
+
User.new data['id']['gaia_id'], data['fallback_name']
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hangouts_json_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim van Dalen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby_dig
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.2
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- tim.vandalen@nubisonline.nl
|
@@ -54,7 +68,11 @@ files:
|
|
54
68
|
- bin/setup
|
55
69
|
- hangouts_json_parser.gemspec
|
56
70
|
- lib/hangouts_json_parser.rb
|
71
|
+
- lib/hangouts_json_parser/attachment.rb
|
72
|
+
- lib/hangouts_json_parser/attachment/location.rb
|
73
|
+
- lib/hangouts_json_parser/attachment/photo.rb
|
57
74
|
- lib/hangouts_json_parser/conversation.rb
|
75
|
+
- lib/hangouts_json_parser/message.rb
|
58
76
|
- lib/hangouts_json_parser/user.rb
|
59
77
|
- lib/hangouts_json_parser/version.rb
|
60
78
|
homepage: https://github.com/nubisonline/hangouts_json_parser
|