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

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

Defined Under Namespace

Classes: Plivo

Instance Method Summary collapse

Instance Method Details

#deliver(notification_receiver) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tolliver/services/methods/sms.rb', line 17

def deliver(notification_receiver)
  return false if provider.nil?

  # Prepare notification
  notification = notification_receiver.notification_delivery.notification

  # Send SMS
  begin
    provider.deliver(notification, notification_receiver)
    notification_receiver.status = 'sent'
  rescue StandardError => e
    notification_receiver.status = 'error'
    notification_receiver.error_message = e.message
  end

  # Mark as sent
  notification_receiver.sent_at = Time.current

  # Save
  notification_receiver.save

  true
end