Skip to content

Instantly share code, notes, and snippets.

@dpritchett
Created July 25, 2011 18:16
Show Gist options
  • Save dpritchett/1104760 to your computer and use it in GitHub Desktop.
Save dpritchett/1104760 to your computer and use it in GitHub Desktop.
Ruby class for sending myself SMSes
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