Trifolium.API (Trifolium v1.0.0)

Thin helper functions to enhance requests to Trefle API.

Link to this section Summary

Functions

Builds a query params map, which contains the token used to communicate with Trefle API, along with the keywords which should be passed to Trefle API. Accepts a nested map, which in this case will build the parameters according to the nested rules allowed on Trefle API. Also accepts a list as a possible parameter, stringifying it.

Parse a response returned by Trefle API in a JSON, in a correct fashion, according to the status_code returned

Link to this section Types

Specs

response() :: {:ok, %{}} | {:error, non_neg_integer(), %{}}

Link to this section Functions

Link to this function

build_query_params(query_opts \\ [])

Specs

build_query_params(any()) :: %{:token => binary(), optional(any()) => any()}

Builds a query params map, which contains the token used to communicate with Trefle API, along with the keywords which should be passed to Trefle API. Accepts a nested map, which in this case will build the parameters according to the nested rules allowed on Trefle API. Also accepts a list as a possible parameter, stringifying it.

Link to this function

parse_response(arg)

Specs

parse_response({:ok, map()}) :: response()

Parse a response returned by Trefle API in a JSON, in a correct fashion, according to the status_code returned

If the status_code field from the request is 200 or 201, returns {:ok, %{}}. If the status_code field from the request is 404, returns {:error, 404, %{message: message} where message is the returned value from Trefle. If any status other than 200 or 404 is returned on status_code we return {:error, status, message} where :status is the status_code returned, and you hould handle the error yourself. The message part of the tuple is the body returned by the request.