Class: Camptweet::Bot
- Inherits:
-
Object
- Object
- Camptweet::Bot
- Defined in:
- lib/camptweet/bot.rb
Instance Attribute Summary collapse
-
#campfire ⇒ Object
readonly
Returns the value of attribute campfire.
-
#campfire_email ⇒ Object
Returns the value of attribute campfire_email.
-
#campfire_password ⇒ Object
Returns the value of attribute campfire_password.
-
#campfire_room ⇒ Object
Returns the value of attribute campfire_room.
-
#campfire_subdomain ⇒ Object
Returns the value of attribute campfire_subdomain.
-
#campfire_use_ssl ⇒ Object
Returns the value of attribute campfire_use_ssl.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#logfile ⇒ Object
Returns the value of attribute logfile.
-
#room ⇒ Object
readonly
Returns the value of attribute room.
-
#twitter ⇒ Object
readonly
Returns the value of attribute twitter.
-
#twitter_users ⇒ Object
Returns the value of attribute twitter_users.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Bot
constructor
A new instance of Bot.
- #run ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Bot
Returns a new instance of Bot.
14 15 16 17 18 19 20 21 |
# File 'lib/camptweet/bot.rb', line 14 def initialize(&block) yield self if block_given? init_log connect_to_twitter connect_to_campfire login_to_campfire connect_to_campfire_room end |
Instance Attribute Details
#campfire ⇒ Object (readonly)
Returns the value of attribute campfire.
12 13 14 |
# File 'lib/camptweet/bot.rb', line 12 def campfire @campfire end |
#campfire_email ⇒ Object
Returns the value of attribute campfire_email.
8 9 10 |
# File 'lib/camptweet/bot.rb', line 8 def campfire_email @campfire_email end |
#campfire_password ⇒ Object
Returns the value of attribute campfire_password.
9 10 11 |
# File 'lib/camptweet/bot.rb', line 9 def campfire_password @campfire_password end |
#campfire_room ⇒ Object
Returns the value of attribute campfire_room.
7 8 9 |
# File 'lib/camptweet/bot.rb', line 7 def campfire_room @campfire_room end |
#campfire_subdomain ⇒ Object
Returns the value of attribute campfire_subdomain.
5 6 7 |
# File 'lib/camptweet/bot.rb', line 5 def campfire_subdomain @campfire_subdomain end |
#campfire_use_ssl ⇒ Object
Returns the value of attribute campfire_use_ssl.
6 7 8 |
# File 'lib/camptweet/bot.rb', line 6 def campfire_use_ssl @campfire_use_ssl end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
12 13 14 |
# File 'lib/camptweet/bot.rb', line 12 def log @log end |
#logfile ⇒ Object
Returns the value of attribute logfile.
11 12 13 |
# File 'lib/camptweet/bot.rb', line 11 def logfile @logfile end |
#room ⇒ Object (readonly)
Returns the value of attribute room.
12 13 14 |
# File 'lib/camptweet/bot.rb', line 12 def room @room end |
#twitter ⇒ Object (readonly)
Returns the value of attribute twitter.
12 13 14 |
# File 'lib/camptweet/bot.rb', line 12 def twitter @twitter end |
#twitter_users ⇒ Object
Returns the value of attribute twitter_users.
4 5 6 |
# File 'lib/camptweet/bot.rb', line 4 def twitter_users @twitter_users end |
#verbose ⇒ Object
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/camptweet/bot.rb', line 10 def verbose @verbose end |
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/camptweet/bot.rb', line 23 def run last_statuses = initial_statuses loop do begin new_statuses = [] checking_twitter_timelines do |user, status| if last_statuses[user].nil? # Only broadcast this tweet if we have an initial status against # which we can compare it. last_statuses[user] = status elsif status.created_at > last_statuses[user].created_at # Only consider the most recent tweet. new_statuses << status last_statuses[user] = status end end new_statuses.sort_by(&:created_at).each do |status| begin = "[#{status.user.name}] #{status.text}" log.info room.speak log.debug "(Campfire updated)" rescue Timeout::Error => e log.info "Campfire timeout: (#{e.message})" ensure sleep 2 end end rescue => e log.error e. log.error e.backtrace # re-establish potentially lost connection to Twitter connect_to_twitter end log.debug "Sleeping (10s)" sleep 10 end end |