Class: SmsBroker::Client::Twilio

Inherits:
Base
  • Object
show all
Defined in:
lib/sms_broker/client/twilio.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) ⇒ Twilio

Returns a new instance of Twilio.



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

def initialize(options)
  client = ::Twilio::REST::Client.new(
    options[:account_sid],
    options[:auth_token]
  )

  super :Twilio, client, options
end

Instance Method Details

#send_message(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sms_broker/client/twilio.rb', line 13

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

  return Response::TwilioSuccess.new(response) \
    if success_response?(response)

  Response::TwilioError.new(response)
rescue ::Twilio::REST::RequestError => exception
  Response::TwilioError.new(exception)
end

#send_voice_message(_message) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/sms_broker/client/twilio.rb', line 27

def send_voice_message(_message)
  message = 'twillio voice message integration is not implemented'
  exception = \
    Exceptions::NotImplemented.new(message)

  raise exception
end