Class: God::Contacts::Twitter

Inherits:
God::Contact show all
Defined in:
lib/god/contacts/twitter.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from God::Contact

#group, #info, #name

Instance Method Summary collapse

Methods inherited from God::Contact

#arg, defaults, #friendly_name, generate, normalize, valid?

Methods included from God::Configurable

#base_name, complain, #complain, #friendly_name, #prepare, #reset

Class Attribute Details

.access_secretObject

Returns the value of attribute access_secret.



19
20
21
# File 'lib/god/contacts/twitter.rb', line 19

def access_secret
  @access_secret
end

.access_tokenObject

Returns the value of attribute access_token.



19
20
21
# File 'lib/god/contacts/twitter.rb', line 19

def access_token
  @access_token
end

.consumer_secretObject

Returns the value of attribute consumer_secret.



19
20
21
# File 'lib/god/contacts/twitter.rb', line 19

def consumer_secret
  @consumer_secret
end

.consumer_tokenObject

Returns the value of attribute consumer_token.



19
20
21
# File 'lib/god/contacts/twitter.rb', line 19

def consumer_token
  @consumer_token
end

Instance Attribute Details

#access_secretObject

Returns the value of attribute access_secret.



35
36
37
# File 'lib/god/contacts/twitter.rb', line 35

def access_secret
  @access_secret
end

#access_tokenObject

Returns the value of attribute access_token.



35
36
37
# File 'lib/god/contacts/twitter.rb', line 35

def access_token
  @access_token
end

#consumer_secretObject

Returns the value of attribute consumer_secret.



35
36
37
# File 'lib/god/contacts/twitter.rb', line 35

def consumer_secret
  @consumer_secret
end

#consumer_tokenObject

Returns the value of attribute consumer_token.



35
36
37
# File 'lib/god/contacts/twitter.rb', line 35

def consumer_token
  @consumer_token
end

Instance Method Details

#notify(message, time, priority, category, host) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/god/contacts/twitter.rb', line 38

def notify(message, time, priority, category, host)
  oauth = ::Twitter::OAuth.new(arg(:consumer_token), arg(:consumer_secret))
  oauth.authorize_from_access(arg(:access_token), arg(:access_secret))

  ::Twitter::Base.new(oauth).update(message)

  self.info = "sent twitter update"
rescue => e
  applog(nil, :info, "failed to send twitter update: #{e.message}")
  applog(nil, :debug, e.backtrace.join("\n"))
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/god/contacts/twitter.rb', line 26

def valid?
  valid = true
  valid &= complain("Attribute 'consumer_token' must be specified", self) unless arg(:consumer_token)
  valid &= complain("Attribute 'consumer_secret' must be specified", self) unless arg(:consumer_secret)
  valid &= complain("Attribute 'access_token' must be specified", self) unless arg(:access_token)
  valid &= complain("Attribute 'access_secret' must be specified", self) unless arg(:access_secret)
  valid
end