Class: God::Contacts::Sendhub

Inherits:
Contact
  • Object
show all
Defined in:
lib/sendhub/plugins/god.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/sendhub/plugins/god.rb', line 7

def api_key
  @api_key
end

.fromObject

Returns the value of attribute from.



7
8
9
# File 'lib/sendhub/plugins/god.rb', line 7

def from
  @from
end

.secret_keyObject

Returns the value of attribute secret_key.



7
8
9
# File 'lib/sendhub/plugins/god.rb', line 7

def secret_key
  @secret_key
end

Instance Attribute Details

#toObject

Returns the value of attribute to.



18
19
20
# File 'lib/sendhub/plugins/god.rb', line 18

def to
  @to
end

Instance Method Details

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sendhub/plugins/god.rb', line 20

def notify(message, time, priority, category, host)
  puts "#{message}"
  data = {
    :message => message,
    :time => time,
    :priority => priority,
    :category => category,
    :host => host
  }
  
  client = ::Sendhub::Client.new(:api_key => arg(:api_key), :secret_key => arg(:secret_key))
  res = client.send_email(
    :from => arg(:from),
    :to => arg(:to),
    :subject => "[god] #{message}",
    :body => data.inspect
  )
  
  applog(nil, :info, res.inspect)
rescue Object => e
  applog(nil, :info, "failed to send email to #{arg(:to)}: #{e.message}")
  applog(nil, :debug, e.backtrace.join("\n"))
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/sendhub/plugins/god.rb', line 10

def valid?
  valid = true
  valid &= complain("Attribute 'api_key' must be specified", self) unless arg(:api_key)
  valid &= complain("Attribute 'secret_key' must be specified", self) unless arg(:secret_key)
  valid &= complain("Attribute 'from' must be specified", self) unless arg(:from)
  valid
end