Class: Notifun::Notifier::TwilioNotifier

Inherits:
ParentNotifier show all
Defined in:
lib/notifun/notifiers/twilio_notifier.rb

Instance Attribute Summary

Attributes inherited from ParentNotifier

#error_message, #success

Instance Method Summary collapse

Methods inherited from ParentNotifier

#initialize

Constructor Details

This class inherits a constructor from Notifun::Notifier::ParentNotifier

Instance Method Details

#notify!(text, phone, options) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/notifun/notifiers/twilio_notifier.rb', line 2

def notify!(text, phone, options)
  if !defined?(Twilio)
    @success = false
    @error_message = "Twilio is not defined."
    return
  end

   = Notifun.configuration.text_config[:account_sid]
  auth_token = Notifun.configuration.text_config[:auth_token]
  from = Notifun.configuration.text_config[:from]
  return false unless .present? && auth_token.present? && from.present?

  begin
    client = Twilio::REST::Client.new , auth_token
    client.messages.create(
      from: from,
      to: phone,
      body: text
    )
  rescue Twilio::REST::RequestError => e
    @success = false
    @error_message = e.message
  end

  @success = true
end