Txbox v0.2.0 Txbox.Transactions View Source

Collection of functions for composing Ecto queries.

The functions in this module can be broadly split into two types, expressions and queries.

Expressions

Expression functions can be used to compose queries following the Elixir pipeline syntax.

iex> Tx
...> |> Transactions.confirmed(true)
...> |> Transactions.tagged(["space", "photos"])
%Ecto.Query{}

Queries

Query functions interface with the repo and either create or return records from the repo.

iex> Transactions.list_tx()
[%Tx{}, ...]

Link to this section Summary

Expressions

Query by the given channel name.

Query by the transaction confirmation status.

Query by the given query map.

Search by the given term.

Query by the given tag or list of tags.

Queries

Creates a transaction from the given params.

Deletes the given transaction from the repo.

Get a transaction by it's internal ID or TXID.

Returns a list of transactions.

Returns a list of transactions that must be pushed or have their status confirmed by mAPI.

Returns a list of transactions filtered by the given search term.

Updates the transaction with the given params.

Updates the given transaction's state.

Updates the given transaction's state, and stores the mAPI response.

Functions

Returns the application's configured Repo.

Link to this section Expressions

Specs

Query by the given channel name.

Link to this function

confirmed(tx, conf \\ true)

View Source

Specs

Query by the transaction confirmation status.

Specs

Query by the given query map.

Specs

Search by the given term.

Specs

Query by the given tag or list of tags.

Optionally tags can be specified as a comma seperated string

Link to this section Queries

Specs

create_tx(map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Creates a transaction from the given params.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.create_tx(%{
...>   txid: "6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110",
...>   channel: "mychannel"
...> })

Specs

delete_tx(Ecto.Schema.t()) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Deletes the given transaction from the repo.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.get_tx("6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110")
...> |> Transactions.delete_tx

Specs

get_tx(Ecto.Queryable.t(), binary()) :: Ecto.Schema.t() | nil

Get a transaction by it's internal ID or TXID.

Can optionally pass a Ecto.Queryable.t as the first argument to compose queries.

Examples

# Find a tx by it's Txbox uuid
iex> tx = Transactions.find_tx "e9d356cf-47e9-47c3-bfc8-c12673877302"

# Composed query, found by txid
iex> tx = Transactions.channel("mychannel)
...> |> Transactions.confirmed(true)
...> |> Transactions.find_tx("6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110")
Link to this function

list_tx(tx \\ Tx, params)

View Source

Specs

list_tx(Ecto.Queryable.t(), map()) :: [Ecto.Schema.t()]

Returns a list of transactions.

Can optionally pass a Ecto.Queryable.t as the first argument to compose queries. If a map of query options is given as a secndon argument, the query is filtered by those arguments.

Examples

iex> txns = Transactions.channel("mychannel)
...> |> Transactions.confirmed(true)
...> |> Transactions.list_tx
Link to this function

list_tx_for_mapi(opts \\ [])

View Source

Specs

list_tx_for_mapi(keyword()) :: [Ecto.Schema.t()]

Returns a list of transactions that must be pushed or have their status confirmed by mAPI.

This is used internally by Txbox.Mapi.Queue to fetch transactions for automatic processing.

Options

The accepted options are:

  • :max_status_attempts - How many times to poll mAPI for confirmation status. Defaults to 20.
  • :retry_status_after - Number of seconds before polling mAPI for confirmation status. Defaults to 300 (5 minutes).
Link to this function

search_tx(tx \\ Tx, term)

View Source

Specs

search_tx(Ecto.Queryable.t(), String.t()) :: [Ecto.Schema.t()]

Returns a list of transactions filtered by the given search term.

Performs a full text search on the transactions' metadata. Can optionally pass a Ecto.Queryable.t as the first argument to compose queries.

Examples

iex> {:ok, txns} = Transactions.search_tx("unwriter bitpic")
Link to this function

update_tx(tx, attrs \\ %{})

View Source

Specs

update_tx(Ecto.Schema.t(), map()) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Updates the transaction with the given params.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.update_tx(tx, %{
...>   meta: %{
...>     title: "Hubble Ultra-Deep Field"
...>   }
...> })
Link to this function

update_tx_state(tx, state)

View Source

Specs

update_tx_state(Ecto.Schema.t(), String.t()) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Updates the given transaction's state.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.update_tx_state(tx, "pushed")
Link to this function

update_tx_state(tx, state, mapi_response)

View Source

Specs

update_tx_state(Ecto.Schema.t(), String.t(), Manic.JSONEnvelope.t() | map()) ::
  {:ok, Ecto.Schema.t()}
  | {:error, Ecto.Changeset.t()}
  | {:error, %{required(atom()) => Ecto.Changeset.t()}}

Updates the given transaction's state, and stores the mAPI response.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.update_tx_state(tx, "pushed", mapi_response)

Link to this section Functions

Specs

repo() :: module()

Returns the application's configured Repo.

Ensure your application's Repo is configured in config.exs:

config :txbox, repo: MyApp.Repo