Skip to content

Commit

Permalink
refactoring process_result function
Browse files Browse the repository at this point in the history
  • Loading branch information
TraceyOnim committed Jun 20, 2020
1 parent 8ffecef commit 5727367
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 3 additions & 9 deletions lib/at_ex/gateway/Sms/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ defmodule AtEx.Gateway.Sms.Bulk do
attrs
|> Map.put(:username, username)

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

{:error, message} ->
{:error, message}
end
"/messaging"
|> post(params)
|> process_result()
end

@doc """
Expand Down
10 changes: 7 additions & 3 deletions lib/at_ex/gateway/base_http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ defmodule AtEx.Gateway.Base do
Process results from calling the gateway
"""
def process_result(result) do
with {:ok, res} <- Jason.decode(result) do
{:ok, res}
else
case result do
{:ok, %{status: 201} = res} ->
Jason.decode(res.body)

{:ok, val} ->
{:error, %{status: val.status, message: val.body}}

{:error, val} ->
{:error, val}
end
Expand Down

0 comments on commit 5727367

Please sign in to comment.