GoCardlessClient.Resource (GoCardlessClient v2.0.0)

Copy Markdown View Source

Shared HTTP helpers for GoCardlessClient resource modules.

GoCardless uses only GET and POST — there is no PUT, PATCH, or DELETE (except DELETE /customers/:id for GDPR erasure). All update operations use POST /resource/:id and all action endpoints use POST /resource/:id/actions/:name.

Summary

Functions

POST to an action endpoint: path/actions/name.

Encodes a map of params into a URL query string, dropping nil values.

GET a single resource and unwrap its envelope.

GET a list resource; returns {:ok, %{items: [...], meta: {...}}}.

POST to create a resource, wrapping params in %{key => params}.

POST to update a resource (GoCardless uses POST, not PUT/PATCH, for updates).

Types

error_response()

@type error_response() ::
  {:error, GoCardlessClient.APIError.t() | GoCardlessClient.Error.t()}

list_response()

@type list_response() :: {:ok, %{items: [map()], meta: map()}} | error_response()

response()

@type response() :: {:ok, map() | list() | nil} | error_response()

Functions

action(client, path, name, key, params, opts \\ [])

@spec action(
  GoCardlessClient.Client.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  keyword()
) ::
  response()

POST to an action endpoint: path/actions/name.

Wraps params in %{resource_key => params} as required by the GoCardless API. The envelope key is the resource key (e.g. "billing_requests"), NOT "data".

build_query(p)

@spec build_query(map()) :: String.t()

Encodes a map of params into a URL query string, dropping nil values.

delete(client, path, key, opts \\ [])

DELETE a resource.

Only used for GDPR customer erasure (DELETE /customers/:id). All other "deletions" in GoCardless are POST actions (cancel, disable, etc.).

get(client, path, key, opts \\ [])

GET a single resource and unwrap its envelope.

list(client, path, key, params \\ %{}, opts \\ [])

GET a list resource; returns {:ok, %{items: [...], meta: {...}}}.

post(client, path, key, params, opts \\ [])

POST to create a resource, wrapping params in %{key => params}.

GoCardless wraps both creates and updates in the resource envelope key.

update(client, path, key, params, opts \\ [])

@spec update(GoCardlessClient.Client.t(), String.t(), String.t(), map(), keyword()) ::
  response()

POST to update a resource (GoCardless uses POST, not PUT/PATCH, for updates).

Wraps params in %{key => params} exactly like post/5.