yamwow 0.0.9 → 0.0.10
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.
- data/lib/yamwow/facade.rb +4 -1
- data/lib/yamwow/message_builder.rb +30 -0
- data/lib/yamwow/messages_with_topic_request.rb +12 -28
- metadata +5 -4
data/lib/yamwow/facade.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'client'
|
2
2
|
Dir[File.expand_path(File.dirname(__FILE__) + '/*_request.rb')].each { |f| require f }
|
3
|
+
require_relative 'message_builder'
|
3
4
|
|
4
5
|
module YamWow
|
5
6
|
class Facade
|
@@ -9,7 +10,9 @@ module YamWow
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def messages_with_topic(topic_name, options={})
|
12
|
-
MessagesWithTopicRequest.new(@client, topic_name, options).send
|
13
|
+
r = MessagesWithTopicRequest.new(@client, topic_name, options).send
|
14
|
+
b = MessageBuilder.new
|
15
|
+
r['messages'].map { |m| b.build_message m, r['references'] }
|
13
16
|
end
|
14
17
|
|
15
18
|
def praises(options={})
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module YamWow
|
2
|
+
class MessageBuilder
|
3
|
+
|
4
|
+
def build_message(message_data, reference_data)
|
5
|
+
d = message_data
|
6
|
+
m = Message.new
|
7
|
+
m.id = d['id']
|
8
|
+
m.plain_body = d['body']['plain']
|
9
|
+
m.parsed_body = d['body']['parsed']
|
10
|
+
m.date_created = Time.parse d['created_at']
|
11
|
+
m.like_count = d['liked_by']['count'].to_i
|
12
|
+
m.url = d['web_url']
|
13
|
+
m.sender = build_user d['sender_id'], reference_data
|
14
|
+
m.reply_to_id = d['replied_to_id']
|
15
|
+
m.attachments = d['attachments']
|
16
|
+
m
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_user(user_id, reference_data)
|
22
|
+
d = reference_data.select { |r| r['id'] == user_id }[0]
|
23
|
+
u = User.new
|
24
|
+
u.id = d['id']
|
25
|
+
u.name = d['full_name']
|
26
|
+
u
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -13,6 +13,7 @@ module YamWow
|
|
13
13
|
|
14
14
|
def send
|
15
15
|
@messages = []
|
16
|
+
@references = []
|
16
17
|
loop_finished = false
|
17
18
|
|
18
19
|
until loop_finished
|
@@ -24,8 +25,12 @@ module YamWow
|
|
24
25
|
loop_finished = no_more_messages || limit_reached
|
25
26
|
end
|
26
27
|
|
27
|
-
@messages.sort! { |x, y| y
|
28
|
-
|
28
|
+
@messages.sort! { |x, y| Time.parse(y['created_at']) <=> Time.parse(x['created_at']) }
|
29
|
+
|
30
|
+
{
|
31
|
+
'messages' => @messages,
|
32
|
+
'references' => @references
|
33
|
+
}
|
29
34
|
end
|
30
35
|
|
31
36
|
private
|
@@ -46,40 +51,19 @@ module YamWow
|
|
46
51
|
end
|
47
52
|
|
48
53
|
def oldest_message_id
|
49
|
-
|
54
|
+
sorted_messages = @messages.sort { |x, y| Time.parse(y['created_at']) <=> Time.parse(x['created_at']) }
|
55
|
+
last_message = sorted_messages.last
|
50
56
|
last_message.id if last_message
|
51
57
|
end
|
52
58
|
|
53
59
|
def add_messages(messages_data, reference_data)
|
54
60
|
@messages += build_messages messages_data, reference_data
|
55
61
|
@messages = @messages[0..limit_count-1] if limit_count > 0
|
62
|
+
@references += reference_data
|
56
63
|
end
|
57
64
|
|
58
65
|
def build_messages(messages_data, reference_data)
|
59
|
-
messages_data.
|
60
|
-
end
|
61
|
-
|
62
|
-
def build_message(message_data, reference_data)
|
63
|
-
d = message_data
|
64
|
-
m = Message.new
|
65
|
-
m.id = d['id']
|
66
|
-
m.plain_body = d['body']['plain']
|
67
|
-
m.parsed_body = d['body']['parsed']
|
68
|
-
m.date_created = Time.parse d['created_at']
|
69
|
-
m.like_count = d['liked_by']['count'].to_i
|
70
|
-
m.url = d['web_url']
|
71
|
-
m.sender = build_user d['sender_id'], reference_data
|
72
|
-
m.reply_to_id = d['replied_to_id']
|
73
|
-
m.attachments = d['attachments']
|
74
|
-
m
|
75
|
-
end
|
76
|
-
|
77
|
-
def build_user(user_id, reference_data)
|
78
|
-
d = reference_data.select { |r| r['id'] == user_id }[0]
|
79
|
-
u = User.new
|
80
|
-
u.id = d['id']
|
81
|
-
u.name = d['full_name']
|
82
|
-
u
|
66
|
+
messages_data.select { |m| m['replied_to_id'].nil? }
|
83
67
|
end
|
84
68
|
|
85
69
|
def limit_reached
|
@@ -91,4 +75,4 @@ module YamWow
|
|
91
75
|
end
|
92
76
|
|
93
77
|
end
|
94
|
-
end
|
78
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yamwow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yam
|
16
|
-
requirement: &
|
16
|
+
requirement: &70150410097100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70150410097100
|
25
25
|
description:
|
26
26
|
email: matthew-github@matthewriley.name
|
27
27
|
executables: []
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/yamwow/group.rb
|
36
36
|
- lib/yamwow/group_with_name_request.rb
|
37
37
|
- lib/yamwow/message.rb
|
38
|
+
- lib/yamwow/message_builder.rb
|
38
39
|
- lib/yamwow/messages_with_topic_request.rb
|
39
40
|
- lib/yamwow/praise.rb
|
40
41
|
- lib/yamwow/praise_request.rb
|