ADM (Amazon Android)

Usage

  1. Set your environment variables.

    config :pigeon, :adm,
      client_id: "your_oauth2_client_id_here",
      client_secret: "your_oauth2_client_secret_here"
  2. Create a notification packet.

    msg = %{ "body" => "your message" }
    n = Pigeon.ADM.Notification.new("your device registration ID", msg)
  3. Send the packet.

    Pigeon.ADM.push(n)

Handling Push Responses

  1. Pass an optional anonymous function as your second parameter.

    data = %{ message: "your message" }
    n = Pigeon.ADM.Notification.new("device registration ID", data)
    Pigeon.ADM.push(n, fn(x) -> IO.inspect(x) end)
  2. Reponses return a tuple of either {:ok, notification} or {:error, reason, notification}. You could handle responses like so:

    on_response = fn(x) ->
      case x do
        {:ok, notification} ->
          # Push successful, check to see if the registration ID changed
          if !is_nil(notification.updated_registration_id) do
            # Update the registration ID in the database
          end
        {:error, :invalid_registration_id, notification} ->
          # Remove the bad ID from the database
        {:error, reason, notification} ->
          # Handle other errors
      end
    end
    
    data = %{ message: "your message" }
    n = Pigeon.ADM.Notification.new("your registration id", data)
    Pigeon.ADM.push(n, on_response)

Error Responses

Taken from Amazon Device Messaging docs

ReasonDescription
:invalid_registration_idInvalid Registration Token
:invalid_dataBad format JSON data
:invalid_consolidation_keyInvalid Consolidation Key
:invalid_expirationInvalid expiresAfter value
:invalid_checksumInvalid md5 value
:invalid_typeInvalid Type header
:unregisteredApp instance no longer available
:access_token_expiredExpired OAuth access token
:message_too_largeData size exceeds 6 KB
:max_rate_exceededSee Retry-After response header
:unknown_errorUnknown Error