Class: BabySMS::Adapters::SignalwireAdapter

Inherits:
BabySMS::Adapter show all
Defined in:
lib/babysms/adapters/signalwire_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(from:, project:, token:, space_url:) ⇒ SignalwireAdapter

Returns a new instance of SignalwireAdapter.



10
11
12
13
# File 'lib/babysms/adapters/signalwire_adapter.rb', line 10

def initialize(from:, project:, token:, space_url:)
  super(from: from)
  self.client = Signalwire::REST::Client.new(project, token, signalwire_space_url: space_url)
end

Instance Method Details

#deliver(message) ⇒ Object



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

def deliver(message)
  result = client.messages.create(from: from,
                                  to: message.to,
                                  body: message.contents,
                                  status_callback: web_hook.end_point)
  result.sid
rescue Signalwire::REST::SignalwireError => e
  raise BabySMS::FailedDelivery.new(e.message, adapter: self)
end