Regula v0.1.0 Regula.Client View Source

A low-level Regula client that performs HTTP requests on the server API while providing a retry mechanism.

Retry attempts can be configured by adjusting client.max_attempts.

Link to this section Summary

Functions

Evaluates a ruleset against given parameters and (optional) version

Returns the headers carried by http requests to the server api

Lists all rulesets that matches the given prefix. Returns server’s response as a map

Link to this section Types

Link to this type t() View Source
t() :: %Regula.Client{
  endpoint: String.t(),
  http_client: module(),
  max_attempts: integer(),
  version: String.t()
}
Link to this type version() View Source
version() :: String.t() | nil

Link to this section Functions

Link to this function eval(client, path, params, version \\ nil) View Source
eval(t(), String.t(), map(), version()) ::
  {:ok, Regula.EvalResult.t()} | {:error, term()}

Evaluates a ruleset against given parameters and (optional) version.

Returns {:ok, %Regula.EvalResult{}}.

If there is an error, if will be retried if possible. After client.max_attemtps the error {:error, reason}is returned.

Link to this function headers(client) View Source
headers(t()) :: [tuple()]

Returns the headers carried by http requests to the server api.

Link to this function list(client, prefix, options \\ []) View Source
list(t(), String.t(), Keyword.t()) :: {:ok, term()} | {:error, term()}

Lists all rulesets that matches the given prefix. Returns server’s response as a map.

Options:

  • limit: max rulesets being returned
  • continue: token used when browsing further pages, allows to list the next limit rulesets

continue token can be found in the response of a list/3 call, given there are rulesets left.

If there is an error, if will be retried if possible. After client.max_attemtps the error {:error, reason}is returned.

Example

# Grab the first ten rulesets that start with "foo"
iex> Regula.list(client, "foo", limit: 10)
[
  %{
    "continue" => "Zm9vL2Jhci8xOG1OMGx5aWRLZEpibkZXQktGdDZBRmpGaDMA",
    "revision" => "6",
    "rulesets" => [...]
  }
]

# Grab the next ten rulesets that start with "foo"
iex> Regula.list(client, "foo", limit: 10, continue: "Zm9vL2Jhci8xOG1OMGx5aWRLZEpibkZXQktGdDZBRmpGaDMA")
[
  %{                    # no "continue" key, meaning we reached the end
    "revision" => "6",
    "rulesets" => [...]
  }
]