Class: TweetMsx
- Inherits:
-
Object
- Object
- TweetMsx
- Defined in:
- lib/tweet_msx.rb
Overview
end
Defined Under Namespace
Classes: NotConfigured
Constant Summary collapse
- CONFIG_FILENAME =
File.('~/.openMSX-builder-TweetMSX.yaml')
- DEFAULTS =
{ :client => { :consumer_key => '', :consumer_secret => '', :token => '', :secret => '', } }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#twitter_down ⇒ Object
readonly
Returns the value of attribute twitter_down.
Instance Method Summary collapse
- #config ⇒ Object
- #create_default_config ⇒ Object
-
#initialize(log_level = Logger::FATAL) ⇒ TweetMsx
constructor
A new instance of TweetMsx.
- #update(message) ⇒ Object
Constructor Details
#initialize(log_level = Logger::FATAL) ⇒ TweetMsx
Returns a new instance of TweetMsx.
26 27 28 29 30 |
# File 'lib/tweet_msx.rb', line 26 def initialize(log_level=Logger::FATAL) @log = Logger.new(STDOUT) @log.level = log_level @client = TwitterOAuth::Client.new(config[:client]) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
25 26 27 |
# File 'lib/tweet_msx.rb', line 25 def client @client end |
#twitter_down ⇒ Object (readonly)
Returns the value of attribute twitter_down.
25 26 27 |
# File 'lib/tweet_msx.rb', line 25 def twitter_down @twitter_down end |
Instance Method Details
#config ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tweet_msx.rb', line 32 def config create_default_config unless File.exist?(CONFIG_FILENAME) @config ||= YAML.load_file(CONFIG_FILENAME) @log.debug @config.to_yaml if @config == DEFAULTS @log.error "TweetMSX config at #{CONFIG_FILENAME} matches DEFAULTS" raise NotConfigured.new("You need to set up your config file at #{CONFIG_FILENAME} first") end @config end |
#create_default_config ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/tweet_msx.rb', line 43 def create_default_config system("mkdir -p #{File.dirname(CONFIG_FILENAME)}") @log.debug "Creating default config at #{CONFIG_FILENAME}" File.open(CONFIG_FILENAME,'w') do |f| f.write DEFAULTS.to_yaml end end |
#update(message) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tweet_msx.rb', line 51 def update() @log.info "Tweeting message:\n #{}" @log.debug "[#{.size} characters]" if @client.rate_limit_status == 0 @log.error "You've exceeded your rate limit" return nil end ret = @client.update(.to_s) @log.info(ret.to_yaml) unless ret.nil? nil rescue SocketError @log.error "Could not send '#{}'. Twitter or your connection might be down." nil end |