Regula v0.1.0 Regula View Source

A Regula client.

The functions in this module evaluate params against a ruleset and a (optional) version then returns the result in a specific type. They hit Regula’s HTTP API and perform at most client.max_attempts if the error is retriable.

Returns {:ok, casted_result, %Regula.EvalResult.t()} so you can inspect the version of the ruleset that was evaluated or the server error that prevented evaluation.

For example, if an integer (64bits) returning ruleset is called with get_string/4, it will return an error {:error, term}.

Link to this section Summary

Functions

Creates a client based on given options. Available options are

Evaluates a given ruleset, params and (optional) version and returns a boolean along with evaluation result for details. If a network or server error happen, an {:error, term} is returned

Evaluates a given ruleset, params and (optional) version and returns a float along with evaluation result for details. If a network or server error happen, an {:error, term} is returned

Evaluates a given ruleset, params and (optional) version and returns an integer along with evaluation result for details. If a network or server error happen, an {:error, term} is returned

Evaluates a given ruleset, params and (optional) version and returns a string along with evaluation result for details. If a network or server error happen, an {:error, term} is returned

Returns a list of rulesets. See Regula.Client.list/3 for more details

Link to this section Types

Link to this type version() View Source
version() :: String.t() | nil

Link to this section Functions

Creates a client based on given options. Available options are:

  • endpoint: url of a regula server
  • max_attempts (defaults to 3): max number of attempts made on retriable errors (like network issues).
  • http_client (optional): a module implementing Regula.HTTPClient behaviour. Used for testing purposes related to transport errors.
Link to this function get_bool(client, ruleset, params, version \\ nil) View Source
get_bool(Regula.Client.t(), ruleset(), params(), version()) ::
  {:ok, boolean(), Regula.EvalResult.t()} | {:error, term()}

Evaluates a given ruleset, params and (optional) version and returns a boolean along with evaluation result for details. If a network or server error happen, an {:error, term} is returned.

Link to this function get_float(client, ruleset, params, version \\ nil) View Source
get_float(Regula.Client.t(), ruleset(), params(), version()) ::
  {:ok, float(), Regula.EvalResult.t()} | {:error, term()}

Evaluates a given ruleset, params and (optional) version and returns a float along with evaluation result for details. If a network or server error happen, an {:error, term} is returned.

Link to this function get_int(client, ruleset, params, version \\ nil) View Source
get_int(Regula.Client.t(), ruleset(), params(), version()) ::
  {:ok, integer(), Regula.EvalResult.t()} | {:error, term()}

Evaluates a given ruleset, params and (optional) version and returns an integer along with evaluation result for details. If a network or server error happen, an {:error, term} is returned.

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

Evaluates a given ruleset, params and (optional) version and returns a string along with evaluation result for details. If a network or server error happen, an {:error, term} is returned.

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

Returns a list of rulesets. See Regula.Client.list/3 for more details.