Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexgleason
Copy link
Contributor

Refactors all adapters to return {:ok, %Apus.Message.t()} | {:error, any()} tuples.

The LocalAdapter and TestAdapter 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

Copy link
Member

@swelham swelham left a 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
Copy link
Member

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?

Comment on lines +12 to +15
case SentMessages.push(message) do
:ok -> {:ok, message}
error -> {:error, error}
end
Copy link
Member

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}?

Comment on lines +19 to +22
case send(self(), {:delivered_message, message}) do
{:delivered_message, _} -> {:ok, message}
error -> {:error, error}
end
Copy link
Member

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants