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

Allowed for dynamic mailgun configuration #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ defmodule Mailgun.Client do

defmacro __using__(config) do
quote do
@conf unquote(config)
def conf, do: @conf
def conf, do: unquote(config)
def send_email(email) do
unquote(__MODULE__).send_email(conf(), email)
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Mailgun.Mixfile do

def project do
[app: :mailgun,
version: "0.1.3",
version: "0.1.4",
elixir: "~> 1.0",
deps: deps,
package: [
Expand Down
12 changes: 12 additions & 0 deletions test/mailgun_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ defmodule MailgunTest do

end

test "mailer configuration is load dynamically" do
Application.put_env(:mailgun, :domain, "https://api.mailgun.net/v3/domain.test")

defmodule Mailer do
use Mailgun.Client, domain: Application.get_env(:mailgun, :domain), key: "my-key"
end

Application.put_env(:mailgun, :domain, "https://api.mailgun.net/v3/updated_domain.test")

assert Mailer.conf() == [domain: "https://api.mailgun.net/v3/updated_domain.test", key: "my-key"]
end

test "send_email returns {:ok, response} if sent successfully" do
config = [domain: "https://api.mailgun.net/v3/mydomain.test", key: "my-key"]
use_cassette :stub, [url: "https://api.mailgun.net/v3/mydomain.test/messages",
Expand Down