15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/kidspire/sms_client.rb', line 15
def self.send(to:, body:)
return false unless configured?
cfg = Kidspire.configuration
url = "#{TWILIO_BASE}/Accounts/#{cfg.twilio_account_sid}/Messages.json"
response = HTTParty.post(url,
basic_auth: { username: cfg.twilio_account_sid, password: cfg.twilio_auth_token },
body: { From: cfg.twilio_from_number, To: to, Body: body }
)
unless response.success?
Rails.logger.error("[Kidspire::SmsClient] Twilio error #{response.code}: #{response.body}")
return false
end
Rails.logger.info("[Kidspire::SmsClient] SMS sent to #{to}")
true
rescue => e
Rails.logger.error("[Kidspire::SmsClient] #{e.message}")
false
end
|