From fc5a7fbac6e34a4390b3391f571fdef39a3ca097 Mon Sep 17 00:00:00 2001 From: Rafal Radziszewski Date: Wed, 1 Jun 2016 14:21:34 +0200 Subject: [PATCH 1/2] Allowed for dynamic mailgun configuration --- lib/client.ex | 3 +-- test/mailgun_test.exs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/client.ex b/lib/client.ex index 3cf53ae..61a9d91 100644 --- a/lib/client.ex +++ b/lib/client.ex @@ -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 diff --git a/test/mailgun_test.exs b/test/mailgun_test.exs index 25f0529..ec31e0b 100644 --- a/test/mailgun_test.exs +++ b/test/mailgun_test.exs @@ -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", From 29aaf08473b13835def456d055716f551ece4153 Mon Sep 17 00:00:00 2001 From: Rafal Radziszewski Date: Fri, 3 Jun 2016 15:28:31 +0200 Subject: [PATCH 2/2] Bump --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index c24670c..42740f2 100644 --- a/mix.exs +++ b/mix.exs @@ -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: [