Class: Blertr::TwitterNotifier

Inherits:
Notifier
  • Object
show all
Defined in:
lib/blertr/twitter_notifier.rb

Instance Attribute Summary

Attributes inherited from Notifier

#error_messages, #names

Instance Method Summary collapse

Methods inherited from Notifier

#in_time_window?, #name, #options, #set_option, #set_time, #will_alert?

Constructor Details

#initializeTwitterNotifier

Returns a new instance of TwitterNotifier.



6
7
8
9
# File 'lib/blertr/twitter_notifier.rb', line 6

def initialize
  super
  @names = ["twitter", "tweet", "twit"]
end

Instance Method Details

#alert(message) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/blertr/twitter_notifier.rb', line 11

def alert message
  Twitter.configure do |config|
    config.consumer_key = options[:consumer_key]
    config.consumer_secret = options[:consumer_secret]
    config.oauth_token = options[:oauth_token]
    config.oauth_token_secret = options[:oauth_token_secret]
  end
  msg = message message.command_short_name, command.time_string
  Twitter.update(msg)
end

#can_alert?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/blertr/twitter_notifier.rb', line 28

def can_alert?
  rtn = true
  begin
    require 'rubygems'
    require 'twitter'
  rescue LoadError => e
    rtn = false
    error_messages << "twitter gem cannot be found"
  end
  if rtn
    [:consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret].each do |key|
      rtn &= options[key]
      error_messages << "No #{key} in config file"
    end
  end
  rtn
end

#message(name, time) ⇒ Object



22
23
24
25
26
# File 'lib/blertr/twitter_notifier.rb', line 22

def message name, time
  user = options[:to].nil? ? "" : "@#{options[:to]}"
  msg = "#{user} #{name} is done! Took #{time}"
  msg
end