twitter_topic_bot 0.2.0 → 0.3.0

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: 51f87423398e6dc3297df21d9cee48baf4d37523
4
- data.tar.gz: c76436994c099997a64442345b3265ccdaece364
3
+ metadata.gz: 18bcde73d848ce382fc2455843573ab9398b5684
4
+ data.tar.gz: d30f0c510f82cde515f48925aded164d06a1d246
5
5
  SHA512:
6
- metadata.gz: a2002e5b392461168589db6587b6c4f27ab3c1ee53010659c776151b9506d109ac3f920524b3e3498ae0bb3af044fc1d1dcb43f86806ae77ac8de6564c2e4cab
7
- data.tar.gz: 9d8ba0e9015d8c6a920e8dc030d69fc5b874bbd233fb2883981cae0d246dbfe25946c473835173e82b983dd93a106504f21cb8a497300e1cd5fc57009f1d4fc4
6
+ metadata.gz: fb7109ff79978710b2a586a8e1548706aee2e1c6466cab28a7b40ecf75c458d9e17c9c3b09ba6fb414e3481f46b1b726a5d0060b933b67f81cb2d4a718945b39
7
+ data.tar.gz: 78e88f92d0a7a6d7929947cab163d9c06ac20812afc4714355bd052bbcdc23a001127988331969777415e815fdb7d6a85d1007911cde9029bb8c75f7061f28dd
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # TwitterTopicBot
2
2
 
3
+ [![Gem](https://img.shields.io/gem/v/twitter_topic_bot.svg?style=flat-square)](https://rubygems.org/gems/twitter_topic_bot)
4
+ [![Travis](https://img.shields.io/travis/annejohnson/twitter_topic_bot.svg?style=flat-square)](https://travis-ci.org/annejohnson/twitter_topic_bot)
5
+
3
6
  Create a Twitter bot in 5 minutes that tweets and engages with the community on topics you're interested in!
4
7
 
5
8
  ## Installation
@@ -20,6 +23,8 @@ Or install it yourself as:
20
23
 
21
24
  ## Usage
22
25
 
26
+ ### Telling Your Bot What to Tweet
27
+
23
28
  To let your bot know what to tweet about, you need to make an object that responds to the three methods in the code sample below. The topic below is art, but your topic can be about anything.
24
29
 
25
30
  ```ruby
@@ -40,11 +45,13 @@ end
40
45
  content_preparer = ArtContentPreparer.new
41
46
  ```
42
47
 
48
+ ### Getting Twitter Credentials
49
+
43
50
  Next, get your Twitter API credentials ready. Register an app on [Twitter](https://apps.twitter.com/) with read & write permissions. Once you have your API keys, prepare the following pieces of information:
44
51
 
45
52
  ```ruby
46
53
  credentials = {
47
- username: '<Your bot\'s username (without the @ sign)>',
54
+ username: '<Your bot\'s Twitter username (without the @ sign)>',
48
55
  consumer_key: '<Your consumer key>',
49
56
  consumer_secret: '<Your consumer secret>',
50
57
  access_token: '<Your access token>',
@@ -52,6 +59,8 @@ credentials = {
52
59
  }
53
60
  ```
54
61
 
62
+ ### Making Your Bot Interact with the World
63
+
55
64
  Next, instantiate a `TwitterTopicBot`, and make it do things!
56
65
 
57
66
  ```ruby
@@ -65,6 +74,39 @@ bot.reply_to_someone
65
74
  bot.follow_followers
66
75
  ```
67
76
 
77
+ ### Automating Your Bot's Activities
78
+
79
+ To make your bot run automatically on a schedule, define a schedule for it like so:
80
+
81
+ ```ruby
82
+ bot.schedule do |schedule|
83
+ schedule.every('30m') { bot.tweet }
84
+ schedule.every('3h') { bot.follow_someone }
85
+ schedule.every('1d') { bot.reply_to_someone }
86
+ schedule.cron('15,45 * * * *') { bot.retweet_someone }
87
+ end
88
+ ```
89
+
90
+ View the [Rufus-Scheduler](https://github.com/jmettraux/rufus-scheduler) documentation to see examples of how to configure the schedule.
91
+
92
+ For the schedule take effect over time, you need to keep your process open. You can add the following to your Ruby file to keep the process running indefinitely:
93
+
94
+ ```ruby
95
+ loop { sleep 1 }
96
+ ```
97
+
98
+ ### Launching Your Bot
99
+
100
+ If your Ruby code so far is in a file called `my_bot.rb`, you can launch your bot with the following command in the terminal:
101
+
102
+ ```
103
+ ruby my_bot.rb
104
+ ```
105
+
106
+ ### Example File
107
+
108
+ The code above is available in this [example file](https://github.com/annejohnson/twitter_topic_bot/blob/master/examples/art_topic_bot.rb).
109
+
68
110
  ## Development
69
111
 
70
112
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,36 @@
1
+ require 'twitter_topic_bot'
2
+
3
+ class ArtContentPreparer
4
+ def topic_string
5
+ ['#painting', '#watercolor'].sample
6
+ end
7
+
8
+ def prepare_tweet
9
+ %q{If you hear a voice within you say 'you cannot paint,' then by all means paint, and that voice will be silenced. -Vincent Van Gogh}
10
+ end
11
+
12
+ def prepare_reply(tweet_to_reply_to, user_to_reply_to)
13
+ "@#{user_to_reply_to}, thank you for tweeting about art!"
14
+ end
15
+ end
16
+
17
+ content_preparer = ArtContentPreparer.new
18
+
19
+ credentials = {
20
+ username: '<Your bot\'s Twitter username (without the @ sign)>',
21
+ consumer_key: '<Your consumer key>',
22
+ consumer_secret: '<Your consumer secret>',
23
+ access_token: '<Your access token>',
24
+ access_token_secret: '<Your access token secret>'
25
+ }
26
+
27
+ bot = TwitterTopicBot.new(content_preparer, credentials)
28
+
29
+ bot.schedule do |schedule|
30
+ schedule.every('30m') { bot.tweet }
31
+ schedule.every('3h') { bot.follow_someone }
32
+ schedule.every('1d') { bot.reply_to_someone }
33
+ schedule.cron('15,45 * * * *') { bot.retweet_someone }
34
+ end
35
+
36
+ loop { sleep 1 }
@@ -0,0 +1,15 @@
1
+ require 'rufus-scheduler'
2
+
3
+ class TwitterTopicBot
4
+ module Schedulable
5
+ def schedule
6
+ yield(schedule_object)
7
+ end
8
+
9
+ private
10
+
11
+ def schedule_object
12
+ @schedule_object ||= Rufus::Scheduler.new
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  class TwitterTopicBot
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,9 +1,11 @@
1
- require 'twitter'
2
1
  require 'twitter_topic_bot/version'
3
2
  require 'twitter_topic_bot/api_client'
4
3
  require 'twitter_topic_bot/tweet_filterer'
4
+ require 'twitter_topic_bot/schedulable'
5
5
 
6
6
  class TwitterTopicBot
7
+ include Schedulable
8
+
7
9
  def initialize(content_preparer, credentials)
8
10
  @content_preparer = content_preparer
9
11
  @api_client = TwitterTopicBot::ApiClient.new(credentials)
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_runtime_dependency 'twitter', '~> 5.16.0'
20
+ spec.add_runtime_dependency 'twitter', '~> 5.16', '>= 5.16.0'
21
+ spec.add_runtime_dependency 'rufus-scheduler', '~> 3.2', '>= 3.2.1'
21
22
  spec.add_development_dependency 'bundler', '~> 1.12'
22
23
  spec.add_development_dependency 'rake', '~> 10.0'
23
24
  spec.add_development_dependency 'rspec', '~> 3.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_topic_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anne Johnson
@@ -15,6 +15,9 @@ dependencies:
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.16'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 5.16.0
20
23
  type: :runtime
@@ -22,8 +25,31 @@ dependencies:
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.16'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 5.16.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rufus-scheduler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.2.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.2.1
27
53
  - !ruby/object:Gem::Dependency
28
54
  name: bundler
29
55
  requirement: !ruby/object:Gem::Requirement
@@ -82,8 +108,10 @@ files:
82
108
  - Rakefile
83
109
  - bin/console
84
110
  - bin/setup
111
+ - examples/art_topic_bot.rb
85
112
  - lib/twitter_topic_bot.rb
86
113
  - lib/twitter_topic_bot/api_client.rb
114
+ - lib/twitter_topic_bot/schedulable.rb
87
115
  - lib/twitter_topic_bot/tweet_filterer.rb
88
116
  - lib/twitter_topic_bot/version.rb
89
117
  - twitter_topic_bot.gemspec