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
response()
Specs
response() :: {:ok, %{}} | {:error, non_neg_integer(), %{}}
Link to this section Functions
build_query_params(query_opts \\ [])
Specs
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_response(arg)
Specs
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.