Xero.API.Base (Xero v1.0.0)

Copy Markdown View Source

Shared __using__ macro for all Xero API resource modules.

Injects req_get/4, post/4, put/4, req_delete/3, ok_body/1, url/1 and the base_url/0 helper derived from the :api option.

The request helpers are prefixed with req_ (req_get, req_get_modified, req_delete) so they don't collide with the public get/3, get/4, and delete/3 functions that resource modules define for their own API surface.

All real logic lives in Xero.API.Runtime, a plain (non-macro) module — what's injected here is only thin, single-clause delegates that close over the :api atom. Keeping the actual implementation out of the quote block means Dialyzer type-checks it exactly once instead of once per use call site, and any diagnostic on the real logic points at a real line in runtime.ex instead of collapsing onto every module's use line.

Usage

defmodule Xero.Accounting.Invoices do
  use Xero.API.Base, api: :accounting
  # now has access to req_get/post/put/req_delete/ok_body/url helpers
end