class Tweet
Finds tweetable articles, tweets them
Attributes
result[R]
Public Class Methods
anything()
click to toggle source
Find an article to tweet and tweet it
# File lib/wikipedia_twitterbot/tweet.rb, line 7 def self.anything # Randomly tweet either the earlier tweetable Article in the database # or the latest. # Wikipedia increments page ids over time, so the first ids are the oldest # articles and the last ids are the latest. article = if coin_flip Article.last_tweetable else Article.first_tweetable end article.tweet puts "Tweeted #{article.title}" end
coin_flip()
click to toggle source
Helpers #
# File lib/wikipedia_twitterbot/tweet.rb, line 42 def self.coin_flip [true, false][rand(2)] end
new(tweet, opts = {})
click to toggle source
Twitter API #
# File lib/wikipedia_twitterbot/tweet.rb, line 24 def initialize(tweet, opts = {}) if opts[:commons_image] filename = opts.delete(:commons_image) Wiki.save_commons_image filename @result = TwitterClient.new.client.update_with_media(tweet, File.new(filename), opts) File.delete filename elsif opts[:filename] filename = opts.delete(:filename) @result = TwitterClient.new.client.update_with_media(tweet, File.new(filename), opts) else @result = TwitterClient.new.client.update(tweet, opts) end end