Current section

Files

Jump to
swoosh lib swoosh adapter.ex
Raw

lib/swoosh/adapter.ex

defmodule Swoosh.Adapter do
@moduledoc ~S"""
Specification of the email delivery adapter.
"""
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
@required_config opts[:required_config] || []
@behaviour Swoosh.Adapter
def validate_config(config) do
missing_keys = Enum.reduce(@required_config, [], fn(key, missing_keys) ->
if config[key] in [nil, ""], do: [key | missing_keys], else: missing_keys
end)
raise_on_missing_config(missing_keys, config)
end
defp raise_on_missing_config([], _config), do: :ok
defp raise_on_missing_config(key, config) do
raise ArgumentError, """
expected #{inspect key} to be set, got: #{inspect config}
"""
end
end
end
@type t :: module
@type email :: Email.t
@typep config :: Keyword.t
@doc """
Delivers an email with the given config.
"""
@callback deliver(email, config) :: {:ok, term} | {:error, term}
end