diff options
author | Rawane Zossou <dev@raw1z.fr> | 2015-09-19 01:22:47 +0200 |
---|---|---|
committer | Rawane Zossou <dev@raw1z.fr> | 2015-09-19 01:22:47 +0200 |
commit | 818c1bb791a30a88df54c286a3cb1571845a3d27 (patch) | |
tree | 38fb20c32a45bed9444d961d56aec0ac6e348b39 | |
parent | 39f3c3ab41d3c2c342a8ee70a3d734bbcd5b273e (diff) | |
download | mailchimp-818c1bb791a30a88df54c286a3cb1571845a3d27.tar.gz mailchimp-818c1bb791a30a88df54c286a3cb1571845a3d27.tar.xz |
starts the config agent on application startup
-rw-r--r-- | lib/mailchimp.ex | 32 | ||||
-rw-r--r-- | mix.exs | 3 |
2 files changed, 10 insertions, 25 deletions
diff --git a/lib/mailchimp.ex b/lib/mailchimp.ex index 144168d..fa8eb1d 100644 --- a/lib/mailchimp.ex +++ b/lib/mailchimp.ex @@ -1,16 +1,15 @@ defmodule Mailchimp do use Application - use GenServer - require Logger - @apikey Application.get_env :mailchimp, :apikey + def start(_type, _args) do + import Supervisor.Spec, warn: false - ### Public API - def start_link do - shard = get_shard - apiroot = "https://#{shard}.api.mailchimp.com/3.0/" - config = %{apiroot: apiroot, apikey: @apikey} - GenServer.start_link(Mailchimp, config, name: :mailchimp) + children = [ + worker(Mailchimp.Config, []), + ] + + opts = [strategy: :one_for_one, name: Aliver.Supervisor] + Supervisor.start_link(children, opts) end def get_account_details do @@ -49,19 +48,4 @@ defmodule Mailchimp do member = Mailchimp.List.add_member(config, %{"list_id" => list_id, "email" => email}) {:reply, member, config} end - - def get_shard do - parts = @apikey - |> String.split(~r{-}) - - case length(parts) do - 2 -> - List.last parts - _ -> - Logger.error "This doesn't look like an API Key: #{@apikey}" - Logger.info "The API Key should have both a key and a server name, separated by a dash, like this: abcdefg8abcdefg6abcdefg4-us1" - {:error} - end - end - end @@ -13,7 +13,8 @@ defmodule Mailchimp.Mixfile do end def application do - [applications: [:logger, :httpoison]] + [mod: {Mailchimp, []}, + applications: [:logger, :httpoison]] end defp description do |