Lettermint.Types (Lettermint v2.1.0)

Copy Markdown View Source

The API types, and helpers to convert them.

Lettermint.Types.* is generated from the Lettermint API specification (lib/lettermint/generated/types.ex). Responses decode into these structs:

  • Every field defaults to :unset. A field the API did not send stays :unset; JSON null is nil.
  • extra holds response fields that this version of the SDK does not know, with string keys.
  • Enums are open: a value the API adds later decodes as its string. values/0 on an enum module lists the values known to the SDK.
  • Decoding never creates atoms from response data, and never fails on an unexpected value: a value of another type than documented is kept as decoded from JSON.
  • Every list response is a Lettermint.Types.CursorPage, whose data holds the items.

Requests take these structs or plain maps with atom or string keys, in the API's field names (reply_to, scheduled_at, ...).

Summary

Functions

Decodes JSON data (string keys, as from Jason.decode/1) into a type.

Converts a struct (or a map or list holding structs) to JSON-ready data with string keys, in the API's field names. :unset fields are left out, nil stays nil (JSON null) and extra fields are kept.

Functions

decode(value, module)

@spec decode(term(), module()) :: term()

Decodes JSON data (string keys, as from Jason.decode/1) into a type.

iex> Lettermint.Types.decode(%{"domain" => "acme.com", "new" => 1}, Lettermint.Types.DomainData)
%Lettermint.Types.DomainData{domain: "acme.com", extra: %{"new" => 1}}

to_map(struct)

@spec to_map(term()) :: term()

Converts a struct (or a map or list holding structs) to JSON-ready data with string keys, in the API's field names. :unset fields are left out, nil stays nil (JSON null) and extra fields are kept.

iex> Lettermint.Types.to_map(%Lettermint.Types.StoreDomainData{domain: "acme.com"})
%{"domain" => "acme.com"}