BathHacked/energy-sparks

View on GitHub
app/services/send_sms.rb

Summary

Maintainability
A
0 mins
Test Coverage
F
36%
require 'twilio-ruby'

class SendSms
  def initialize(body, to_number)
    account_sid = ENV['TWILIO_ACCOUNT_SID']
    auth_token = ENV['TWILIO_AUTH_TOKEN']
    @from_phone_number = ENV['TWILIO_PHONE_NUMBER']
    @send_automated_sms = (ENV['SEND_AUTOMATED_SMS'] == 'true')
    @twilio_client = Twilio::REST::Client.new(account_sid, auth_token)
    @body = body
    @to_number = to_number
  end

  def send
    @twilio_client.messages.create(body: @body, to: @to_number, from: @from_phone_number) if @send_automated_sms
  end
end