Class KotobaAppTwitter
In: lib/kotoba_app_twitter.rb
Parent: Object

Methods

Included Modules

Singleton

Public Instance methods

[Source]

     # File lib/kotoba_app_twitter.rb, line 136
136:   def account
137:     'kotoba_app'
138:   end

[Source]

    # File lib/kotoba_app_twitter.rb, line 61
61:   def befriend_people
62:       terms = Array.new
63: 
64:       # English terms
65:       terms << 'kotoba'
66:       terms << 'kanji'
67:       terms << 'hiragana'
68:       terms << 'katakana'
69:       terms << 'japanese'
70:       terms << 'vocabulary'
71:       terms << 'dictionary' 
72:       terms << 'wardosworld' 
73:       terms << 'vuillemot'
74:       
75:       # Japanese key terms
76:       terms << 'ことば' 
77:       terms << '言語'
78:       terms << '漢字'
79:       terms << 'ひらがな'
80:       terms << 'かたかな'
81:       terms << '英語'
82:       terms << '日本語'
83:       terms << '語彙'
84:       terms << '辞典' 
85:       terms << '辞書'
86:       terms << 'ワード' 
87:       
88:       for term in terms
89:         begin
90:           RAILS_DEFAULT_LOGGER.info("Search for people who have tweeted [#{term}]")
91:           TwitterFriend.befriend_people_tweeting(term)        
92:         rescue Exception => exception
93:           RAILS_DEFAULT_LOGGER.error("Unable to search for tweets with [#{term}] due to [#{exception}]")
94:           RAILS_DEFAULT_LOGGER.error(exception.backtrace.join("   \n"))
95:         end
96:       end
97:   end

Twitter a message to the Kotoba app account

[Source]

     # File lib/kotoba_app_twitter.rb, line 100
100:   def tweet(twitter_type, item_id, message, source)
101:     twitter_tweet           = TwitterTweet.new
102:     twitter_tweet.message   = message
103:     case twitter_type
104:     when TwitterTweet::TYPE_WORD
105:       twitter_tweet.word_id        = item_id
106:     when TwitterTweet::TYPE_CHARACTER
107:       twitter_tweet.character_id   = item_id
108:     else
109:       raise "We do not know how to twitter type [#{twitter_type}]"
110:     end
111:     twitter_tweet.source = source
112:     twitter_tweet.save!
113:     begin
114:       if ['production'].include?(RAILS_ENV)
115:         twitter_app.update(message)
116:       else 
117:         puts "  Had it been production: message [#{message}]"
118:       end
119:       RAILS_DEFAULT_LOGGER.info("Succesffully sent Twitter update [#{message}]")
120:       twitter_tweet.is_sent = true
121:       twitter_tweet.save!
122:     rescue Exception => exception
123:       RAILS_DEFAULT_LOGGER.error("Unable to twitter [#{message}] due to [#{exception.message}]")
124:       RAILS_DEFAULT_LOGGER.error(exception.backtrace.join("   \n"))
125:       twitter_tweet.is_sent = false
126:       twitter_tweet.save!
127:     end
128:   end

Twitter a randomly selected type

[Source]

    # File lib/kotoba_app_twitter.rb, line 7
 7:   def twitter(twitter_type)
 8:     case twitter_type
 9:     when TwitterTweet::TYPE_WORD
10:       twitter_word
11:     when TwitterTweet::TYPE_CHARACTER
12:       twitter_character
13:     else
14:       raise "We do not know how to twitter type [#{twitter_type}]"
15:     end
16:   end

Returns our twitter account See twitter.rubyforge.org/rdoc/

[Source]

     # File lib/kotoba_app_twitter.rb, line 132
132:   def twitter_app
133:     Twitter::Base.new(account,password)
134:   end

Twitter a randomly selected character

[Source]

    # File lib/kotoba_app_twitter.rb, line 31
31:   def twitter_character
32:     begin
33:       character_messages = Array.new
34:       
35:       character, message = Character.get_character_of_moment_message()
36:       character_messages << { :character => character, :message => message, :source => TwitterTweet::SOURCE_MOMENT_OF }
37:       
38:       for jlpt in CharacterAttribute.distinct_jlpt_values
39:         character, message = Character.get_character_of_jlpt_message(jlpt.value)
40:         character_messages << { :character => character, :message => message, :source => TwitterTweet::SOURCE_JLPT }
41:       end
42:       
43:       for character_message in character_messages
44:         tweet(
45:           TwitterTweet::TYPE_CHARACTER, 
46:           character_message[:character].id, 
47:           character_message[:message],
48:           character_message[:source]
49:         )
50:         TwitterFriend.befriend_people_tweeting(character.character)
51:         if ['production'].include?(RAILS_ENV)
52:           sleep 2
53:         end
54:       end
55:     rescue Exception => exception
56:       RAILS_DEFAULT_LOGGER.error("Unable to tweet character [#{character}]: #{exception}")
57:       RAILS_DEFAULT_LOGGER.error(exception.backtrace.join("  \n"))
58:     end
59:   end

Twitter a randomly selected word

[Source]

    # File lib/kotoba_app_twitter.rb, line 19
19:   def twitter_word
20:     begin
21:       word, message = Word.get_word_of_moment_message
22:       tweet(TwitterTweet::TYPE_WORD, word.id, message, TwitterTweet::SOURCE_MOMENT_OF)
23:       TwitterFriend.befriend_people_tweeting(word.spelling)
24:     rescue Exception => exception
25:       RAILS_DEFAULT_LOGGER.error("Unable to tweet word [#{word}]: #{exception}")
26:       RAILS_DEFAULT_LOGGER.error(exception.backtrace.join("   \n"))
27:     end
28:   end

[Validate]