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.
-
#feed_urls ⇒ Object
Returns the value of attribute feed_urls.
-
#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_search_terms ⇒ Object
Returns the value of attribute twitter_search_terms.
-
#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.
16 17 18 19 20 21 22 23 24 |
# File 'lib/camptweet/bot.rb', line 16 def initialize(&block) yield self if block_given? init_log add_twitter_search_urls_to_feed_urls 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.
14 15 16 |
# File 'lib/camptweet/bot.rb', line 14 def campfire @campfire end |
#campfire_email ⇒ Object
Returns the value of attribute campfire_email.
10 11 12 |
# File 'lib/camptweet/bot.rb', line 10 def campfire_email @campfire_email end |
#campfire_password ⇒ Object
Returns the value of attribute campfire_password.
11 12 13 |
# File 'lib/camptweet/bot.rb', line 11 def campfire_password @campfire_password end |
#campfire_room ⇒ Object
Returns the value of attribute campfire_room.
9 10 11 |
# File 'lib/camptweet/bot.rb', line 9 def campfire_room @campfire_room end |
#campfire_subdomain ⇒ Object
Returns the value of attribute campfire_subdomain.
7 8 9 |
# File 'lib/camptweet/bot.rb', line 7 def campfire_subdomain @campfire_subdomain end |
#campfire_use_ssl ⇒ Object
Returns the value of attribute campfire_use_ssl.
8 9 10 |
# File 'lib/camptweet/bot.rb', line 8 def campfire_use_ssl @campfire_use_ssl end |
#feed_urls ⇒ Object
Returns the value of attribute feed_urls.
6 7 8 |
# File 'lib/camptweet/bot.rb', line 6 def feed_urls @feed_urls end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
14 15 16 |
# File 'lib/camptweet/bot.rb', line 14 def log @log end |
#logfile ⇒ Object
Returns the value of attribute logfile.
13 14 15 |
# File 'lib/camptweet/bot.rb', line 13 def logfile @logfile end |
#room ⇒ Object (readonly)
Returns the value of attribute room.
14 15 16 |
# File 'lib/camptweet/bot.rb', line 14 def room @room end |
#twitter ⇒ Object (readonly)
Returns the value of attribute twitter.
14 15 16 |
# File 'lib/camptweet/bot.rb', line 14 def twitter @twitter end |
#twitter_search_terms ⇒ Object
Returns the value of attribute twitter_search_terms.
5 6 7 |
# File 'lib/camptweet/bot.rb', line 5 def twitter_search_terms @twitter_search_terms 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.
12 13 14 |
# File 'lib/camptweet/bot.rb', line 12 def verbose @verbose end |
Instance Method Details
#run ⇒ Object
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/camptweet/bot.rb', line 26 def run last_statuses = {} last_feed_items = {} polling_interval = twitter_users.empty? ? 30 : min_unthrottled_interval log.info "Polling interval: #{polling_interval}s" loop do begin new_statuses = [] new_feed_items = [] # check for updated tweets checking_twitter_timelines do |user, status| if last_statuses[user].nil? last_statuses[user] = status elsif status.created_at > last_statuses[user].created_at new_statuses << status last_statuses[user] = status end end # post any updated tweets to campfire new_statuses.sort_by(&:created_at).each do |status| begin "[#{status.user.name}] #{status.text}" rescue Timeout::Error => e log.info "Campfire timeout: (#{e.})" ensure sleep 1 end end # check for updated rss feed items and post them to campfire checking_feeds do |feed_url, feed, item| log.debug "...checking last_feed_item for this feed: #{last_feed_items[feed_url].blank? ? 'no item' : last_feed_items[feed_url].title}" if last_feed_items[feed_url].blank? last_feed_items[feed_url] = item elsif (item) > (last_feed_items[feed_url]) last_feed_items[feed_url] = item (feed, item) 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 (#{polling_interval}s)" sleep polling_interval end end |