1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
defmodule Mailchimp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
worker(Mailchimp.Config, []),
]
opts = [strategy: :one_for_one, name: Aliver.Supervisor]
Supervisor.start_link(children, opts)
end
def get_account_details do
GenServer.call(:mailchimp, :account_details)
end
def get_all_lists do
GenServer.call(:mailchimp, :all_lists)
end
def get_list_members(list_id) do
GenServer.call(:mailchimp, {:list_members, list_id})
end
def add_member(list_id, email) do
GenServer.call(:mailchimp, {:add_member, list_id, email})
end
### Server API
def handle_call(:account_details, _from, config) do
details = Mailchimp.Account.get_details(config)
{:reply, details, config}
end
def handle_call(:all_lists, _from, config) do
lists = Mailchimp.List.all(config)
{:reply, lists, config}
end
def handle_call({:list_members, list_id}, _from, config) do
members = Mailchimp.List.members(config, list_id)
{:reply, members, config}
end
def handle_call({:add_member, list_id, email}, _from, config) do
member = Mailchimp.List.add_member(config, %{"list_id" => list_id, "email" => email})
{:reply, member, config}
end
end
|