-
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?
Conversation
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.
I didn't notice this inconsistency, thanks for the feedback and PR 👍
This is looking good. I have left a review below with some potential suggestions.
@callback deliver(%Apus.Message{}, config :: map) :: {:ok, Apus.Message.t()} | {:error, any} | ||
|
||
@doc "Initialize adapter configuration." | ||
@callback handle_config(config :: map) :: config :: map |
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
?
case SentMessages.push(message) do | ||
:ok -> {:ok, message} | ||
error -> {:error, error} | ||
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.
The SentMessages.push
function always returns the same result so I don't think we need the case
here.
Can we remove the case
and update SentMessages.push
to return {:ok, message}
?
case send(self(), {:delivered_message, message}) do | ||
{:delivered_message, _} -> {:ok, message} | ||
error -> {:error, error} | ||
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.
The send
function always returns the given input so we shouldn't need the case
here.
As we can hardcode the response, maybe something like this would be clearer?
send(self(), {:delivered_message, message})
{:ok, message}
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Related to the comment above on the local_adapter
, could we change this to {:ok, message}
to keep this clearer?
Refactors all adapters to return
{:ok, %Apus.Message.t()} | {:error, any()}
tuples.The
LocalAdapter
andTestAdapter
in particular returned inconsistent responses.This does not change the SmsSender API (yet), so it is a non-breaking change to anyone calling
SmsSender.deliver/1
and not calling the adapters directly.Note I'm maintaining a downstream fork here: https://gitlab.com/soapbox-pub/apus