-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from beamkenya/develop
Promote to master
- Loading branch information
Showing
8 changed files
with
255 additions
and
182 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
defmodule AtEx.Gateway.Sms.Bulk do | ||
@moduledoc """ | ||
This module holds the implementation for the HTTP Gateway that runs calls against the Africas Talking API | ||
SMS endpoint, use it to POST and GET requests to the SMS endpoint | ||
""" | ||
use AtEx.Gateway.Base, url: "https://api.sandbox.africastalking.com/version1" | ||
|
||
@doc """ | ||
This function builds and runs a post request to send an SMS via the Africa's talking SMS endpoint, this | ||
function accepts a map of parameters that should always contain the `to` address and the `message` to be | ||
sent | ||
## Parameters | ||
attrs: - a map containing a `to` and `message` key optionally it may also contain `from`, bulk_sms, enqueue, key_word | ||
link_id and retry_hours keys, see the docs at https://build.at-labs.io/docs/sms%2Fsending for how to use these keys | ||
""" | ||
@spec send_sms(map()) :: {:ok, term()} | {:error, term()} | ||
def send_sms(attrs) do | ||
username = Application.get_env(:at_ex, :username) | ||
|
||
params = | ||
attrs | ||
|> Map.put(:username, username) | ||
|
||
"/messaging" | ||
|> post(params) | ||
|> process_result() | ||
end | ||
|
||
@doc """ | ||
This function makes a get request to fetch an SMS via the Africa's talking SMS endpoint, this | ||
function accepts a map of parameters that optionally accepts `lastReceivedId` of the message. | ||
sent | ||
## Parameters | ||
attrs: - an empty map or a map containing optionally `lastReceivedId` of the message to be fetched, see the docs at https://build.at-labs.io/docs/sms%2Ffetch_messages for how to use these keys | ||
""" | ||
|
||
@spec fetch_sms(map()) :: {:error, any()} | {:ok, any()} | ||
def fetch_sms(attrs) do | ||
username = Application.get_env(:at_ex, :username) | ||
|
||
params = | ||
attrs | ||
|> Map.put(:username, username) | ||
|> Map.to_list() | ||
|
||
with {:ok, %{status: 200} = res} <- get("/messaging", query: params) do | ||
{:ok, Jason.decode!(res.body)} | ||
else | ||
{:ok, val} -> | ||
{:error, %{status: val.status, message: val.body}} | ||
|
||
{:error, message} -> | ||
{:error, message} | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
defmodule AtEx.Gateway.Voice do | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.