Class: BabySMS::Adapters::BandwidthAdapter

Inherits:
BabySMS::Adapter show all
Defined in:
lib/babysms/adapters/bandwidth_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(user_id:, api_token:, api_secret:, from:) ⇒ BandwidthAdapter

Returns a new instance of BandwidthAdapter.



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

def initialize(user_id:, api_token:, api_secret:, from:)
  super(from: from)

  self.client = Bandwidth::Client.new(user_id: user_id,
                                      api_token: api_token,
                                      api_secret: api_secret)
end

Instance Method Details

#deliver(message) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/babysms/adapters/bandwidth_adapter.rb', line 16

def deliver(message)
  response = Bandwidth::Message.create(client,
                                       from: from,
                                       to: message.to,
                                       text: message.contents)
  if response[:error]
    raise BabySMS::FailedDelivery.new(response[:error].to_s, adapter: self)
  end

  response[:id]
end