Skip to content

Commit

Permalink
Created Twilio contact
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmarkgo committed Jan 12, 2012
1 parent 7778f9c commit c6e6356
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/god/contacts/twilio.rb
@@ -0,0 +1,43 @@
# Send a TXT message via Twilio (http://twilio.com/).
#
# account_sid - Your account SID
# auth_token - Your account auth secret token

require 'twilio-ruby'

module God
module Contacts
class Twilio < Contact
class << self
attr_accessor :account_sid, :auth_token,
:from_number, :to_number
end

def valid?
valid = true
valid &= complain("Attribute 'account_sid' must be specified", self) unless arg(:account_sid)
valid &= complain("Attribute 'auth_token' must be specified", self) unless arg(:auth_token)
valid &= complain("Attribute 'from_number' must be specified", self) unless arg(:from_number)
valid &= complain("Attribute 'to_number' must be specified", self) unless arg(:to_number)
valid
end

attr_accessor :account_sid, :auth_token,
:from_number, :to_number

def notify(message, time, priority, category, host)
@client = Twilio::REST::Client.new arg(:account_sid), arg(:auth_token)
@client.account.sms.messages.create(
:from => arg(:from_number),
:to => arg(:to_number),
:body => message
)

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

0 comments on commit c6e6356

Please sign in to comment.