retrobot 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a83f05838bf270e208f5e779ccbcd3d0ce814e9
4
- data.tar.gz: d8cb968b4d3de7c7caba534574f5ebe5e2f0a71f
3
+ metadata.gz: 237d796585e44c76de0301958af7802d5e85d7de
4
+ data.tar.gz: 2607e0dd0b57a3089a79c20e450a04235c91746b
5
5
  SHA512:
6
- metadata.gz: ca4e4c5d47268cea152c90334ca1fba6c858f3cb279a98b60ea80db948fde6636c044e79d33e308c5b91033ac227497d60812b1c5fc3550c8c6ee5025de8c68a
7
- data.tar.gz: 2ca8bc2190c7a44493f51523b3aa1c8980e2bad419fd629e3e2f3dc2c378a4a77914e3ce9d3058ac34559cb8f992e3e867d4be485212a8591b319d2f477a0d56
6
+ metadata.gz: bef0efecc73f63232c9ae1863bde8b06285ac23c2e290a3d8bc0096cd5780b9b1de6429fc411802260922b2d5d0256c80bccbb357e461c1c5fc6377559f986d1
7
+ data.tar.gz: 862bcafae52911b466c828dbca9f684fe839b8c747556e6f2c9bc86c55cf2616af5714bd8fff32c26a412084d990c60b2c93ba2e3e9ea34f332dcdfe19b994cd
@@ -1,4 +1,8 @@
1
1
  # ChangeLog
2
+ ## 0.3.1
3
+ - Add `suppress_pattern` option
4
+ - https://github.com/mirakui/retrobot/pull/9
5
+
2
6
  ## 0.3.0
3
7
  - Add `add_in_reply_to` option (Thanks @studio3104)
4
8
  - https://github.com/mirakui/retrobot/pull/7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retrobot (0.3.0)
4
+ retrobot (0.3.1)
5
5
  activesupport (~> 4.0)
6
6
  daemons
7
7
  get-twitter-oauth-token
@@ -97,6 +97,7 @@ class Retrobot
97
97
  return @tweet_filters if @tweet_filters
98
98
  @tweet_filters = []
99
99
  @tweet_filters << TweetFilters::RetroDays.new(self)
100
+ @tweet_filters << TweetFilters::SuppressPattern.new(self) if @config.suppress_pattern
100
101
  @tweet_filters << TweetFilters::AddInReplyToUrl.new(self) if @config.add_in_reply_to_url
101
102
  @tweet_filters << TweetFilters::Retweet.new(self)
102
103
  @tweet_filters << TweetFilters::RemoveAtmark.new(self)
@@ -18,6 +18,7 @@ class Retrobot
18
18
  retry_interval
19
19
  retry_count
20
20
  add_in_reply_to_url
21
+ suppress_pattern
21
22
  )
22
23
 
23
24
  DEFAULTS = {
@@ -29,7 +30,8 @@ class Retrobot
29
30
  loop_interval: 3,
30
31
  retry_interval: 3,
31
32
  retry_count: 5,
32
- add_in_reply_to_url: false
33
+ add_in_reply_to_url: false,
34
+ suppress_pattern: nil,
33
35
  }
34
36
 
35
37
  def initialize(options={})
@@ -5,6 +5,7 @@ require 'retrobot/tweet_filters/retweet'
5
5
  require 'retrobot/tweet_filters/tweet'
6
6
  require 'retrobot/tweet_filters/unescape'
7
7
  require 'retrobot/tweet_filters/add_in_reply_to_url'
8
+ require 'retrobot/tweet_filters/suppress_pattern'
8
9
 
9
10
  class Retrobot
10
11
  module TweetFilters
@@ -0,0 +1,30 @@
1
+ require 'retrobot/tweet_filters/base'
2
+
3
+ class Retrobot
4
+ module TweetFilters
5
+ class SuppressPattern < Base
6
+ def initialize(retrobot)
7
+ super
8
+ end
9
+
10
+ def filter(tweet)
11
+ text = text tweet
12
+ if pattern && text =~ pattern
13
+ logger.info "Skipped by suppress_pattern: #{tweet.text}"
14
+ nil
15
+ else
16
+ tweet
17
+ end
18
+ end
19
+
20
+ private
21
+ def pattern
22
+ config.suppress_pattern ? Regexp.new(config.suppress_pattern) : nil
23
+ end
24
+
25
+ def text(tweet)
26
+ tweet.retweeted_status_id ? tweet.text.sub(/^RT @.+: /, '') : tweet.text
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  class Retrobot
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -8,3 +8,4 @@ access_secret: your_access_secret
8
8
  # debug: false (default)
9
9
  # dryrun: false (default)
10
10
  # add_in_reply_to_url: false (default=false / add url of in_reply_to into the tweet)
11
+ # suppress_pattern: '@\w+' (default=nil / regular expression for tweet text which you don't need to tweet)
@@ -142,4 +142,66 @@ describe Retrobot::TweetFilters do
142
142
  expect(retrobot.client).to have_received(:update).with('hello')
143
143
  end
144
144
  end
145
+
146
+ describe 'SuppressPattern' do
147
+ let(:filter_class) { Retrobot::TweetFilters::SuppressPattern }
148
+
149
+ context 'suppress_pattern == nil' do
150
+ it 'does nothing' do
151
+ tweet_before = Retrobot::Tweet.new.tap do |t|
152
+ t.text = 'hello'
153
+ end
154
+ tweet_after = filter.filter(tweet_before)
155
+ expect(tweet_after).to be(tweet_after)
156
+ end
157
+ end
158
+
159
+ context 'suppress_pattern is a regexp' do
160
+ let(:config) { Retrobot::Config.new suppress_pattern: '^@mirakui' }
161
+
162
+ describe 'does not match text' do
163
+ it 'does nothing' do
164
+ tweet_before = Retrobot::Tweet.new.tap do |t|
165
+ t.text = 'hello'
166
+ end
167
+ tweet_after = filter.filter(tweet_before)
168
+ expect(tweet_after).to be(tweet_after)
169
+ end
170
+ end
171
+
172
+ describe 'matches text' do
173
+ it 'skips' do
174
+ tweet_before = Retrobot::Tweet.new.tap do |t|
175
+ t.text = '@mirakui hello'
176
+ end
177
+ tweet_after = filter.filter(tweet_before)
178
+ expect(tweet_after).to be(nil)
179
+ end
180
+ end
181
+
182
+ context 'RT text' do
183
+ describe 'does not match text' do
184
+ it 'skips' do
185
+ tweet_before = Retrobot::Tweet.new.tap do |t|
186
+ t.retweeted_status_id = 12345
187
+ t.text = 'RT @mirakui: hello'
188
+ end
189
+ tweet_after = filter.filter(tweet_before)
190
+ expect(tweet_after).to be(tweet_after)
191
+ end
192
+ end
193
+
194
+ describe 'matches text' do
195
+ it 'skips' do
196
+ tweet_before = Retrobot::Tweet.new.tap do |t|
197
+ t.retweeted_status_id = 12345
198
+ t.text = 'RT @mirakui: @mirakui hello'
199
+ end
200
+ tweet_after = filter.filter(tweet_before)
201
+ expect(tweet_after).to be(nil)
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
145
207
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retrobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Issei Naruta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter
@@ -138,6 +138,7 @@ files:
138
138
  - lib/retrobot/tweet_filters/remove_atmark.rb
139
139
  - lib/retrobot/tweet_filters/retro_days.rb
140
140
  - lib/retrobot/tweet_filters/retweet.rb
141
+ - lib/retrobot/tweet_filters/suppress_pattern.rb
141
142
  - lib/retrobot/tweet_filters/tweet.rb
142
143
  - lib/retrobot/tweet_filters/unescape.rb
143
144
  - lib/retrobot/version.rb