Class: Tolliver::Services::Methods::Sms::Plivo

Inherits:
Object
  • Object
show all
Defined in:
lib/tolliver/services/methods/sms/plivo.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Plivo

Returns a new instance of Plivo.



18
19
20
21
22
23
24
25
26
# File 'lib/tolliver/services/methods/sms/plivo.rb', line 18

def initialize(params = {})
  require 'plivo'
  if params[:auth_id].blank? || params[:auth_token].blank?
    raise Tolliver::Errors::StandardError.new('Please provide Auth ID and Auth Token in SMS provider params.')
  end
  @auth_id = params[:auth_id]
  @auth_token = params[:auth_token]
  @api = ::Plivo::RestAPI.new(@auth_id, @auth_token)
end

Instance Method Details

#deliver(notification, notification_receiver) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tolliver/services/methods/sms/plivo.rb', line 28

def deliver(notification, notification_receiver)

  # Check message length.
  if message.bytesize > 200
    raise 'Message too long.'
  end

  # Request API
  response = @api.send_message({
                                   'src' => Tolliver.sms_sender, # TODO: This should be improved to take sender from number pool and remember number / message mapping
                                   'dst' => notification_receiver.receiver_contact.to_s,
                                   'text' => ActionController::Base.helpers.strip_tags(notification.message.to_s),
                                   'method' => 'POST'
                               })

  true
end