class BabySMS::Adapters::TwilioAdapter

Public Class Methods

new(account_sid:, auth_token:, from:) click to toggle source
Calls superclass method BabySMS::Adapter::new
# File lib/babysms/adapters/twilio_adapter.rb, line 8
def initialize(account_sid:, auth_token:, from:)
  super(from: from)

  self.client = Twilio::REST::Client.new(account_sid, auth_token)
end

Public Instance Methods

deliver(message) click to toggle source
# File lib/babysms/adapters/twilio_adapter.rb, line 14
def deliver(message)
  result = client.api.account.messages.create(from: from,
                                              to: message.to,
                                              body: message.contents,
                                              status_callback: web_hook.end_point)
  result.sid
rescue Twilio::REST::TwilioError => e
  raise BabySMS::FailedDelivery.new(e.message, adapter: self)
end