Unicom360 (Unicom360 v0.1.0)

Copy Markdown View Source

The official Elixir client for the Unicom360 API: SMS, email and WhatsApp over one JSON API.

{:ok, client} = Unicom360.client()  # reads UNICOM360_API_KEY

{:ok, result} =
  Unicom360.SMS.send(client, %{
    from: "Unicom360",
    to: "260971234567",
    message: "Your order ZM4821 is ready."
  })

Every operation takes the client first and returns {:ok, result} or {:error, %Unicom360.Error{}}; each has a ! variant that returns the result or raises.

OperationFunctionReturns
Send an SMSUnicom360.SMS.send/3Unicom360.SMS.SendResult
Send an emailUnicom360.Email.send/3Unicom360.Email.SendResult
Send a WhatsApp templateUnicom360.WhatsApp.send_template/3Unicom360.WhatsApp.TemplateSendResult
Send a WhatsApp session messageUnicom360.WhatsApp.send_session/3Unicom360.WhatsApp.SessionSendResult
WhatsApp message statusUnicom360.WhatsApp.status/3Unicom360.WhatsApp.StatusResult
WhatsApp templatesUnicom360.WhatsApp.templates/2Unicom360.WhatsApp.TemplateList
One balanceUnicom360.Balance.get/2Unicom360.Balance
Every balanceUnicom360.Balance.all/2Unicom360.Balances
Healthhealth/2Unicom360.Health

Webhooks and delivery reports are in Unicom360.Webhook, the opt-in GSM-7 helpers in Unicom360.GSM. There is no sandbox: every accepted send is real and billed.

Summary

Functions

Builds a client. See Unicom360.Client for every option.

Like client/1, but returns the client or raises Unicom360.Error.

The version of the Unicom360 API contract (openapi.yaml and its conformance suite) this SDK targets.

Checks that the API is up (GET /health). Sends no API key.

Like health/2, but returns the result or raises Unicom360.Error.

The SDK's version.

Functions

client(opts \\ [])

@spec client([Unicom360.Client.option()]) ::
  {:ok, Unicom360.Client.t()} | {:error, Unicom360.Error.t()}

Builds a client. See Unicom360.Client for every option.

{:ok, client} = Unicom360.client()
{:ok, client} = Unicom360.client(api_key: "...", max_retries: 4)

Returns {:error, %Unicom360.Error{type: :configuration_error}} when no API key is found or an option is unusable.

client!(opts \\ [])

Like client/1, but returns the client or raises Unicom360.Error.

contract_version()

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

The version of the Unicom360 API contract (openapi.yaml and its conformance suite) this SDK targets.

health(client, opts \\ [])

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

Checks that the API is up (GET /health). Sends no API key.

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

health!(client, opts \\ [])

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

Like health/2, but returns the result or raises Unicom360.Error.

version()

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

The SDK's version.