Class: BabySMS::Adapters::NexmoAdapter
- Inherits:
-
BabySMS::Adapter
- Object
- BabySMS::Adapter
- BabySMS::Adapters::NexmoAdapter
- Defined in:
- lib/babysms/adapters/nexmo_adapter.rb
Defined Under Namespace
Classes: WebHook
Instance Attribute Summary
Attributes inherited from BabySMS::Adapter
Instance Method Summary collapse
- #deliver(message) ⇒ Object
-
#initialize(api_key:, api_secret:, from:) ⇒ NexmoAdapter
constructor
A new instance of NexmoAdapter.
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(api_key:, api_secret:, from:) ⇒ NexmoAdapter
Returns a new instance of NexmoAdapter.
8 9 10 11 12 |
# File 'lib/babysms/adapters/nexmo_adapter.rb', line 8 def initialize(api_key:, api_secret:, from:) super(from: from) self.client = Nexmo::Client.new(api_key: api_key, api_secret: api_secret) end |
Instance Method Details
#deliver(message) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/babysms/adapters/nexmo_adapter.rb', line 14 def deliver() # Thanks for being weird, Nexmo. Rejects numbers starting with "+" response = client.sms.send(from: from.gsub(/\A\+/, ''), to: .to, text: .contents) if response..first.status != '0' raise BabySMS::FailedDelivery.new(response..first.error_text, adapter: self) end response..first. end |