ruboty-twitter_search 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a101873c2cb41d5d728cf61262f77bf2a5e3d890
4
- data.tar.gz: c29ce2d0503b71933e1e92edcdc549684afebb8f
3
+ metadata.gz: 6dafb7c3ce9a43df3af927996161b0f3066a5093
4
+ data.tar.gz: 6fa1ce3cfdfedafd532e6770538f90fb6d10d69d
5
5
  SHA512:
6
- metadata.gz: 9725086905c97364564ffda709cb6ef96827771755e5b4e597d45d5efac9c8f46c3e5a403e7fe7803656142730cc1581914354dd244dbe738a010cffc4b43190
7
- data.tar.gz: 239e4ae74c634f5fa15653e977f69f766cfeb2768a8b3112d867428014e989c7ac79ce6f0b2f26c7da17403cb71f65db809649201a4e752bb3de42fd45aefde3
6
+ metadata.gz: 2565ba3f48da594fc444f824a5358a311580cdb57a451d48deaa4eedb77cdefd4add5311d531fb4ca53b7158d185566b4021afcf285a122463ad141641b15559
7
+ data.tar.gz: 0ebe3c100527a1e29d937c55b15bed367125d0af8cfdf2c0d1c3d2a5c8a60c7ac5c1158d8e6208366af08342b8e5294c1c7d83496301dc1ab49d38b6fd539025
@@ -1,3 +1,8 @@
1
+ ## 0.1.1
2
+ - Separate class files from handler's inner classes
3
+ - Support combination use with ruboty-twitter
4
+ - Fix since_id on filtered result
5
+
1
6
  ## 0.1.0
2
7
  - Support search filter query (Thx @gong023)
3
8
 
@@ -1,4 +1,6 @@
1
1
  require "ruboty"
2
+ require "ruboty/twitter_search/query"
3
+ require "ruboty/twitter_search/statuses_view"
2
4
  require "twitter"
3
5
 
4
6
  module Ruboty
@@ -21,7 +23,7 @@ module Ruboty
21
23
 
22
24
  # @return [true] to prevent running missing handlers.
23
25
  def search(message)
24
- query = Query.new(message[:query])
26
+ query = Ruboty::TwitterSearch::Query.new(message[:query])
25
27
 
26
28
  statuses = client.search(
27
29
  query.query_string,
@@ -29,6 +31,8 @@ module Ruboty
29
31
  since_id: fetch_since_id_for(message[:query]),
30
32
  ).take(TWEETS_COUNT)
31
33
 
34
+ since_id = statuses.first.id
35
+
32
36
  statuses.select! do |status|
33
37
  status.retweet_count >= query.minimum_retweet_count
34
38
  end
@@ -38,10 +42,10 @@ module Ruboty
38
42
  end
39
43
 
40
44
  if statuses.any?
41
- message.reply(StatusesView.new(statuses).to_s)
42
- store_since_id(query: message[:query], since_id: statuses.first.id)
45
+ message.reply(Ruboty::TwitterSearch::StatusesView.new(statuses).to_s)
46
+ store_since_id(query: message[:query], since_id: since_id)
43
47
  end
44
- rescue Twitter::Error => exception
48
+ rescue ::Twitter::Error => exception
45
49
  message.reply("#{exception.class}: #{exception}")
46
50
  ensure
47
51
  return true
@@ -80,120 +84,6 @@ module Ruboty
80
84
  store[query] = since_id
81
85
  end
82
86
  end
83
-
84
- class Query
85
- DEFAULT_MINIMUM_FAVORITE_COUNT = 0
86
- DEFAULT_MINIMUM_RETWEET_COUNT = 0
87
-
88
- # @param [String] original_query_string
89
- def initialize(original_query_string)
90
- @original_query_string = original_query_string
91
- end
92
-
93
- # @return [Fixnum]
94
- def minimum_favorite_count
95
- if token = tokens.find(&:favorite_count_filter?)
96
- token.favorite_count
97
- else
98
- DEFAULT_MINIMUM_FAVORITE_COUNT
99
- end
100
- end
101
-
102
- # @return [Fixnum]
103
- def minimum_retweet_count
104
- if token = tokens.find(&:retweet_count_filter?)
105
- token.retweet_count
106
- else
107
- DEFAULT_MINIMUM_RETWEET_COUNT
108
- end
109
- end
110
-
111
- # @return [String]
112
- def query_string
113
- tokens.reject(&:filter?).join(" ")
114
- end
115
-
116
- # @return [String, nil]
117
- def result_type
118
- if token = tokens.find(&:result_type_filter?)
119
- token.result_type
120
- end
121
- end
122
-
123
- private
124
-
125
- # @return [Array<Ruboty::Handlers::TwitterSearch::Token>]
126
- def tokens
127
- @tokens ||= @original_query_string.split.map do |token_string|
128
- Token.new(token_string)
129
- end
130
- end
131
- end
132
-
133
- class StatusesView
134
- def initialize(statuses)
135
- @statuses = statuses
136
- end
137
-
138
- def to_s
139
- source_urls.reverse.join("\n")
140
- end
141
-
142
- private
143
-
144
- def source_urls
145
- @statuses.map do |status|
146
- "https://twitter.com/#{status.user.screen_name}/status/#{status.id}"
147
- end
148
- end
149
- end
150
-
151
- class Token
152
- def initialize(token_string)
153
- @token_string = token_string
154
- end
155
-
156
- # @return [Fixnum, nil]
157
- def favorite_count
158
- if @token_string.match(/\Afav:(?<count>\d+)\z/)
159
- Regexp.last_match(:count).to_i
160
- end
161
- end
162
-
163
- def favorite_count_filter?
164
- !favorite_count.nil?
165
- end
166
-
167
- def filter?
168
- favorite_count_filter? || result_type_filter? || retweet_count_filter?
169
- end
170
-
171
- # @return [String, nil]
172
- def result_type
173
- if @token_string.match(/\Aresult_type:(?<type>\w+)\z/)
174
- Regexp.last_match(:type)
175
- end
176
- end
177
-
178
- def result_type_filter?
179
- !result_type.nil?
180
- end
181
-
182
- # @return [Fixnum, nil]
183
- def retweet_count
184
- if @token_string.match(/\Aretweet:(?<count>\d+)\z/)
185
- Regexp.last_match(:count).to_i
186
- end
187
- end
188
-
189
- def retweet_count_filter?
190
- !retweet_count.nil?
191
- end
192
-
193
- def to_s
194
- @token_string
195
- end
196
- end
197
87
  end
198
88
  end
199
89
  end
@@ -0,0 +1,54 @@
1
+ require "ruboty/twitter_search/token"
2
+
3
+ module Ruboty
4
+ module TwitterSearch
5
+ class Query
6
+ DEFAULT_MINIMUM_FAVORITE_COUNT = 0
7
+ DEFAULT_MINIMUM_RETWEET_COUNT = 0
8
+
9
+ # @param [String] original_query_string
10
+ def initialize(original_query_string)
11
+ @original_query_string = original_query_string
12
+ end
13
+
14
+ # @return [Fixnum]
15
+ def minimum_favorite_count
16
+ if token = tokens.find(&:favorite_count_filter?)
17
+ token.favorite_count
18
+ else
19
+ DEFAULT_MINIMUM_FAVORITE_COUNT
20
+ end
21
+ end
22
+
23
+ # @return [Fixnum]
24
+ def minimum_retweet_count
25
+ if token = tokens.find(&:retweet_count_filter?)
26
+ token.retweet_count
27
+ else
28
+ DEFAULT_MINIMUM_RETWEET_COUNT
29
+ end
30
+ end
31
+
32
+ # @return [String]
33
+ def query_string
34
+ tokens.reject(&:filter?).join(" ")
35
+ end
36
+
37
+ # @return [String, nil]
38
+ def result_type
39
+ if token = tokens.find(&:result_type_filter?)
40
+ token.result_type
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ # @return [Array<Ruboty::Handlers::TwitterSearch::Token>]
47
+ def tokens
48
+ @tokens ||= @original_query_string.split.map do |token_string|
49
+ Token.new(token_string)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ module Ruboty
2
+ module TwitterSearch
3
+ class StatusesView
4
+ def initialize(statuses)
5
+ @statuses = statuses
6
+ end
7
+
8
+ def to_s
9
+ source_urls.reverse.join("\n")
10
+ end
11
+
12
+ private
13
+
14
+ def source_urls
15
+ @statuses.map do |status|
16
+ "https://twitter.com/#{status.user.screen_name}/status/#{status.id}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ module Ruboty
2
+ module TwitterSearch
3
+ class Token
4
+ def initialize(token_string)
5
+ @token_string = token_string
6
+ end
7
+
8
+ # @return [Fixnum, nil]
9
+ def favorite_count
10
+ if @token_string.match(/\Afav:(?<count>\d+)\z/)
11
+ Regexp.last_match(:count).to_i
12
+ end
13
+ end
14
+
15
+ def favorite_count_filter?
16
+ !favorite_count.nil?
17
+ end
18
+
19
+ def filter?
20
+ favorite_count_filter? || result_type_filter? || retweet_count_filter?
21
+ end
22
+
23
+ # @return [String, nil]
24
+ def result_type
25
+ if @token_string.match(/\Aresult_type:(?<type>\w+)\z/)
26
+ Regexp.last_match(:type)
27
+ end
28
+ end
29
+
30
+ def result_type_filter?
31
+ !result_type.nil?
32
+ end
33
+
34
+ # @return [Fixnum, nil]
35
+ def retweet_count
36
+ if @token_string.match(/\Aretweet:(?<count>\d+)\z/)
37
+ Regexp.last_match(:count).to_i
38
+ end
39
+ end
40
+
41
+ def retweet_count_filter?
42
+ !retweet_count.nil?
43
+ end
44
+
45
+ def to_s
46
+ @token_string
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module TwitterSearch
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- RSpec.describe Ruboty::Handlers::TwitterSearch::Query do
1
+ RSpec.describe Ruboty::TwitterSearch::Query do
2
2
  let(:query) do
3
3
  described_class.new(original_string)
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-twitter_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -112,9 +112,12 @@ files:
112
112
  - Rakefile
113
113
  - lib/ruboty/handlers/twitter_search.rb
114
114
  - lib/ruboty/twitter_search.rb
115
+ - lib/ruboty/twitter_search/query.rb
116
+ - lib/ruboty/twitter_search/statuses_view.rb
117
+ - lib/ruboty/twitter_search/token.rb
115
118
  - lib/ruboty/twitter_search/version.rb
116
119
  - ruboty-twitter_search.gemspec
117
- - spec/ruboty/handlers/twitter_search/query_spec.rb
120
+ - spec/ruboty/twitter_search/query_spec.rb
118
121
  - spec/spec_helper.rb
119
122
  homepage: https://github.com/r7kamura/ruboty-twitter_search
120
123
  licenses:
@@ -141,6 +144,6 @@ signing_key:
141
144
  specification_version: 4
142
145
  summary: Ruboty plug-in to search twitter.
143
146
  test_files:
144
- - spec/ruboty/handlers/twitter_search/query_spec.rb
147
+ - spec/ruboty/twitter_search/query_spec.rb
145
148
  - spec/spec_helper.rb
146
149
  has_rdoc: