Class: BabySMS::Adapters::PlivoAdapter

Inherits:
BabySMS::Adapter show all
Defined in:
lib/babysms/adapters/plivo_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(auth_id:, auth_token:, from:) ⇒ PlivoAdapter

Returns a new instance of PlivoAdapter.



8
9
10
11
12
# File 'lib/babysms/adapters/plivo_adapter.rb', line 8

def initialize(auth_id:, auth_token:, from:)
  super(from: from)

  self.client = Plivo::RestClient.new(auth_id, auth_token)
end

Instance Method Details

#deliver(message) ⇒ Object



14
15
16
17
18
19
# File 'lib/babysms/adapters/plivo_adapter.rb', line 14

def deliver(message)
  response = client.messages.create(from, [message.to], message.contents)
  response.message_uuid
rescue PlivoRESTError => e
  raise BabySMS::FailedDelivery.new(e.message, adapter: self)
end