Class TwitterFriend
In: app/models/twitter_friend.rb
Parent: ActiveRecord::Base

Methods

Public Class methods

[Source]

    # File app/models/twitter_friend.rb, line 36
36:   def self.befriend_people_tweeting(tweet_term)
37:     unless ['prodution'].include?(RAILS_ENV)
38:       return
39:     end
40:     begin
41:       tweets = Twitter::Search.new(tweet_term)
42:       for tweet in tweets
43:         from_user = tweet.from_user
44:         logger.info("User [#{from_user}] tweeted [#{tweet.text}]")
45:         if 'production' == RAILS_ENV
46:           self.create_or_update_friendship(from_user) unless KotobaAppTwitter.instance.account == from_user
47:         end
48:       end
49:     rescue Exception => exception
50:       logger.error("Unable to search Twitter for term [#{tweet_term}] due to [#{exception.message}]")
51:       logger.error(exception.backtrace.join("  \n"))
52:     end
53:   end

[Source]

    # File app/models/twitter_friend.rb, line 3
 3:   def self.create_or_update_friendship(twitter_account)
 4:     begin
 5:       current_time = Time.now
 6:       twitter_friendship = TwitterFriend.find_by_twitter_account(twitter_account)
 7:       unless twitter_friendship
 8:         twitter_friendship = TwitterFriend.new
 9:         twitter_friendship.twitter_account = twitter_account
10:         twitter_friendship.date_started_following = current_time
11:         twitter_friendship.kotoba_twitter.create_friendship(twitter_account)
12:         logger.info("User [#{twitter_account}] newly befriended")
13:       end
14:       twitter_friendship.date_last_matched_search = current_time
15:       twitter_friendship.save!
16:       logger.info("We have created/updated the friendship with [#{twitter_account}]")
17:     rescue Exception => exception
18:       logger.error("Unable to create/update friendship with [#{twitter_account}] due to [#{exception}]")
19:       self.destroy_friendship(twitter_account)
20:     end
21:   end

[Source]

    # File app/models/twitter_friend.rb, line 23
23:   def self.destroy_friendship(twitter_account)
24:     twitter_friendship = TwitterFriend.find_by_twitter_account(twitter_account)
25:     if twitter_friendship
26:       begin
27:         twitter_friendship.kotoba_twitter.destroy_friendship(twitter_account)
28:         twitter_friendship.destroy
29:         logger.info("We have destroyed the friendship with [#{twitter_account}]")
30:       rescue Exception => exception
31:         logger.error("Unable to destroy friendship with [#{twitter_account}] due to [#{exception}]")
32:       end
33:     end
34:   end

Public Instance methods

[Source]

    # File app/models/twitter_friend.rb, line 55
55:   def kotoba_twitter
56:     KotobaAppTwitter.instance.twitter
57:   end

[Validate]