Skip to content

Instantly share code, notes, and snippets.

@gathuku
Created February 23, 2021 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gathuku/d9fcff565f7df11cb096fb4302adad02 to your computer and use it in GitHub Desktop.
Save gathuku/d9fcff565f7df11cb096fb4302adad02 to your computer and use it in GitHub Desktop.
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