Class: God::Contacts::Email

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

#friendly_name, generate, normalize, valid?

Methods included from God::Configurable

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

Class Attribute Details

.delivery_methodObject

Returns the value of attribute delivery_method.



9
10
11
# File 'lib/god/contacts/email.rb', line 9

def delivery_method
  @delivery_method
end

.formatObject

Returns the value of attribute format.



9
10
11
# File 'lib/god/contacts/email.rb', line 9

def format
  @format
end

.message_settingsObject

Returns the value of attribute message_settings.



9
10
11
# File 'lib/god/contacts/email.rb', line 9

def message_settings
  @message_settings
end

.server_settingsObject

Returns the value of attribute server_settings.



9
10
11
# File 'lib/god/contacts/email.rb', line 9

def server_settings
  @server_settings
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



38
39
40
# File 'lib/god/contacts/email.rb', line 38

def email
  @email
end

Instance Method Details

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



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

def notify(message, time, priority, category, host)
  begin
    body = Email.format.call(self.name, self.email, message, time, priority, category, host)
    
    args = [Email.server_settings[:address], Email.server_settings[:port]]
    if Email.server_settings[:authentication]
      args << Email.server_settings[:domain]
      args << Email.server_settings[:user_name]
      args << Email.server_settings[:password]
      args << Email.server_settings[:authentication] 
    end
      
    Net::SMTP.start(*args) do |smtp|
      smtp.send_message body, Email.message_settings[:from], self.email
    end
    
    self.info = "sent email to #{self.email}"
  rescue => e
    puts e.message
    puts e.backtrace.join("\n")
    
    self.info = "failed to send email to #{self.email}: #{e.message}"
  end
end

#valid?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/god/contacts/email.rb', line 40

def valid?
  valid = true
  valid &= complain("Attribute 'email' must be specified", self) if self.email.nil?
  valid
end