yamwow 0.0.8 → 0.0.9
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/csv_generator.rb +14 -6
- data/lib/yamwow/facade.rb +11 -18
- data/lib/yamwow/group_with_name_request.rb +40 -0
- data/lib/yamwow/{messages_for_topic_request.rb → messages_with_topic_request.rb} +8 -13
- data/lib/yamwow/praise_request.rb +5 -4
- data/lib/yamwow/topic.rb +1 -1
- data/lib/yamwow/topic_with_name_request.rb +36 -0
- data/lib/yamwow/topics_request.rb +8 -14
- data/lib/yamwow.rb +2 -1
- metadata +7 -12
- data/lib/yamwow/group_request.rb +0 -47
- data/lib/yamwow/group_response.rb +0 -11
- data/lib/yamwow/messages_for_topic_response.rb +0 -11
- data/lib/yamwow/praise_response.rb +0 -15
- data/lib/yamwow/topic_request.rb +0 -46
- data/lib/yamwow/topic_response.rb +0 -11
- data/lib/yamwow/topics_response.rb +0 -11
data/lib/yamwow/csv_generator.rb
CHANGED
@@ -3,17 +3,25 @@ require 'csv'
|
|
3
3
|
module YamWow
|
4
4
|
class CsvGenerator
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
attr_accessor :headers
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@headers = nil
|
8
10
|
end
|
9
11
|
|
10
|
-
def generate(
|
12
|
+
def generate(items)
|
11
13
|
CSV.generate do |csv|
|
12
|
-
csv << @
|
13
|
-
|
14
|
-
sorted_messages.each { |p| csv << yield(p) }
|
14
|
+
csv << headers_as_array if @headers
|
15
|
+
items.each { |i| csv << yield(i) }
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
19
|
+
private
|
20
|
+
|
21
|
+
def headers_as_array
|
22
|
+
return unless @headers
|
23
|
+
@headers.kind_of?(Array) ? @headers : @headers.split(',').map { |h| h.strip }
|
24
|
+
end
|
25
|
+
|
18
26
|
end
|
19
27
|
end
|
data/lib/yamwow/facade.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative 'client'
|
2
|
+
Dir[File.expand_path(File.dirname(__FILE__) + '/*_request.rb')].each { |f| require f }
|
3
|
+
|
1
4
|
module YamWow
|
2
5
|
class Facade
|
3
6
|
|
@@ -5,34 +8,24 @@ module YamWow
|
|
5
8
|
@client = Client.new oauth_token
|
6
9
|
end
|
7
10
|
|
8
|
-
def
|
9
|
-
|
10
|
-
response = request.send
|
11
|
-
response.messages
|
11
|
+
def messages_with_topic(topic_name, options={})
|
12
|
+
MessagesWithTopicRequest.new(@client, topic_name, options).send
|
12
13
|
end
|
13
14
|
|
14
15
|
def praises(options={})
|
15
|
-
|
16
|
-
response = request.send
|
17
|
-
response.praises
|
16
|
+
PraiseRequest.new(@client, options).send
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
21
|
-
|
22
|
-
response = request.send
|
23
|
-
response.topic
|
19
|
+
def topic_with_name(topic_name)
|
20
|
+
TopicWithNameRequest.new(@client, topic_name).send
|
24
21
|
end
|
25
22
|
|
26
23
|
def topics
|
27
|
-
|
28
|
-
response = request.send
|
29
|
-
response.topics
|
24
|
+
TopicsRequest.new(@client).send
|
30
25
|
end
|
31
26
|
|
32
|
-
def
|
33
|
-
|
34
|
-
response = request.send
|
35
|
-
response.group
|
27
|
+
def group_with_name(group_name)
|
28
|
+
GroupWithNameRequest.new(@client, group_name).send
|
36
29
|
end
|
37
30
|
|
38
31
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'group'
|
2
|
+
|
3
|
+
module YamWow
|
4
|
+
class GroupWithNameRequest
|
5
|
+
|
6
|
+
def initialize(client, group_name)
|
7
|
+
@client = client
|
8
|
+
@group_name = group_name.downcase.gsub(/[^0-9a-z]/i, '')
|
9
|
+
end
|
10
|
+
|
11
|
+
def send
|
12
|
+
build_group group_data
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def group_data
|
18
|
+
data = send_autocomplete_request
|
19
|
+
groups = data['groups'] || []
|
20
|
+
groups.select { |g| g['name'] == @group_name }.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_autocomplete_request
|
24
|
+
@client.get_autocomplete prefix: autocomplete_prefix
|
25
|
+
end
|
26
|
+
|
27
|
+
def autocomplete_prefix
|
28
|
+
'to:' + @group_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_group(group_data)
|
32
|
+
return unless group_data
|
33
|
+
g = YamWow::Group.new
|
34
|
+
g.id = group_data['id']
|
35
|
+
g.name = group_data['full_name']
|
36
|
+
g
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative 'messages_for_topic_response'
|
1
|
+
require_relative 'topic_with_name_request'
|
3
2
|
require_relative 'message'
|
4
3
|
require_relative 'user'
|
5
4
|
|
6
5
|
module YamWow
|
7
|
-
class
|
6
|
+
class MessagesWithTopicRequest
|
8
7
|
|
9
8
|
def initialize(client, topic_name, options={})
|
10
9
|
@client = client
|
@@ -12,7 +11,6 @@ module YamWow
|
|
12
11
|
@options = options
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
14
|
def send
|
17
15
|
@messages = []
|
18
16
|
loop_finished = false
|
@@ -26,7 +24,8 @@ module YamWow
|
|
26
24
|
loop_finished = no_more_messages || limit_reached
|
27
25
|
end
|
28
26
|
|
29
|
-
|
27
|
+
@messages.sort! { |x, y| y.date_created <=> x.date_created }
|
28
|
+
@messages
|
30
29
|
end
|
31
30
|
|
32
31
|
private
|
@@ -40,10 +39,10 @@ module YamWow
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def get_topic_id
|
43
|
-
request =
|
44
|
-
|
45
|
-
raise "Topic '#{@topic_name}' was not found." unless
|
46
|
-
|
42
|
+
request = TopicWithNameRequest.new @client, @topic_name
|
43
|
+
topic = request.send
|
44
|
+
raise "Topic '#{@topic_name}' was not found." unless topic
|
45
|
+
topic.id
|
47
46
|
end
|
48
47
|
|
49
48
|
def oldest_message_id
|
@@ -91,9 +90,5 @@ module YamWow
|
|
91
90
|
@options[:limit_count] ? @options[:limit_count].to_i : 0
|
92
91
|
end
|
93
92
|
|
94
|
-
def build_response
|
95
|
-
MessagesForTopicResponse.new @messages
|
96
|
-
end
|
97
|
-
|
98
93
|
end
|
99
94
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'messages_with_topic_request'
|
2
|
+
require_relative 'praise'
|
2
3
|
|
3
4
|
module YamWow
|
4
5
|
class PraiseRequest
|
@@ -9,9 +10,9 @@ module YamWow
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def send
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
r = MessagesWithTopicRequest.new @client, 'praise', @options
|
14
|
+
messages = r.send
|
15
|
+
messages.map { |m| Praise.new m }
|
15
16
|
end
|
16
17
|
|
17
18
|
end
|
data/lib/yamwow/topic.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'topic'
|
2
|
+
|
3
|
+
module YamWow
|
4
|
+
class TopicWithNameRequest
|
5
|
+
|
6
|
+
def initialize(client, topic_name)
|
7
|
+
@client = client
|
8
|
+
@topic_name = topic_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def send
|
12
|
+
build_topic topic_data
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def topic_data
|
18
|
+
data = send_autocomplete_request
|
19
|
+
topics = data['topics'] || []
|
20
|
+
topics.select { |t| t['name'].casecmp(@topic_name) == 0 }.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_autocomplete_request
|
24
|
+
@client.get_autocomplete prefix: @topic_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_topic(topic_data)
|
28
|
+
return unless topic_data
|
29
|
+
t = Topic.new
|
30
|
+
t.id = topic_data['id']
|
31
|
+
t.name = topic_data['name']
|
32
|
+
t
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
require_relative 'topic'
|
4
|
-
require_relative 'topics_response'
|
5
2
|
|
6
3
|
module YamWow
|
7
4
|
class TopicsRequest
|
@@ -14,18 +11,20 @@ module YamWow
|
|
14
11
|
@topics = []
|
15
12
|
process_range '0', '9'
|
16
13
|
process_range 'a', 'z'
|
17
|
-
|
14
|
+
@topics.uniq! { |t| t.id }
|
15
|
+
@topics.sort! { |x, y| x.name.downcase <=> y.name.downcase }
|
16
|
+
@topics
|
18
17
|
end
|
19
18
|
|
20
19
|
private
|
21
20
|
|
22
|
-
def process_range(first, last)
|
23
|
-
(first..last).each do |
|
24
|
-
response_data = send_autocomplete_request
|
21
|
+
def process_range(first, last, current=nil)
|
22
|
+
((current.to_s + first)..(current.to_s + last)).each do |prefix|
|
23
|
+
response_data = send_autocomplete_request prefix
|
25
24
|
topics_data = response_data['topics'] || []
|
26
25
|
topics = topics_data.map { |t| build_topic t }
|
27
26
|
@topics += topics
|
28
|
-
process_range
|
27
|
+
process_range first, last, prefix if topics.length == 50
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
@@ -33,16 +32,11 @@ module YamWow
|
|
33
32
|
@client.get_autocomplete prefix: prefix.downcase
|
34
33
|
end
|
35
34
|
|
36
|
-
def build_response
|
37
|
-
topics = @topics.uniq { |t| t.id }
|
38
|
-
topics = topics.sort { |x, y| x.name.downcase <=> y.name.downcase }
|
39
|
-
TopicsResponse.new topics
|
40
|
-
end
|
41
|
-
|
42
35
|
def build_topic(topic_data)
|
43
36
|
t = Topic.new
|
44
37
|
t.id = topic_data['id']
|
45
38
|
t.name = topic_data['name']
|
39
|
+
t.usages = topic_data['applications_count']
|
46
40
|
t
|
47
41
|
end
|
48
42
|
|
data/lib/yamwow.rb
CHANGED
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.9
|
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-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yam
|
16
|
-
requirement: &
|
16
|
+
requirement: &70195163260140 !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: *70195163260140
|
25
25
|
description:
|
26
26
|
email: matthew-github@matthewriley.name
|
27
27
|
executables: []
|
@@ -33,20 +33,15 @@ files:
|
|
33
33
|
- lib/yamwow/csv_generator.rb
|
34
34
|
- lib/yamwow/facade.rb
|
35
35
|
- lib/yamwow/group.rb
|
36
|
-
- lib/yamwow/
|
37
|
-
- lib/yamwow/group_response.rb
|
36
|
+
- lib/yamwow/group_with_name_request.rb
|
38
37
|
- lib/yamwow/message.rb
|
39
|
-
- lib/yamwow/
|
40
|
-
- lib/yamwow/messages_for_topic_response.rb
|
38
|
+
- lib/yamwow/messages_with_topic_request.rb
|
41
39
|
- lib/yamwow/praise.rb
|
42
40
|
- lib/yamwow/praise_request.rb
|
43
|
-
- lib/yamwow/praise_response.rb
|
44
41
|
- lib/yamwow/throttle.rb
|
45
42
|
- lib/yamwow/topic.rb
|
46
|
-
- lib/yamwow/
|
47
|
-
- lib/yamwow/topic_response.rb
|
43
|
+
- lib/yamwow/topic_with_name_request.rb
|
48
44
|
- lib/yamwow/topics_request.rb
|
49
|
-
- lib/yamwow/topics_response.rb
|
50
45
|
- lib/yamwow/user.rb
|
51
46
|
- lib/yamwow.rb
|
52
47
|
homepage: http://rubygems.org/gems/yamwow
|
data/lib/yamwow/group_request.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require_relative 'group'
|
2
|
-
require_relative 'group_response'
|
3
|
-
|
4
|
-
module YamWow
|
5
|
-
class GroupRequest
|
6
|
-
|
7
|
-
def initialize(client, group_name)
|
8
|
-
@client = client
|
9
|
-
@group_name = group_name.gsub /[^0-9a-z]/i, ''
|
10
|
-
end
|
11
|
-
|
12
|
-
def send
|
13
|
-
group_data = get_group_data
|
14
|
-
group_data ? build_response(group_data) : build_empty_response
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def get_group_data
|
20
|
-
data = send_autocomplete_request
|
21
|
-
topics = data['groups'] || []
|
22
|
-
topics.select { |t| t['name'].downcase == @group_name.downcase }[0]
|
23
|
-
end
|
24
|
-
|
25
|
-
def send_autocomplete_request
|
26
|
-
prefix = 'to:' + @group_name.downcase
|
27
|
-
@client.get_autocomplete prefix: prefix
|
28
|
-
end
|
29
|
-
|
30
|
-
def build_empty_response
|
31
|
-
GroupResponse.new nil
|
32
|
-
end
|
33
|
-
|
34
|
-
def build_response(group_data)
|
35
|
-
group = build_group group_data
|
36
|
-
GroupResponse.new group
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_group(group_data)
|
40
|
-
g = YamWow::Group.new
|
41
|
-
g.id = group_data['id']
|
42
|
-
g.name = group_data['full_name']
|
43
|
-
g
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
data/lib/yamwow/topic_request.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require_relative 'topic'
|
2
|
-
require_relative 'topic_response'
|
3
|
-
|
4
|
-
module YamWow
|
5
|
-
class TopicRequest
|
6
|
-
|
7
|
-
def initialize(client, topic_name)
|
8
|
-
@client = client
|
9
|
-
@topic_name = topic_name
|
10
|
-
end
|
11
|
-
|
12
|
-
def send
|
13
|
-
topic_data = get_topic_data
|
14
|
-
topic_data ? build_response(topic_data) : build_empty_response
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def get_topic_data
|
20
|
-
data = send_autocomplete_request
|
21
|
-
topics = data['topics'] || []
|
22
|
-
topics.select { |t| t['name'].downcase == @topic_name.downcase }[0]
|
23
|
-
end
|
24
|
-
|
25
|
-
def send_autocomplete_request
|
26
|
-
@client.get_autocomplete prefix: @topic_name.downcase
|
27
|
-
end
|
28
|
-
|
29
|
-
def build_empty_response
|
30
|
-
TopicResponse.new nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def build_response(topic_data)
|
34
|
-
topic = build_topic topic_data
|
35
|
-
TopicResponse.new topic
|
36
|
-
end
|
37
|
-
|
38
|
-
def build_topic(topic_data)
|
39
|
-
t = Topic.new
|
40
|
-
t.id = topic_data['id']
|
41
|
-
t.name = topic_data['name']
|
42
|
-
t
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|