Unicom360.Balance (Unicom360 v0.1.0)

Copy Markdown View Source

Account balances (POST /api/v1/json/balance and /balance/all), and the struct get/2 returns (canonical name Balance).

{:ok, %Unicom360.Balance{balance: balance}} = Unicom360.Balance.get(client)
{:ok, whatsapp} = Unicom360.Balance.get(client, bundle_type: "WHATSAPP")
{:ok, %Unicom360.Balances{balances: balances}} = Unicom360.Balance.all(client)

Balances are Decimals, exactly as the gateway sent them. Bundle types: "SMS" (the default), "SMS_INTERNATIONAL", "EMAIL" and "WHATSAPP".

Fields of %Unicom360.Balance{}: message, balance (a Decimal), bundle_type, client_id, client_name, raw and extra.

Summary

Functions

Every balance, as a map from bundle type to Decimal.

Like all/2, but returns the balances or raises Unicom360.Error.

The email bundle type.

One balance: the SMS bundle, or the bundle given as bundle_type:.

Like get/2, but returns the balance or raises Unicom360.Error.

The SMS bundle type.

The international SMS bundle type.

The WhatsApp bundle type.

Types

t()

@type t() :: %Unicom360.Balance{
  balance: Decimal.t() | nil,
  bundle_type: String.t() | nil,
  client_id: String.t() | nil,
  client_name: String.t() | nil,
  extra: map(),
  message: String.t() | nil,
  raw: map()
}

Functions

all(client, opts \\ [])

@spec all(Unicom360.Client.t(), keyword()) ::
  {:ok, Unicom360.Balances.t()} | {:error, Unicom360.Error.t()}

Every balance, as a map from bundle type to Decimal.

Options: :timeout (ms per attempt) and :max_retries.

all!(client, opts \\ [])

Like all/2, but returns the balances or raises Unicom360.Error.

email()

@spec email() :: String.t()

The email bundle type.

get(client, opts \\ [])

@spec get(Unicom360.Client.t(), keyword()) ::
  {:ok, t()} | {:error, Unicom360.Error.t()}

One balance: the SMS bundle, or the bundle given as bundle_type:.

Options: :bundle_type, :timeout (ms per attempt) and :max_retries. A refusal (for example code: "CLIENT_NOT_FOUND") is an :api_error with no api_reference.

get!(client, opts \\ [])

@spec get!(Unicom360.Client.t(), keyword()) :: t()

Like get/2, but returns the balance or raises Unicom360.Error.

sms()

@spec sms() :: String.t()

The SMS bundle type.

sms_international()

@spec sms_international() :: String.t()

The international SMS bundle type.

whatsapp()

@spec whatsapp() :: String.t()

The WhatsApp bundle type.