class Tweetomator
Constants
- VERSION
Public Class Methods
new(tweetomator_config)
click to toggle source
# File lib/tweetomator.rb, line 16 def initialize(tweetomator_config) if tweetomator_config.valid? somebody_set_us_up_the_bot(tweetomator_config) else raise 'Invalid TweetomatorConfig' end end
Public Instance Methods
run()
click to toggle source
# File lib/tweetomator.rb, line 24 def run begin @scheduler.interval("#{@delay}s") { do_stuff } @scheduler.join rescue retry end end
run_once()
click to toggle source
# File lib/tweetomator.rb, line 33 def run_once do_stuff end
Private Instance Methods
do_stuff()
click to toggle source
# File lib/tweetomator.rb, line 52 def do_stuff r = (1..9).to_a.sample if r < 4 tweet_with_image! elsif r < 7 tweet! else follow! end end
follow!()
click to toggle source
# File lib/tweetomator.rb, line 76 def follow! user = @twitter_client.random_follower_of_random_follower @twitter_client.follow(user) if user end
somebody_set_us_up_the_bot(config)
click to toggle source
# File lib/tweetomator.rb, line 39 def somebody_set_us_up_the_bot(config) @delay = config.delay_in_seconds @twitter_client = TwitterClient.new(config.twitter_config) tweet_finder = TweetFinder.new(@twitter_client, config.topics) flickr_client = FlickrClient.new(config.flickr_config) @flickr_finder = FlickrFindr.new(flickr_client) emoji_finder = EmojiFinder.new composer_class = Object.const_get(config.composer_type) @composer = composer_class.new(config, @twitter_client, tweet_finder, emoji_finder) @downloader = Downloader.new @scheduler = Rufus::Scheduler.new end
tweet!()
click to toggle source
# File lib/tweetomator.rb, line 63 def tweet! tweet = @composer.compose_tweet tweet.post! end
tweet_with_image!()
click to toggle source
# File lib/tweetomator.rb, line 68 def tweet_with_image! tweet = @composer.compose_tweet flickr_query = @composer.compose_image_query(tweet.hashtags.sample) image_uri = @flickr_finder.find(flickr_query) image_local = @downloader.download(image_uri, 'image') tweet.post!(image_local) end