Codat.RateLimit (codat v1.0.0)

Copy Markdown View Source

Rate limit information extracted from Codat API response headers.

Headers

HeaderDescription
X-Rate-Limit-LimitDaily request allowance (1000 × (1 + ACCs))
X-Rate-Limit-RemainingRequests remaining today
X-Rate-Limit-ResetUnix timestamp when the limit resets (00:00 UTC)

ACCs = Active Connected Companies.

Summary

Functions

Returns true if fewer than threshold requests remain today.

Parses rate limit info from a list of HTTP response headers. Returns nil if no rate limit headers are present.

Returns the number of seconds until the rate limit resets, or nil.

Types

t()

@type t() :: %Codat.RateLimit{
  exhausted?: boolean(),
  limit: non_neg_integer() | nil,
  remaining: non_neg_integer() | nil,
  reset_timestamp: non_neg_integer() | nil,
  resets_at: DateTime.t() | nil
}

Functions

approaching?(rate_limit, opts \\ [])

@spec approaching?(
  t(),
  keyword()
) :: boolean()

Returns true if fewer than threshold requests remain today.

Options

  • :threshold — the minimum remaining requests (default: 100)

from_headers(headers)

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

Parses rate limit info from a list of HTTP response headers. Returns nil if no rate limit headers are present.

seconds_until_reset(rate_limit)

@spec seconds_until_reset(t()) :: non_neg_integer() | nil

Returns the number of seconds until the rate limit resets, or nil.