Shared plumbing used internally by every resource module
(TreasuryPrime.Account, TreasuryPrime.Ach, TreasuryPrime.Card, ...)
to implement list/2, get/2, create/2, update/3, and delete/2 in
terms of TreasuryPrime.HTTP.
This module is not meant to be called directly by consumers of the
library — it exists purely so the ~45 resource modules don't each
reimplement "make the request, cast the response into my struct, maybe
wrap it in a Page" from scratch. Each resource module remains a normal,
explicit, fully-documented module with its own struct and typespecs; only
the repetitive HTTP/casting plumbing is shared.
Summary
Functions
Casts a raw, string-keyed JSON map (as decoded by Jason) into module's
struct, using module.__fields__/0 as an allowlist of known atoms. This
is deliberately not String.to_existing_atom/1 over arbitrary input —
every atom involved is already known at compile time from the resource
module's own field list, so there's no atom-exhaustion risk even though
the input map's keys come from the network.
POST to create a resource.
DELETE a resource by id. Returns {:ok, nil} on success (Treasury Prime returns an empty body).
GET a single resource by id.
GET a list/collection endpoint, returning a TreasuryPrime.Page.
PATCH to update a resource by id.
Functions
Casts a raw, string-keyed JSON map (as decoded by Jason) into module's
struct, using module.__fields__/0 as an allowlist of known atoms. This
is deliberately not String.to_existing_atom/1 over arbitrary input —
every atom involved is already known at compile time from the resource
module's own field list, so there's no atom-exhaustion risk even though
the input map's keys come from the network.
Unknown keys returned by the API (Treasury Prime explicitly documents that it may add undocumented fields to responses over time) are silently ignored rather than raising — forward compatibility over strictness.
@spec create(TreasuryPrime.Client.t(), String.t(), module(), map(), keyword()) :: {:ok, struct()} | {:error, TreasuryPrime.Error.t()}
POST to create a resource.
@spec delete(TreasuryPrime.Client.t(), String.t(), String.t(), keyword()) :: {:ok, nil} | {:error, TreasuryPrime.Error.t()}
DELETE a resource by id. Returns {:ok, nil} on success (Treasury Prime returns an empty body).
@spec delete!(TreasuryPrime.Client.t(), String.t(), String.t(), keyword()) :: nil
@spec get(TreasuryPrime.Client.t(), String.t(), module(), String.t(), keyword()) :: {:ok, struct()} | {:error, TreasuryPrime.Error.t()}
GET a single resource by id.
@spec list(TreasuryPrime.Client.t(), String.t(), module(), map()) :: {:ok, TreasuryPrime.Page.t()} | {:error, TreasuryPrime.Error.t()}
GET a list/collection endpoint, returning a TreasuryPrime.Page.
@spec list!(TreasuryPrime.Client.t(), String.t(), module(), map()) :: TreasuryPrime.Page.t()
@spec update( TreasuryPrime.Client.t(), String.t(), module(), String.t(), map(), keyword() ) :: {:ok, struct()} | {:error, TreasuryPrime.Error.t()}
PATCH to update a resource by id.