Class: God::Contacts::Jabber

Inherits:
God::Contact show all
Defined in:
lib/god/contacts/jabber.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

.formatObject

Returns the value of attribute format



21
22
23
# File 'lib/god/contacts/jabber.rb', line 21

def format
  @format
end

.from_jidObject

Returns the value of attribute from_jid



20
21
22
# File 'lib/god/contacts/jabber.rb', line 20

def from_jid
  @from_jid
end

.hostObject

Returns the value of attribute host



20
21
22
# File 'lib/god/contacts/jabber.rb', line 20

def host
  @host
end

.passwordObject

Returns the value of attribute password



20
21
22
# File 'lib/god/contacts/jabber.rb', line 20

def password
  @password
end

.portObject

Returns the value of attribute port



20
21
22
# File 'lib/god/contacts/jabber.rb', line 20

def port
  @port
end

.subjectObject

Returns the value of attribute subject



20
21
22
# File 'lib/god/contacts/jabber.rb', line 20

def subject
  @subject
end

.to_jidObject

Returns the value of attribute to_jid



20
21
22
# File 'lib/god/contacts/jabber.rb', line 20

def to_jid
  @to_jid
end

Instance Attribute Details

#from_jidObject

Returns the value of attribute from_jid



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

def from_jid
  @from_jid
end

#hostObject

Returns the value of attribute host



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

def host
  @host
end

#passwordObject

Returns the value of attribute password



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

def password
  @password
end

#portObject

Returns the value of attribute port



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

def port
  @port
end

#subjectObject

Returns the value of attribute subject



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

def subject
  @subject
end

#to_jidObject

Returns the value of attribute to_jid



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

def to_jid
  @to_jid
end

Instance Method Details

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/god/contacts/jabber.rb', line 47

def notify(message, time, priority, category, host)
  body = Jabber.format.call(message, time, priority, category, host)

  message = ::Jabber::Message.new(arg(:to_jid), body)
  message.set_type(:normal)
  message.set_id('1')
  message.set_subject(arg(:subject))

  jabber_id = ::Jabber::JID.new("#{arg(:from_jid)}/God")

  client = ::Jabber::Client.new(jabber_id)
  client.connect(arg(:host), arg(:port))
  client.auth(arg(:password))
  client.send(message)
  client.close

  self.info = "sent jabber message to #{self.to_jid}"
rescue Object => e
  if e.respond_to?(:message)
    applog(nil, :info, "failed to send jabber message to #{arg(:to_jid)}: #{e.message}")
  else
    applog(nil, :info, "failed to send jabber message to #{arg(:to_jid)}: #{e.class}")
  end
  applog(nil, :debug, e.backtrace.join("\n"))
end

#valid?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
# File 'lib/god/contacts/jabber.rb', line 37

def valid?
  valid = true
  valid &= complain("Attribute 'host' must be specified", self) unless arg(:host)
  valid &= complain("Attribute 'port' must be specified", self) unless arg(:port)
  valid &= complain("Attribute 'from_jid' must be specified", self) unless arg(:from_jid)
  valid &= complain("Attribute 'to_jid' must be specified", self) unless arg(:to_jid)
  valid &= complain("Attribute 'password' must be specified", self) unless arg(:password)
  valid
end