retrobot 0.3.2 → 0.3.3

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: 36483df2d5483d39cb99a144af509657a19bee92
4
- data.tar.gz: acc2cf7d3ed70ad460fd189d6b12aff67f3ad7fa
3
+ metadata.gz: a07ffd05e9636227ff02974c5fec321e325e8074
4
+ data.tar.gz: 283059383b9df7552d2f0707300b9ae86ca66090
5
5
  SHA512:
6
- metadata.gz: 032fe2499a535e62b0af01b792bf2e7c9a48fc72475dc98f603095b4dc87b519c3e3cdaa38d4a83ee8bb93bdfa8343700ce11213619faa8b26dcd8cae9056b3c
7
- data.tar.gz: 5c855645ebe133640bd96fa87e8624995676ced98ee16d1a24ca37fd4d8f0d3c893f7a7aec56bb55a091ffef272867928800aa3aa29a2f6fdd1fced8fb3913d6
6
+ metadata.gz: ce0c93e370528b6d1af9c209e576b09eebc74d0584c909106b38b54956cdf24feaccc3c73b4d4c4e9904ba37643731b656b45f938d01c4c96a08a1b8b32ceeb1
7
+ data.tar.gz: e12385d0b8efc843ecc2a4ed5261218bfd562d6ad99c07ad394b11e0dddaf96039f8e4e88c3dd1ec974f518409845cf8dc16c94c2fff6dabd53a2ef0a9f5df65
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ tmp/
5
5
  pkg/
6
6
  .bundle
7
7
  retrobot.yml
8
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1.1
4
+ - 2.1.4
5
+ - 2.2.0
5
6
  script: 'bundle exec rspec spec'
data/ChangeLog.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # ChangeLog
2
+ ## 0.3.3
3
+ - Add dying_message feature and `dying_mention_to` option (Thanks @sonots)
4
+ - Bug fix: error with retryable-2.0.0 (Thanks @hansode)
5
+
2
6
  ## 0.3.2
3
7
  - Add `remove_hashtag` option (Thanks @kenjiskywalker)
4
8
  - https://github.com/mirakui/retrobot/pull/10
data/lib/retrobot.rb CHANGED
@@ -61,20 +61,43 @@ class Retrobot
61
61
  break;
62
62
  end
63
63
  end
64
- csv.slice! last_index..-1
65
- logger.info "Next update: \"#{csv.last[5]}\" at #{@config.retro_days.since(Time.parse(csv.last[3]))}"
64
+ csv.slice! last_index..-1 if last_index
65
+ if csv.empty?
66
+ logger.fatal "No data is left. Please update the tweets.csv"
67
+ false
68
+ else
69
+ logger.info "Next update: \"#{csv.last[5]}\" at #{@config.retro_days.since(Time.parse(csv.last[3]))}"
70
+ true
71
+ end
66
72
  end
67
73
 
68
74
  def tweet_loop
69
75
  logger.info 'start'
70
76
  loop do
71
77
  line = csv.last
78
+ unless line
79
+ dying_message
80
+ return false
81
+ end
72
82
  if process_line(line)
73
83
  csv.pop
74
84
  end
75
85
  sleep @config.loop_interval
76
86
  logger.debug '.'
77
87
  end
88
+ true
89
+ end
90
+
91
+ def dying_message
92
+ message = "No data is left. Please update my tweets.csv. Pee.. Gaa..."
93
+ tweet_text = if mention = @config.dying_mention_to
94
+ "#{mention} #{message}"
95
+ else
96
+ message
97
+ end
98
+ twitter = TweetFilters::Tweet.new(self)
99
+ twitter.tweet(tweet_text)
100
+ logger.fatal message
78
101
  end
79
102
 
80
103
  def process_line(line)
@@ -139,8 +162,8 @@ class Retrobot
139
162
 
140
163
  def main
141
164
  init_configuration
142
- init_csv
143
- tweet_loop
165
+ exit 1 unless init_csv
166
+ exit 1 unless tweet_loop
144
167
  end
145
168
 
146
169
  private
@@ -20,6 +20,7 @@ class Retrobot
20
20
  add_in_reply_to_url
21
21
  suppress_pattern
22
22
  remove_hashtag
23
+ dying_mention_to
23
24
  )
24
25
 
25
26
  DEFAULTS = {
@@ -34,6 +35,7 @@ class Retrobot
34
35
  add_in_reply_to_url: false,
35
36
  suppress_pattern: nil,
36
37
  remove_hashtag: false,
38
+ dying_mention_to: nil,
37
39
  }
38
40
 
39
41
  def initialize(options={})
@@ -60,6 +62,13 @@ class Retrobot
60
62
  def retry_interval; @options[:retry_interval].to_i; end
61
63
  def retry_count; @options[:retry_count].to_i; end
62
64
 
65
+ def dying_mention_to
66
+ return nil unless @options[:dying_mention_to]
67
+ # add mention mark (atmark)
68
+ @options[:dying_mention_to].start_with?('@') ?
69
+ @options[:dying_mention_to] : "@" + @options[:dying_mention_to]
70
+ end
71
+
63
72
  def load_yaml_file!(path)
64
73
  @options.merge! Psych.load_file(path.to_s).symbolize_keys
65
74
  end
@@ -25,7 +25,7 @@ class Retrobot
25
25
  def retweet(status_id, text=nil)
26
26
  logger.info "retweet: #{status_id} \"#{text}\""
27
27
  return if config.dryrun
28
- retryable(tries: config.retry_count, sleep: config.retry_interval) do
28
+ Retryable.retryable(tries: config.retry_count, sleep: config.retry_interval) do
29
29
  client.retweet status_id
30
30
  end
31
31
  end
@@ -12,11 +12,10 @@ class Retrobot
12
12
  tweet tweet.text
13
13
  end
14
14
 
15
- private
16
15
  def tweet(text)
17
16
  logger.info "tweet: #{text}"
18
17
  return if config.dryrun
19
- retryable(tries: config.retry_count, sleep: config.retry_interval) do
18
+ Retryable.retryable(tries: config.retry_count, sleep: config.retry_interval) do
20
19
  client.update text
21
20
  end
22
21
  end
@@ -1,3 +1,3 @@
1
1
  class Retrobot
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
data/retrobot.example.yml CHANGED
@@ -10,3 +10,4 @@ access_secret: your_access_secret
10
10
  # add_in_reply_to_url: false (default=false / add url of in_reply_to into the tweet)
11
11
  # remove_hashtag: false (default=false / remove hashtag the tweet)
12
12
  # suppress_pattern: '@\w+' (default=nil / regular expression for tweet text which you don't need to tweet)
13
+ # dying_mention_to: '@mirakui' (default=nil / send dying message as mention to this person if tweets.csv doesn't have tweets anymore)
@@ -88,5 +88,20 @@ describe Retrobot do
88
88
  end
89
89
  end
90
90
  end
91
+
92
+ context "no data left" do
93
+ before do
94
+ allow(retrobot).to receive(:csv).and_return([]) # empty
95
+ end
96
+
97
+ it 'shoud exit if no data left on starting up' do
98
+ expect(retrobot.init_csv).to be false
99
+ end
100
+
101
+ it 'should tweet a dying message and exit if no data left on tweet_loop' do
102
+ expect(client).to receive(:update)
103
+ expect(retrobot.tweet_loop).to be false
104
+ end
105
+ end
91
106
  end
92
107
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.raise_errors_for_deprecations!
9
9
  config.run_all_when_everything_filtered = true
10
10
  config.filter_run :focus
11
11
 
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.2
4
+ version: 0.3.3
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-10-06 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter
@@ -123,7 +123,6 @@ files:
123
123
  - ".travis.yml"
124
124
  - ChangeLog.md
125
125
  - Gemfile
126
- - Gemfile.lock
127
126
  - LICENSE.txt
128
127
  - README.md
129
128
  - Rakefile
@@ -169,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
168
  version: '0'
170
169
  requirements: []
171
170
  rubyforge_project:
172
- rubygems_version: 2.2.2
171
+ rubygems_version: 2.4.5
173
172
  signing_key:
174
173
  specification_version: 4
175
174
  summary: 'Retrobot tweets a word that you''ve tweeted just 1 year ago. (example: @mirakui_retro)'
data/Gemfile.lock DELETED
@@ -1,72 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- retrobot (0.3.1)
5
- activesupport (~> 4.0)
6
- daemons
7
- get-twitter-oauth-token
8
- retryable
9
- twitter (~> 5.8)
10
-
11
- GEM
12
- remote: https://rubygems.org/
13
- specs:
14
- activesupport (4.1.1)
15
- i18n (~> 0.6, >= 0.6.9)
16
- json (~> 1.7, >= 1.7.7)
17
- minitest (~> 5.1)
18
- thread_safe (~> 0.1)
19
- tzinfo (~> 1.1)
20
- addressable (2.3.6)
21
- buftok (0.2.0)
22
- daemons (1.1.9)
23
- diff-lcs (1.2.5)
24
- equalizer (0.0.9)
25
- faraday (0.9.0)
26
- multipart-post (>= 1.2, < 3)
27
- get-twitter-oauth-token (1.1.0)
28
- oauth
29
- http (0.6.1)
30
- http_parser.rb (~> 0.6.0)
31
- http_parser.rb (0.6.0)
32
- i18n (0.6.9)
33
- json (1.8.1)
34
- memoizable (0.4.2)
35
- thread_safe (~> 0.3, >= 0.3.1)
36
- minitest (5.3.4)
37
- multipart-post (2.0.0)
38
- naught (1.0.0)
39
- oauth (0.4.7)
40
- retryable (1.3.5)
41
- rspec (2.99.0)
42
- rspec-core (~> 2.99.0)
43
- rspec-expectations (~> 2.99.0)
44
- rspec-mocks (~> 2.99.0)
45
- rspec-core (2.99.0)
46
- rspec-expectations (2.99.0)
47
- diff-lcs (>= 1.1.3, < 2.0)
48
- rspec-mocks (2.99.1)
49
- simple_oauth (0.2.0)
50
- thread_safe (0.3.4)
51
- timecop (0.7.1)
52
- twitter (5.10.0)
53
- addressable (~> 2.3)
54
- buftok (~> 0.2.0)
55
- equalizer (~> 0.0.9)
56
- faraday (~> 0.9.0)
57
- http (~> 0.6.0)
58
- http_parser.rb (~> 0.6.0)
59
- json (~> 1.8)
60
- memoizable (~> 0.4.0)
61
- naught (~> 1.0)
62
- simple_oauth (~> 0.2.0)
63
- tzinfo (1.2.1)
64
- thread_safe (~> 0.1)
65
-
66
- PLATFORMS
67
- ruby
68
-
69
- DEPENDENCIES
70
- retrobot!
71
- rspec (= 2.99)
72
- timecop