Created
February 23, 2021 06:50
-
-
Save gathuku/d9fcff565f7df11cb096fb4302adad02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DeliveryMethods::AfricasTalking < Noticed::DeliveryMethods::Base | |
def deliver | |
post(url, format) | |
end | |
def format | |
{ | |
username: credentials.fetch(:username), | |
to: recipient.tel.gsub(/\s+/, ''), # recepient phone number | |
message: notification.params[:message], | |
from: credentials.fetch(:short_code) # Your registered short code or alphanumeric, defaults to AFRICASTKNG. | |
} | |
end | |
def post(url, body) | |
HTTP.headers( | |
apikey: credentials.fetch(:api_key), | |
accept: 'application/json' | |
).post(url, form: body) | |
end | |
def url | |
'https://api.africastalking.com/version1/messaging' | |
end | |
def credentials | |
if (method = options[:credentials]) | |
notification.send(method) | |
else | |
Rails.application.credentials.africas_talking | |
end | |
end | |
after_deliver do | |
# after deliver callback | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment