Packages

Elixir client for Apostle.io.

Current section

Files

Jump to
apostle lib apostle.ex
Raw

lib/apostle.ex

require HTTPoison
defmodule Apostle do
alias Application, as: App
use App, otp_app: :apostle
@moduledoc """
Elixir client for Apostle.io.
The `Apostle` module can be used to queue messages for delivery via the Apostle API.
iex> Apostle.deliver email: "test@example.com", template_id: "welcome", name: "Mr Example"
Under the hood Apostle uses [HTTPoison](https://github.com/edgurgel/httpoison)
to issue HTTP requests to the Apostle API.
"""
def start _type, _args do
start
end
def start do
HTTPoison.start
end
def delivery_host do
App.get_env :apostle, :delivery_host, default_delivery_host
end
def domain_key do
App.get_env :apostle, :domain_key, default_domain_key
end
@doc ~S"""
Delivers a queue of messages via the API.
"""
def deliver %Apostle.Queue{}=queue do
Apostle.Queue.deliver queue
end
@doc ~S"""
Delivers a single mail via the API.
"""
def deliver %Apostle.Mail{}=mail do
Apostle.Queue.deliver Apostle.Queue.init(mail)
end
@doc ~S"""
Generates and delivers a single mail via the API.
"""
def deliver opts do
mail = Apostle.Mail.init opts
queue = Apostle.Queue.init mail
Apostle.Queue.deliver queue
end
def version do
{:ok, version} = :application.get_key(:apostle, :vsn)
to_string version
end
defp default_delivery_host do
host = System.get_env "APOSTLE_DELIVERY_HOST"
if host do
host
else
"http://deliver.apostle.io"
end
end
defp default_domain_key do
key = System.get_env "APOSTLE_DOMAIN_KEY"
if key do
key
else
raise "Either set :domain_key in the application's configuration or the APOSTLE_DOMAIN_KEY environment variable"
end
end
end