Class: Noticed::DeliveryMethods::TwilioMessaging
Instance Attribute Summary
#config, #event, #notification
Instance Method Summary
collapse
#evaluate_option, #fetch_constant, #perform
Methods included from ApiClient
#post_request
Instance Method Details
#account_sid ⇒ Object
26
27
28
|
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 26
def account_sid
evaluate_option(:account_sid) || credentials.fetch(:account_sid)
end
|
#auth_token ⇒ Object
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
|
#credentials ⇒ Object
38
39
40
|
# File 'lib/noticed/delivery_methods/twilio_messaging.rb', line 38
def credentials
evaluate_option(:credentials) || Rails.application.credentials.twilio
end
|
#deliver ⇒ Object
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: account_sid, 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
|
#json ⇒ Object
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_number ⇒ Object
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
|
#url ⇒ Object
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/#{account_sid}/Messages.json"
end
|