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



20
21
22
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 20

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

#auth_tokenObject



24
25
26
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 24

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

#credentialsObject



32
33
34
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 32

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

#deliverObject



4
5
6
# 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
end

#jsonObject



8
9
10
11
12
13
14
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 8

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

#phone_numberObject



28
29
30
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 28

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

#urlObject



16
17
18
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 16

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