Class: God::Contacts::Sms
- Inherits:
-
God::Contact
- Object
- God::Contact
- God::Contacts::Sms
- Defined in:
- lib/god/contacts/sms.rb
Class Attribute Summary collapse
-
.delivery_method ⇒ Object
Returns the value of attribute delivery_method.
-
.format ⇒ Object
Returns the value of attribute format.
-
.message_settings ⇒ Object
Returns the value of attribute message_settings.
-
.sendmail_settings ⇒ Object
Returns the value of attribute sendmail_settings.
-
.server_settings ⇒ Object
Returns the value of attribute server_settings.
Instance Attribute Summary collapse
-
#phone ⇒ Object
Returns the value of attribute phone.
Attributes inherited from God::Contact
Instance Method Summary collapse
- #notify(message, time, priority, category, host) ⇒ Object
- #notify_sendmail(mail) ⇒ Object
-
#notify_smtp(mail) ⇒ Object
private.
- #valid? ⇒ Boolean
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_method ⇒ Object
Returns the value of attribute delivery_method.
10 11 12 |
# File 'lib/god/contacts/sms.rb', line 10 def delivery_method @delivery_method end |
.format ⇒ Object
Returns the value of attribute format.
10 11 12 |
# File 'lib/god/contacts/sms.rb', line 10 def format @format end |
.message_settings ⇒ Object
Returns the value of attribute message_settings.
10 11 12 |
# File 'lib/god/contacts/sms.rb', line 10 def @message_settings end |
.sendmail_settings ⇒ Object
Returns the value of attribute sendmail_settings.
10 11 12 |
# File 'lib/god/contacts/sms.rb', line 10 def sendmail_settings @sendmail_settings end |
.server_settings ⇒ Object
Returns the value of attribute server_settings.
10 11 12 |
# File 'lib/god/contacts/sms.rb', line 10 def server_settings @server_settings end |
Instance Attribute Details
#phone ⇒ Object
Returns the value of attribute phone.
43 44 45 |
# File 'lib/god/contacts/sms.rb', line 43 def phone @phone end |
Instance Method Details
#notify(message, time, priority, category, host) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/god/contacts/sms.rb', line 51 def notify(, time, priority, category, host) begin body = Sms.format.call(self.phone, , time, priority, category, host) case Sms.delivery_method when :smtp notify_smtp(body) when :sendmail notify_sendmail(body) else raise "unknown delivery method: #{Sms.delivery_method}" end self.info = "sent sms to #{self.name}:#{self.phone}" rescue => e applog(nil, :info, "failed to send sms to #{self.name}:#{self.phone}: #{e.}") applog(nil, :debug, e.backtrace.join("\n")) end end |
#notify_sendmail(mail) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/god/contacts/sms.rb', line 87 def notify_sendmail(mail) IO.popen("#{Sms.sendmail_settings[:location]} #{Sms.sendmail_settings[:arguments]}","w+") do |sm| sm.print(mail.gsub(/\r/, '')) sm.flush end end |
#notify_smtp(mail) ⇒ Object
private
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/god/contacts/sms.rb', line 73 def notify_smtp(mail) args = [Sms.server_settings[:address], Sms.server_settings[:port]] if Sms.server_settings[:authentication] args << Sms.server_settings[:domain] args << Sms.server_settings[:user_name] args << Sms.server_settings[:password] args << Sms.server_settings[:authentication] end Net::SMTP.start(*args) do |smtp| smtp. mail, Sms.[:from], Sms.[:gateway_email] end end |
#valid? ⇒ Boolean
45 46 47 48 49 |
# File 'lib/god/contacts/sms.rb', line 45 def valid? valid = true valid &= complain("Attribute 'phone' must be specified", self) if self.phone.nil? valid end |