Class Cron::Twitter
In: lib/cron/twitter.rb
Parent: Object

Overview

This class wraps Kotoba twitter for use by CRON. Call from CRON using script/runner.

Usage

%> $RAILS_ROOT/script/runner lib/cron/twitter.rb

Alternatively, you can pass in the time to the next tweet

%> $RAILS_ROOT/script/runner lib/cron/twitter.rb hours_ago

Methods

Constants

DEFAULT_TIME_IN_HOURS = 24   If nothing is specified for a period of time then we default to something conservative but not unreasonable
DEFAULT_MINIMUM_TIME_IN_HOURS = 5.0/60.0
DEFAULT_MINIMUM_TIME_IN_HOURS = 0.0

Public Class methods

Initialize

Caller can specify the amount of time to to go back for the last tweet. If we find a tweet in this period then we do not tweet

[Source]

    # File lib/cron/twitter.rb, line 36
36:   def initialize(twitter_type, time_in_hours = Cron::Twitter::DEFAULT_TIME_IN_HOURS)
37:     @time_in_hours = time_in_hours
38:     @twitter_type  = twitter_type
39: 
40:     get_twitter
41:     get_last_tweet
42:     
43:     begin
44:       unless less_than_minimum?
45:         raise "Hours too small [#{@time_in_hours}] (must be >= [#{Cron::Twitter::DEFAULT_MINIMUM_TIME_IN_HOURS}])"    
46:       end
47:     rescue => e
48:       puts "  ERROR setting time since last tweet, default to #{Cron::Twitter::DEFAULT_TIME_IN_HOURS} hours [#{e}]"
49:       @time_in_hours = Cron::Twitter::DEFAULT_TIME_IN_HOURS
50:     end
51:     @tweeted_hours_ago = @time_in_hours.hours.ago    
52:   end

Public Instance methods

Find other twitters who tweet about things similar to Kotoba; may be they will start following us

[Source]

    # File lib/cron/twitter.rb, line 70
70:   def find_new_twitter_friends
71:     puts "  Finding some friends!"
72:     @twitter.befriend_people
73:     puts "  Done finding some friends!"    
74:   end

[Source]

    # File lib/cron/twitter.rb, line 54
54:   def tweet
55:     puts "  Presently it is #{Time.now.localtime}"
56:     if @last_tweet
57:       puts "  Last tweeted at #{@last_tweet.created_at.localtime}"
58:     else
59:       puts "  We have never successfully tweeted!"
60:     end
61: 
62:     periodically_tweet
63:     inform_when_we_will_tweet_next
64: 
65:     puts "  Done."  
66:   end

[Validate]