BrazeEx.RequestBuilder (braze_ex v1.0.4)

Helper functions for building Tesla requests

Link to this section Summary

Functions

Add optional parameters to the request.

Add non-optional parameters to the request.

This function ensures that the body parameter is always set.

Evaluate the response from a Tesla request. Decode the response for a Tesla request.

Specify the request method when building a request.

Specify the request URL when building a request.

Link to this section Types

Link to this type

response_mapping()

@type response_mapping() :: [{status_code(), struct() | false}]
Link to this type

status_code()

@type status_code() :: 100..599

Link to this section Functions

Link to this function

add_optional_params(request, definitions, list)

@spec add_optional_params(map(), %{optional(atom()) => atom()}, keyword()) :: map()

Add optional parameters to the request.

parameters

Parameters

  • request (Map) - Collected request options
  • definitions (Map) - Map of parameter name to parameter location.
  • options (KeywordList) - The provided optional parameters

returns

Returns

Map

Link to this function

add_param(request, location, key, value)

@spec add_param(map(), atom(), atom(), any()) :: map()

Add non-optional parameters to the request.

parameters

Parameters

  • request (Map) - Collected request options
  • location (atom) - Where to put the parameter
  • key (atom) - The name of the parameter
  • value (any) - The value of the parameter

returns

Returns

Map

Link to this function

ensure_body(request)

@spec ensure_body(map()) :: map()

This function ensures that the body parameter is always set.

When using Tesla with the httpc adapter (the default adapter), there is a bug where POST, PATCH and PUT requests will fail if the body is empty.

parameters

Parameters

  • request (Map) - Collected request options

returns

Returns

Map

Link to this function

evaluate_response(error, mapping)

@spec evaluate_response(Tesla.Env.result(), response_mapping()) ::
  {:ok, struct()} | Tesla.Env.result()

Evaluate the response from a Tesla request. Decode the response for a Tesla request.

parameters

Parameters

  • result (Tesla.Env.result()): The response from Tesla.request/2.
  • mapping ([{http_status, struct}]): The mapping for status to struct for decoding.

returns

Returns

  • {:ok, struct} or {:ok, Tesla.Env.t()} on success
  • {:error, term} on failure
Link to this function

method(request, method)

@spec method(map(), atom()) :: map()

Specify the request method when building a request.

Does not override the method if one has already been specified.

parameters

Parameters

  • request (Map) - Collected request options
  • method (atom) - Request method

returns

Returns

Map

Link to this function

url(request, url)

@spec url(map(), String.t()) :: map()

Specify the request URL when building a request.

Does not override the url if one has already been specified.

parameters

Parameters

  • request (Map) - Collected request options
  • url (String) - Request URL

returns

Returns

Map