Pigeon v1.1.1 Pigeon.ADM View Source
Amazon Device Messaging (ADM)
Link to this section Summary
Functions
Sends a push over ADM
Starts ADM worker connection with given config or name
Stops existing ADM worker connection
Link to this section Types
Link to this type
connection_response()
View Source
connection_response :: {:ok, pid} | {:error, {:already_started, pid}}
Link to this type
on_response()
View Source
on_response() :: (Pigeon.ADM.Notification.t -> no_return)
Async callback for push notifications response.
Examples
handler = fn(%Pigeon.ADM.Notification{response: response}) ->
case response do
:success ->
Logger.debug "Push successful!"
:unregistered ->
Logger.error "Bad device token!"
_error ->
Logger.error "Some other error happened."
end
end
n = Pigeon.ADM.Notification.new("token", %{"message" => "test"})
Pigeon.ADM.push(n, on_response: handler)
Link to this type
push_opts()
View Source
push_opts() :: [to: atom | pid | nil, on_response: on_response | nil]
Options for sending push notifications.
:to
- Defines worker to process push. Defaults to:adm_default
:on_response
- Optional async callback triggered on receipt of push. Seeon_response/0
Link to this section Functions
Link to this function
push(notifications, opts \\ [])
View Source
push(Pigeon.ADM.Notification.t | [Pigeon.ADM.Notification.t], Keyword.t) :: no_return
Sends a push over ADM.
Examples
iex> msg = %{"body" => "your message"}
iex> n = Pigeon.ADM.Notification.new("your_reg_id", msg)
iex> Pigeon.ADM.push(n, on_response: nil)
:ok
iex> msg = %{"body" => "your message"}
iex> n = Pigeon.ADM.Notification.new("your_reg_id", msg)
iex> Pigeon.ADM.push(n)
%Pigeon.ADM.Notification{consolidation_key: nil,
expires_after: 604800, md5: "M13RuG4uDWqajseQcCiyiw==",
payload: %{"data" => %{"body" => "your message"}},
registration_id: "your_reg_id", response: :invalid_registration_id,
updated_registration_id: nil}
iex> msg = %{"body" => "your message"}
iex> n = Pigeon.ADM.Notification.new("your_reg_id", msg)
iex> notifs = Pigeon.ADM.push([n, n], to: :adm_default)
iex> Enum.map(notifs, & &1.response)
[:invalid_registration_id, :invalid_registration_id]
iex> me = self()
iex> handler = fn(_x) -> send(me, "Sent a push!") end
iex> n = Pigeon.ADM.Notification.new("your_reg_id", %{})
iex> Pigeon.ADM.push(n, on_response: handler)
iex> receive do
...> x -> x
...> after
...> 5_000 -> "No push response..."
...> end
"Sent a push!"
iex> msg = %{"body" => "your message"}
iex> n = Pigeon.ADM.Notification.new("your_reg_id", msg)
iex> notif = Pigeon.ADM.push(n, to: :worker_not_started)
iex> notif.response
:timeout
Link to this function
start_connection(name)
View Source
start_connection(atom | Pigeon.ADM.Config.t | Keyword.t) :: connection_response
Starts ADM worker connection with given config or name.
Examples
iex> config = Pigeon.ADM.Config.new(:adm_default)
iex> {:ok, pid} = Pigeon.ADM.start_connection(%{config | name: nil})
iex> Process.alive?(pid)
true