Pigeon v0.11.0 Pigeon.GCM.Notification

Defines GCM notification struct and convenience constructor functions.

Summary

Functions

Creates GCM.Notification struct with device registration IDs and optional notification and data payloads

Updates "data" key in push payload

Updates "notification" key in push payload

Types

t()
t() :: %Pigeon.GCM.Notification{message_id: String.t, payload: %{}, registration_id: String.t | [String.t], updated_registration_id: String.t}

Functions

new(registration_ids, notification \\ %{}, data \\ %{})

Creates GCM.Notification struct with device registration IDs and optional notification and data payloads.

Examples

iex> Pigeon.GCM.Notification.new("reg ID")
%Pigeon.GCM.Notification{
  message_id: nil,
  payload: %{},
  registration_id: "reg ID",
  updated_registration_id: nil
}

iex> Pigeon.GCM.Notification.new("reg ID", %{"body" => "test message"})
%Pigeon.GCM.Notification{
  message_id: nil,
  payload: %{"notification" => %{"body" => "test message"}},
  registration_id: "reg ID",
  updated_registration_id: nil
}

iex> Pigeon.GCM.Notification.new("reg ID", %{"body" => "test message"}, %{"key" => "value"})
%Pigeon.GCM.Notification{
  message_id: nil,
  payload: %{
    "data" => %{"key" => "value"},
    "notification" => %{"body" => "test message"}
  },
  registration_id: "reg ID",
  updated_registration_id: nil
}
put_data(n, data)

Updates "data" key in push payload.

Examples

iex> Pigeon.GCM.Notification.put_data(%Pigeon.GCM.Notification{}, %{"key" => 1234})
%Pigeon.GCM.Notification{
  message_id: nil,
  payload: %{"data" => %{"key" => 1234}},
  registration_id: nil,
  updated_registration_id: nil
}
put_notification(n, notification)

Updates "notification" key in push payload.

Examples

iex> Pigeon.GCM.Notification.put_notification(%Pigeon.GCM.Notification{},
...> %{"body" => "message"})
%Pigeon.GCM.Notification{
  message_id: nil,
  payload: %{"notification" => %{"body" => "message"}},
  registration_id: nil,
  updated_registration_id: nil
}