Current section
Files
Jump to
Current section
Files
lib/keplars/automations.ex
defmodule Keplars.Automations do
@moduledoc false
alias Keplars.Http
def list(client, opts \\ []) do
query = build_query(opts, [:page, :limit])
Http.request(client, :get, "/automations#{query}")
end
def get(client, id) do
Http.request(client, :get, "/automations/#{id}")
end
def enroll(client, id, email) do
Http.request(client, :post, "/automations/#{id}/enroll", %{email: email})
end
def unenroll(client, id, email) do
Http.request(client, :post, "/automations/#{id}/unenroll", %{email: email})
end
defp build_query(opts, keys) do
params =
keys
|> Enum.reduce(%{}, fn key, acc ->
case Keyword.get(opts, key) do
nil -> acc
value -> Map.put(acc, key, value)
end
end)
if map_size(params) == 0 do
""
else
"?" <> URI.encode_query(params)
end
end
end