Skip to content

Instantly share code, notes, and snippets.

@jcap49
Last active January 1, 2016 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcap49/8a49291e8096f2c001f1 to your computer and use it in GitHub Desktop.
Save jcap49/8a49291e8096f2c001f1 to your computer and use it in GitHub Desktop.
## master.rb located in ./workers
require 'active_record'
require 'iron_worker_ng'
require 'twilio-ruby'
require 'pg'
require 'yaml'
require 'models/text_message'
# load in twilio vars
config = YAML.load_file("application.yml")
@account_sid = config['TWILIO_ACCOUNT_SID']
@auth_token = config['TWILIO_AUTH_TOKEN']
def setup_database
puts "Database connection details: #{params['database'].inspect}"
return unless params['database']
# estabilsh database connection
ActiveRecord::Base.establish_connection(params['database'])
end
def send_sms
twilio_client = Twilio::REST::Client.new(@account_sid, @auth_token)
text_message = TextMessage.find_by_user_id(params['user_id'])
return if text_message.nil?
twilio_client.account.sms.messages.create(
from: TextMessage::TWILIO_PHONE_NUMBER,
to: text_message.phone_number,
body: text_message.text_body
)
end
setup_database
send_sms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment