Current section
Files
Jump to
Current section
Files
lib/teac/api/extensions/transactions.ex
defmodule Teac.Api.Extensions.Transactions do
alias Teac.Api
@schema NimbleOptions.new!(
extension_id: [type: :string, required: true],
id: [type: :string],
after: [type: :string],
first: [type: :pos_integer]
)
@doc """
Gets the list of transactions for an extension.
## Authorization
Requires an app access token.
## Options
* `:extension_id` - required. The ID of the extension whose transactions to get.
* `:id` - optional. Filter to a specific transaction ID.
* `:first` - optional. Maximum items to return. Default: 20, max: 100.
* `:after` - optional. Cursor for forward pagination.
"""
@spec get(Teac.Client.t(), keyword()) ::
{:ok, list(map()), String.t() | nil} | {:error, Teac.Error.t()}
def get(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @schema) do
{:ok, opts} ->
params =
[
extension_id: opts[:extension_id],
id: opts[:id],
after: opts[:after],
first: opts[:first]
]
|> Enum.reject(fn {_, v} -> is_nil(v) end)
[
base_url: Api.uri("extensions/transactions"),
params: params,
headers: Api.headers(client)
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.get!()
|> Api.handle_paginated_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
@doc "Streams all extension transactions, automatically following pagination cursors."
@spec stream(Teac.Client.t(), keyword()) :: Enumerable.t()
def stream(%Teac.Client{} = client, opts \\ []) do
Teac.Api.Pagination.stream(client, &get/2, opts)
end
end