Class: Unisms::Adapter::Nexmo

Inherits:
Base
  • Object
show all
Defined in:
lib/unisms/adapter/nexmo.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, secret) ⇒ Nexmo

Returns a new instance of Nexmo.



6
7
8
# File 'lib/unisms/adapter/nexmo.rb', line 6

def initialize(key, secret)
	@nexmo = ::Nexmo::Client.new key: key, secret: secret
end

Instance Method Details

#deliver(message, to: nil, from: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/unisms/adapter/nexmo.rb', line 10

def deliver(message, to: nil, from: nil)
	raise ArgumentError.new "'from' is required in Nexmo" if from.nil?
	response = @nexmo.send_message(text: message, to: to, from: from, type: 'unicode')
	Unisms.logger.debug response
	true
rescue ArgumentError => e
	Unisms.logger.error "ArgumentError: #{e}"
	false
rescue SocketError => e
	Unisms.logger.error "Failed to send message to #{to}"
	false
end