Class: Noticed::DeliveryMethods::TwilioMessaging

Inherits:
Noticed::DeliveryMethod show all
Defined in:
lib/noticed/delivery_methods/twilio_messaging.rb

Instance Attribute Summary

Attributes inherited from Noticed::DeliveryMethod

#config, #event, #notification

Instance Method Summary collapse

Methods inherited from Noticed::DeliveryMethod

#evaluate_option, #fetch_constant, #perform

Methods included from ApiClient

#post_request

Instance Method Details

#account_sidObject



26
27
28
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 26

def 
  evaluate_option(:account_sid) || credentials.fetch(:account_sid)
end

#auth_tokenObject



30
31
32
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 30

def auth_token
  evaluate_option(:auth_token) || credentials.fetch(:auth_token)
end

#credentialsObject



38
39
40
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 38

def credentials
  evaluate_option(:credentials) || Rails.application.credentials.twilio
end

#deliverObject



4
5
6
7
8
9
10
11
12
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 4

def deliver
  post_request url, basic_auth: {user: , pass: auth_token}, form: json.stringify_keys
rescue Noticed::ResponseUnsuccessful => exception
  if exception.response.code.start_with?("4") && config[:error_handler]
    notification.instance_exec(exception.response, &config[:error_handler])
  else
    raise
  end
end

#jsonObject



14
15
16
17
18
19
20
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 14

def json
  evaluate_option(:json) || {
    From: phone_number,
    To: recipient.phone_number,
    Body: params.fetch(:message)
  }
end

#phone_numberObject



34
35
36
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 34

def phone_number
  evaluate_option(:phone_number) || credentials.fetch(:phone_number)
end

#urlObject



22
23
24
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 22

def url
  evaluate_option(:url) || "https://api.twilio.com/2010-04-01/Accounts/#{}/Messages.json"
end