Class: BabySMS::Adapters::TwilioAdapter

Inherits:
BabySMS::Adapter show all
Defined in:
lib/babysms/adapters/twilio_adapter.rb

Defined Under Namespace

Classes: WebHook

Instance Attribute Summary

Attributes inherited from BabySMS::Adapter

#client, #from

Instance Method Summary collapse

Methods inherited from BabySMS::Adapter

#adapter_id, adapter_name, #adapter_name, for_adapter_id, for_number, #web_hook, #web_hook?, #web_hook_class

Constructor Details

#initialize(account_sid:, auth_token:, from:) ⇒ TwilioAdapter

Returns a new instance of TwilioAdapter.



8
9
10
11
12
# 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(, auth_token)
end

Instance Method Details

#deliver(message) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/babysms/adapters/twilio_adapter.rb', line 14

def deliver(message)
  result = client.api..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