class TwitterTopicBot

Constants

VERSION

Attributes

api_client[R]
content_preparer[R]

Public Class Methods

new(content_preparer, credentials) click to toggle source
# File lib/twitter_topic_bot.rb, line 9
def initialize(content_preparer, credentials)
  @content_preparer = content_preparer
  @api_client = TwitterTopicBot::ApiClient.new(credentials)
end

Public Instance Methods

follow_followers() click to toggle source
# File lib/twitter_topic_bot.rb, line 46
def follow_followers
  # TODO: it is too easy to hit the rate limit on this one
  api_client.follow *api_client.followers
end
follow_someone() click to toggle source
# File lib/twitter_topic_bot.rb, line 24
def follow_someone
  api_client.follow(user_to_follow)
end
reply_to_someone() click to toggle source
# File lib/twitter_topic_bot.rb, line 33
def reply_to_someone
  tweet = tweet_to_reply_to
  reply = content_preparer.prepare_reply(
            tweet.text,
            tweet.user.screen_name
          )

  api_client.tweet(
    reply,
    in_reply_to_status_id: tweet.id
  )
end
retweet_mentions() click to toggle source
# File lib/twitter_topic_bot.rb, line 28
def retweet_mentions
  # TODO: filter out already retweeted mentions
  api_client.retweet *api_client.mentions
end
retweet_someone() click to toggle source
# File lib/twitter_topic_bot.rb, line 20
def retweet_someone
  api_client.retweet(tweet_to_retweet)
end
tweet() click to toggle source
# File lib/twitter_topic_bot.rb, line 14
def tweet
  api_client.tweet(
    content_preparer.prepare_tweet
  )
end

Private Instance Methods

get_topic_tweets() click to toggle source
# File lib/twitter_topic_bot.rb, line 72
def get_topic_tweets
  api_client.search_recent_tweets(
    content_preparer.topic_string
  )
end
tweet_to_reply_to() click to toggle source
# File lib/twitter_topic_bot.rb, line 64
def tweet_to_reply_to
  tweet_ids_already_replied_to = api_client.replies.map(&:in_reply_to_status_id)

  get_topic_tweets.reject do |tweet|
    tweet.retweet? || tweet_ids_already_replied_to.include?(tweet.id)
  end.sample
end
tweet_to_retweet() click to toggle source
# File lib/twitter_topic_bot.rb, line 56
def tweet_to_retweet
  get_topic_tweets.max_by(&:favorite_count)
end
user_to_follow() click to toggle source
# File lib/twitter_topic_bot.rb, line 60
def user_to_follow
  get_topic_tweets.sample.user
end