Packages
pigeon
2.0.0-rc.1
2.0.1
2.0.0
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.6.3
1.6.2
1.6.1
1.6.0
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.1.0-rc.1
1.1.0-rc.0
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.9.1
0.9.0
0.8.0
0.7.0
0.6.0
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.0
0.2.0
0.1.0
iOS (APNS), Android (FCM), and Amazon Android (ADM) push notifications for Elixir.
Current section
Files
Jump to
Current section
Files
lib/pigeon/adm/result_parser.ex
defmodule Pigeon.ADM.ResultParser do
@moduledoc false
@doc ~S"""
Parses response and updates notification.
## Examples
iex> parse(%Pigeon.ADM.Notification{}, %{})
%Pigeon.ADM.Notification{response: :success}
iex> parse(%Pigeon.ADM.Notification{}, %{"registrationID" => "test"})
%Pigeon.ADM.Notification{response: :update,
updated_registration_id: "test"}
iex> parse(%Pigeon.ADM.Notification{}, %{"reason" => "InvalidRegistrationId"})
%Pigeon.ADM.Notification{response: :invalid_registration_id}
"""
# Handle RegID updates
def parse(notification, %{"registrationID" => new_regid}) do
notification
|> Map.put(:response, :update)
|> Map.put(:updated_registration_id, new_regid)
end
def parse(notification, %{"reason" => error}) do
notification
|> Map.put(:response, to_error_atom(error))
end
def parse(notification, %{}) do
notification
|> Map.put(:response, :success)
end
defp to_error_atom("InvalidRegistrationId"), do: :invalid_registration_id
defp to_error_atom("InvalidData"), do: :invalid_data
defp to_error_atom("InvalidConsolidationKey"), do: :invalid_consolidation_key
defp to_error_atom("InvalidExpiration"), do: :invalid_expiration
defp to_error_atom("InvalidChecksum"), do: :invalid_checksum
defp to_error_atom("InvalidType"), do: :invalid_type
defp to_error_atom("Unregistered"), do: :unregistered
defp to_error_atom("AccessTokenExpired"), do: :access_token_expired
defp to_error_atom("MessageTooLarge"), do: :message_too_large
defp to_error_atom("MaxRateExceeded"), do: :max_rate_exceeded
defp to_error_atom(_), do: :unknown_error
end