Class: Tolliver::Services::Methods::Sms::Plivo
- Inherits:
-
Object
- Object
- Tolliver::Services::Methods::Sms::Plivo
- Defined in:
- lib/tolliver/services/methods/sms/plivo.rb
Instance Method Summary collapse
- #deliver(notification, notification_receiver) ⇒ Object
-
#initialize(params = {}) ⇒ Plivo
constructor
A new instance of Plivo.
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 .bytesize > 200 raise 'Message too long.' end # Request API response = @api.({ '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.(notification..to_s), 'method' => 'POST' }) true end |