BubblesNotifications (bubbles_notifications v0.1.0)

Copy Markdown View Source

Client for the Bubbles Push Notifications API.

Public API:

The API base URL is read from application config:

config :bubbles_notifications,
  base_url: "https://your-api.example.com"

Summary

Functions

Creates a notification for the initialized app.

Creates a notification for devices with the given user ID strings and for devices with at least one of the given alias strings.

Initializes a notification client with the app id and API key.

Creates a notification for the given device id.

Types

device_push_params()

@type device_push_params() :: message_params()

error_response()

@type error_response() :: %{status: pos_integer(), body: map()}

message_params()

@type message_params() :: %{title: String.t(), body: String.t(), data: map()}

notification()

@type notification() :: %{required(String.t()) => term()}

notification_params()

@type notification_params() :: message_params()

response()

@type response() :: {:ok, notification()} | {:error, error_response() | Exception.t()}

t()

@type t() :: %BubblesNotifications{
  api_key: String.t(),
  app_id: integer(),
  base_url: String.t(),
  headers: [{String.t(), String.t()}],
  receive_timeout: non_neg_integer()
}

Functions

create_notification(client, attrs)

@spec create_notification(t(), notification_params()) :: response()

Creates a notification for the initialized app.

The payload must include:

  • :title
  • :body
  • :data

:app_id is taken from the initialized client.

create_notification_user_ids_aliases(client, user_ids, aliases, attrs)

@spec create_notification_user_ids_aliases(
  t(),
  [String.t()],
  [String.t()],
  device_push_params()
) ::
  response()

Creates a notification for devices with the given user ID strings and for devices with at least one of the given alias strings.

The payload must include:

  • :title
  • :body
  • :data

:app_id is taken from the initialized client.

initialize(app_id, api_key)

@spec initialize(integer() | String.t() | charlist(), String.t() | charlist()) :: t()

Initializes a notification client with the app id and API key.

The base URL is loaded from Application.fetch_env!(:bubbles_notifications, :base_url).

Examples

iex> client = BubblesNotifications.initialize(42, "secret-token")
iex> client.app_id
42

send_push_to_device(client, device_id, attrs)

@spec send_push_to_device(
  t(),
  integer() | String.t() | charlist(),
  device_push_params()
) :: response()

Creates a notification for the given device id.

The payload must include:

  • :title
  • :body
  • :data

:app_id is taken from the initialized client.