Xero.API.Runtime (Xero v1.0.0)

Copy Markdown View Source

Shared request/response plumbing for all Xero API resource modules.

This used to live inline inside Xero.API.Base's quote do ... end block and get re-injected (re-compiled, re-inferred) into every single resource module via use Xero.API.Base. That meant ~30 duplicate private copies of the same logic, each independently type-inferred by Dialyzer, and any diagnostic pointing into one of those copies collapsed onto the use call site instead of a real line (macro-injected code has no line metadata unless the quote uses location: :keep).

Pulling the logic out into a normal, single, fully-specced module fixes both problems: Dialyzer infers/checks this exactly once, and every diagnostic points at a real line in this file. Xero.API.Base now just injects trivial one-line delegates that close over the :api atom.

Summary

Functions

camelize(k)

@spec camelize(atom() | String.t()) :: String.t()

clean_params(params)

@spec clean_params(map() | keyword()) :: map()

delete(api, token, tenant_id, path)

@spec delete(atom(), Xero.Auth.Token.t(), String.t() | nil, String.t()) ::
  Xero.HTTP.Client.result()

format_list(list)

@spec format_list(nil | list()) :: String.t() | nil

get(api, token, tenant_id, path, params \\ %{})

@spec get(atom(), Xero.Auth.Token.t(), String.t() | nil, String.t(), map()) ::
  Xero.HTTP.Client.result()

get_modified(api, token, tenant_id, path, since, params \\ %{})

@spec get_modified(
  atom(),
  Xero.Auth.Token.t(),
  String.t() | nil,
  String.t(),
  DateTime.t() | String.t(),
  map()
) :: Xero.HTTP.Client.result()

ok_body(err)

@spec ok_body(Xero.HTTP.Client.result()) :: {:ok, term()} | {:error, Xero.Error.t()}

Decodes a JSON body on success; passes non-JSON bodies through raw (e.g. PDF).

ok_xml(err)

@spec ok_xml(Xero.HTTP.Client.result()) :: {:ok, term()} | {:error, Xero.Error.t()}

Passes the body through raw and undecoded — for XML-returning endpoints.

post(api, token, tenant_id, path, body)

@spec post(atom(), Xero.Auth.Token.t(), String.t() | nil, String.t(), term()) ::
  Xero.HTTP.Client.result()

put(api, token, tenant_id, path, body)

@spec put(atom(), Xero.Auth.Token.t(), String.t() | nil, String.t(), term()) ::
  Xero.HTTP.Client.result()

url(api, path)

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