Skip to content

Instantly share code, notes, and snippets.

@lasseebert
Created October 21, 2016 20:52
Show Gist options
  • Save lasseebert/5e0263f2ab184f8da1965194d8402999 to your computer and use it in GitHub Desktop.
Save lasseebert/5e0263f2ab184f8da1965194d8402999 to your computer and use it in GitHub Desktop.
defmodule MyApp.Mailer.Mailgun do
@behaviour MyApp.Mailer.Behaviour
use Mailgun.Client, [
domain: Application.fetch_env!(:my_app, :mailgun_domain),
key: Application.fetch_env!(:my_app, :mailgun_key)
]
def send_mail(mail) do
{:ok, _} = send_email(mail)
:ok
end
end
defmodule MyApp.Mailer.Mock do
@behaviour MyApp.Mailer.Behaviour
def start_link do
Agent.start_link(fn -> [] end, name: __MODULE__)
end
def mails do
Agent.get(__MODULE__, &(&1))
end
def clear do
Agent.update(__MODULE__, fn _mails -> [] end)
end
def send_mail(mail) do
mail = mail |> Enum.into(%{})
Agent.update(__MODULE__, fn existing_mails -> [mail | existing_mails] end)
:ok
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment