GelotvBot.API (GeloTVBot v0.1.0)

Copy Markdown View Source

Shared helpers for dependency-free platform API clients.

Summary

Functions

Decodes a raw HTTP client response, preserving the original response fields.

Sends a request and decodes a JSON response body.

Types

request_option()

@type request_option() ::
  {:params, map() | keyword()}
  | {:body, term()}
  | {:body_format, :json | :form | :raw}
  | {:content_type, String.t()}
  | {:headers, [{String.t(), String.t()}]}
  | {:http_client, module()}
  | {:base_url, String.t()}

Functions

bearer(token)

@spec bearer(String.t() | nil) :: [{String.t(), String.t()}]

build_url(base_url, path, params \\ [])

@spec build_url(String.t(), String.t(), map() | keyword()) :: String.t()

decode_response(arg)

@spec decode_response(GelotvBot.HTTPClient.response()) ::
  {:ok, map()} | {:error, term()}

Decodes a raw HTTP client response, preserving the original response fields.

form_headers()

@spec form_headers() :: [{String.t(), String.t()}]

json_headers()

@spec json_headers() :: [{String.t(), String.t()}]

request(method, url, opts)

@spec request(atom(), String.t(), keyword()) :: GelotvBot.HTTPClient.response()

request_decoded(method, url, opts)

@spec request_decoded(atom(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Sends a request and decodes a JSON response body.

The returned response keeps the original :body and adds :decoded_body. Non-2xx HTTP responses are returned as {:error, {:http_error, status, body}}.