Zazu.Client (zazu v0.2.1)

Copy Markdown View Source

The SDK entry point. Build one with Zazu.new/1 and pass it as the first argument to every resource function (Zazu.Accounts, Zazu.Invoices, ...).

Summary

Functions

Joins path segments, URI-escaping each one. Segments may contain literal / separators ("api/invoices"); everything between separators is escaped.

Performs an HTTP request against the API.

Types

t()

@type t() :: %Zazu.Client{
  api_key: String.t(),
  api_version: String.t() | nil,
  base_url: String.t(),
  timeout: pos_integer()
}

Functions

encode_path(segments)

@spec encode_path([String.t()]) :: String.t()

Joins path segments, URI-escaping each one. Segments may contain literal / separators ("api/invoices"); everything between separators is escaped.

request(client, method, path, query \\ [], body \\ nil)

@spec request(t(), atom(), String.t(), keyword() | map(), map() | nil) ::
  {:ok, Zazu.Response.t()} | {:error, Exception.t()}

Performs an HTTP request against the API.

Non-2xx responses come back as {:error, %Zazu.Error{}}; transport failures as {:error, %Zazu.ConnectionError{}}. body (when non-nil) is JSON-encoded.