Created
July 25, 2011 18:16
-
-
Save dpritchett/1104760 to your computer and use it in GitHub Desktop.
Ruby class for sending myself SMSes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twilio-ruby' | |
class SMSSender | |
def initialize | |
# put your own credentials here | |
@account_sid = ENV['TWILIO_ACCOUNT_SID'] | |
@auth_token = ENV['TWILIO_AUTH_TOKEN'] | |
@SMS_RECIPIENT = "+REDACTED" # My google voice number | |
@SMS_SENDER = "+REDACTED" # My paid twilio number | |
# set up a client to talk to the Twilio REST API | |
@client = Twilio::REST::Client.new(@account_sid, @auth_token) | |
end | |
def send(args={}) | |
defaults = { | |
:from => @SMS_SENDER, | |
:to => @SMS_RECIPIENT, | |
:body => "No text supplied." | |
} | |
args = defaults.merge(args) | |
@client.account.sms.messages.create( | |
:from => args[:from], | |
:to => args[:to], | |
:body => args[:body], | |
) | |
puts "Text sent: #{args[:body]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment