-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
29 lines (25 loc) · 832 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'logger'
require 'twilio-ruby'
require 'yaml'
def twilio_client_with(data)
Twilio::REST::Client.new data['account_sid'], data['auth_token']
end
environment = ENV['APP_ENV'] || 'testing'
config = YAML::load_file('config/config.yml')[environment]
client = twilio_client_with config['twilio']
logger = Logger.new("log/#{environment}.log")
logger.info "Starting execution..."
File.open(config['destination_numbers_file']) do |file|
file.each_line do |destination_number|
begin
message = client.account.messages.create(
:body => config['twilio']['body'],
:to => destination_number.chomp,
:from => config['twilio']['from']
)
logger.info "Message to #{message.to} was succesfully sent."
rescue Twilio::REST::RequestError => e
logger.error e.message
end
end
end