-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapter: consistent returns #125
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
defmodule Apus.Adapter do | ||
@moduledoc """ | ||
An adapter provides a way to communicate with a third-party SMS service | ||
using a consistent API. | ||
""" | ||
|
||
@callback deliver(%Apus.Message{}, %{}) :: any | ||
@callback handle_config(map) :: map | ||
@doc "Send the SMS message." | ||
@callback deliver(%Apus.Message{}, config :: map) :: {:ok, Apus.Message.t()} | {:error, any} | ||
|
||
@doc "Initialize adapter configuration." | ||
@callback handle_config(config :: map) :: config :: map | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
defmodule Apus.LocalAdapter do | ||
@moduledoc """ | ||
Deliver messages to a local inbox, available to view if | ||
`Apus.SentMessagesViewerPlug` is installed in your router. | ||
""" | ||
|
||
@behaviour Apus.Adapter | ||
|
||
alias Apus.SentMessages | ||
|
||
def deliver(message, _config) do | ||
SentMessages.push(message) | ||
case SentMessages.push(message) do | ||
:ok -> {:ok, message} | ||
error -> {:error, error} | ||
end | ||
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Can we remove the |
||
end | ||
|
||
def handle_config(config), do: config | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
defmodule Apus.TestAdapter do | ||
@moduledoc """ | ||
Adapter for use with automated testing. | ||
""" | ||
|
||
@behaviour Apus.Adapter | ||
|
@@ -15,7 +16,10 @@ defmodule Apus.TestAdapter do | |
end | ||
|
||
def deliver(message, _config) do | ||
send(self(), {:delivered_message, message}) | ||
case send(self(), {:delivered_message, message}) do | ||
{:delivered_message, _} -> {:ok, message} | ||
error -> {:error, error} | ||
end | ||
Comment on lines
+19
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The As we can hardcode the response, maybe something like this would be clearer? send(self(), {:delivered_message, message})
{:ok, message} |
||
end | ||
|
||
def handle_config(config) do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,5 @@ defmodule Apus.SentMessages do | |
Agent.update(__MODULE__, fn messages -> | ||
[message | messages] | ||
end) | ||
|
||
message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the comment above on the |
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible typo on the return type here?
I think this should be
:: map
instead of:: config :: map
?