Picnic.Client (Picnic v0.1.0)

Copy Markdown View Source

The client struct — plain data, not a process.

new/1 resolves configuration once (see Picnic.Config) and stores a base Req.Request template on the struct. Every request merges onto that template, so there is no global state and nothing to start or supervise. Resource functions take the client as their first argument and, where a call changes it (login), return an updated client.

Options

  • :country - Country whose storefront to talk to. Defaults to :nl.

  • :api_version (String.t/0) - Path version segment of the API, e.g. "15".

  • :base_url (String.t/0) - Full base URL including the version segment. Overrides :country/:api_version.

  • :client_id (integer/0) - Client id sent with the login payload.

  • :headers (map of String.t/0 keys and String.t/0 values) - Extra or replacement default headers, merged over the built-in ones.

  • :auth_token (String.t/0) - A previously obtained token; lets you skip Picnic.login/3 entirely.

  • :req_options (keyword/0) - Options merged into the underlying Req request template (retry tuning, plug, …).

Reusing a token

The auth token is plain data on the struct. Persist client.auth_token wherever you like and rebuild a logged-in client later with Picnic.Client.new(auth_token: token).

Summary

Functions

Builds a new client. Raises NimbleOptions.ValidationError on invalid options; see the module documentation for the accepted ones.

Returns a client that authenticates subsequent requests with token.

Types

t()

@type t() :: %Picnic.Client{
  auth_token: String.t() | nil,
  base_url: String.t(),
  config: Picnic.Config.t(),
  headers: %{required(String.t()) => String.t()},
  req: Req.Request.t()
}

Functions

new(opts \\ [])

@spec new(keyword()) :: t()

Builds a new client. Raises NimbleOptions.ValidationError on invalid options; see the module documentation for the accepted ones.

put_token(client, token)

@spec put_token(t(), String.t() | nil) :: t()

Returns a client that authenticates subsequent requests with token.