Skip to content

Commit

Permalink
Merge pull request #40 from beamkenya/refactor_sms
Browse files Browse the repository at this point in the history
Refactor of SMS
  • Loading branch information
manuelgeek authored Jun 29, 2020
2 parents 5b83ae8 + ffd4721 commit 97faee8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 52 deletions.
14 changes: 4 additions & 10 deletions lib/at_ex/gateway/Sms/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ defmodule AtEx.Gateway.Sms.Bulk do
attrs
|> Map.put(:username, username)

with {:ok, %{status: 201} = res} <- post("/messaging", params) do
{:ok, Jason.decode!(res.body)}
else
{:ok, val} ->
{:error, %{status: val.status, message: val.body}}

{:error, message} ->
{:error, message}
end
"/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 an map of parameters that optionally accepts `lastReceivedId` of the message.
function accepts a map of parameters that optionally accepts `lastReceivedId` of the message.
sent
## Parameters
Expand Down
22 changes: 15 additions & 7 deletions lib/at_ex/gateway/base_http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,21 @@ defmodule AtEx.Gateway.Base do
@doc """
Process results from calling the gateway
"""
def process_result(result) do
with {:ok, res} <- Jason.decode(result) do
{:ok, res}
else
{:error, val} ->
{:error, val}
end

def process_result({:ok, %{status: 200} = res}) do
Jason.decode(res.body)
end

def process_result({:ok, %{status: 201} = res}) do
Jason.decode(res.body)
end

def process_result({:ok, result}) do
{:error, %{status: result.status, message: result.body}}
end

def process_result({:error, result}) do
{:error, result}
end
end
end
Expand Down
35 changes: 0 additions & 35 deletions lib/at_ex/gateway/sms.ex

This file was deleted.

0 comments on commit 97faee8

Please sign in to comment.