Lettermint (Lettermint v2.0.0)

Copy Markdown View Source

The Lettermint client.

lettermint =
  Lettermint.new(
    sending_token: System.get_env("LETTERMINT_PROJECT_TOKEN"),
    team_token: System.get_env("LETTERMINT_TEAM_TOKEN")
  )

lettermint = Lettermint.new("lm_...")  # team or sending token, detected by its format

Pass the client as the first argument to the SDK's functions:

The SDK never falls back to the other token. When the token a function needs is missing, it raises Lettermint.ConfigError before any request.

Functions that call the API return {:ok, result} (or :ok when the API answers without a body) or {:error, error}; see Lettermint.Error.

Summary

Functions

Queries email analytics. Needs :team_token.

The file extensions and MIME types that cannot be attached. Needs :team_token.

Creates a client from options or from a token string.

Creates a client from a token string and options. See new/1.

Checks the configured token: GET /ping returns "pong". Uses the team token when configured, otherwise the sending token.

Functions

analytics(client, query, options \\ [])

Queries email analytics. Needs :team_token.

blocked_file_types(client, options \\ [])

@spec blocked_file_types(Lettermint.Client.t(), [{:timeout, pos_integer()}]) ::
  {:ok, Lettermint.Types.BlockedFileTypes.t()} | {:error, Lettermint.Error.t()}

The file extensions and MIME types that cannot be attached. Needs :team_token.

new(token_or_options)

@spec new(String.t() | keyword()) :: Lettermint.Client.t()

Creates a client from options or from a token string.

Options

  • :sending_token: a project sending token (lm_...), for Lettermint.Emails
  • :team_token: a team API token (lm_team_...), for the Team API
  • :base_url: default "https://api.lettermint.co/v1"
  • :timeout: milliseconds, default 30_000. It covers the whole request, including reading the body. Each call can override it with timeout:.
  • :adapter: the HTTP adapter, a module or {module, options}; default Lettermint.Adapter.Req. See Lettermint.Adapter.

Pass at least one token. With a token string, the SDK picks the token type by its format: lm_team_ followed by letters and digits is a team token, lm_ followed by letters and digits a sending token. Any other format, such as an SSO token (lm_sso_...), raises Lettermint.ConfigError; pass it with :sending_token or :team_token instead. Errors never contain the token.

Lettermint.new(sending_token: token)
Lettermint.new(token, timeout: 10_000)

new(token, options)

@spec new(String.t(), keyword()) :: Lettermint.Client.t()

Creates a client from a token string and options. See new/1.

ping(client, options \\ [])

@spec ping(Lettermint.Client.t(), [{:timeout, pos_integer()}]) ::
  {:ok, String.t()} | {:error, Lettermint.Error.t()}

Checks the configured token: GET /ping returns "pong". Uses the team token when configured, otherwise the sending token.