Class: SmsBroker::Client::Nexmo

Inherits:
Base
  • Object
show all
Defined in:
lib/sms_broker/client/nexmo.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #name, #phone_number, #sender_id

Instance Method Summary collapse

Methods inherited from Base

#serialize_to_number

Constructor Details

#initialize(options) ⇒ Nexmo

Returns a new instance of Nexmo.



4
5
6
7
8
9
# File 'lib/sms_broker/client/nexmo.rb', line 4

def initialize(options)
  client = \
    ::Nexmo::Client.new(key: options[:key], secret: options[:secret])

  super :nexmo, client, options
end

Instance Method Details

#send_message(message) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sms_broker/client/nexmo.rb', line 11

def send_message(message)
  response = client.send_message \
    text: message[:text],
    from: message[:from],
    to: serialize_to_number(message[:to])

  if success_response?(response)
    Response::NexmoSuccess.new(response)
  else
    Response::NexmoError.new(response)
  end
end

#send_voice_message(message) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sms_broker/client/nexmo.rb', line 24

def send_voice_message(message)
  response = client.initiate_tts_call \
    text: message[:text],
    from: message[:from],
    to: serialize_to_number(message[:to]),
    lg: message[:lang]

  if voice_success_response?(response)
    Response::NexmoVoiceSuccess.new(response)
  else
    Response::NexmoVoiceError.new(response)
  end
end