Created
October 21, 2016 20:52
-
-
Save lasseebert/5e0263f2ab184f8da1965194d8402999 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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