OpenFeed.Sharing (OpenFeed v0.1.0)

Copy Markdown View Source

The OpenFeed sharing API — one function per endpoint.

Every function takes an OpenFeed.Config and an access token. Collections return every page as a list; single resources return the unwrapped data.

For a collection that could be large, OpenFeed.Client.stream/4 pages lazily instead:

OpenFeed.Client.stream(config, token, "/v1/banking/accounts/#{id}/transactions")
|> Stream.each(&store!/1)
|> Stream.run()

Scopes

FunctionsScope
banking_*openfeed-au:data:banking:read
energy_*openfeed-au:data:energy:read
grant/3openfeed-au:grant:self:query
revoke_grant/3openfeed-au:grant:self:revoke
app/2openfeed-au:app:all:read (client credentials)
app_grants/2openfeed-au:grant:all:list (client credentials)

The app_* functions need a client-credentials token from OpenFeed.Auth.client_credentials_token/2, not a consumer's grant-bound one.

Costs

Balances are not mirrored: OpenFeed fetches them from the data holder on demand and caches for around 15 minutes. They are the slowest calls here, and can fail with :balance_unavailable when the data holder is down while every other endpoint works fine. Do not fetch balances in a tight loop.

Summary

Types

An access token. Prefer the OpenFeed.Tokens struct — it carries the token_type OpenFeed issued, which the transport needs to pick the right authorization scheme. See OpenFeed.Client.token_type/2.

Functions

Get your app's registration. Needs a client-credentials token.

List every grant belonging to your app.

List the consumer's banking accounts.

Get a banking account's current balance.

List transactions for a banking account.

List the consumer's energy accounts.

Get an energy account's current balance. See banking_balance/4 on cost.

List billing transactions for an energy account.

Get a meter's distributed energy resource (DER) configuration.

List invoices for an energy account.

List meters for an energy account.

Types

result(t)

@type result(t) :: {:ok, t} | {:error, OpenFeed.Error.t()}

token()

@type token() :: OpenFeed.Client.token()

An access token. Prefer the OpenFeed.Tokens struct — it carries the token_type OpenFeed issued, which the transport needs to pick the right authorization scheme. See OpenFeed.Client.token_type/2.

Functions

app(config, token, opts \\ [])

@spec app(OpenFeed.Config.t(), token(), keyword()) :: result(map())

Get your app's registration. Needs a client-credentials token.

app_grants(config, token, opts \\ [])

@spec app_grants(OpenFeed.Config.t(), token(), keyword()) :: result([map()])

List every grant belonging to your app.

A lightweight index — id, revision, last_updated — intended for reconciliation: poll it to notice grants revoked upstream without waiting for a data call to fail with :grant_revoked. Needs a client-credentials token.

banking_account(config, token, account_id, opts \\ [])

@spec banking_account(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result(map())

Get one banking account.

banking_accounts(config, token, opts \\ [])

@spec banking_accounts(OpenFeed.Config.t(), token(), keyword()) :: result([map()])

List the consumer's banking accounts.

banking_balance(config, token, account_id, opts \\ [])

@spec banking_balance(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result(map())

Get a banking account's current balance.

Fetched from the data holder on demand. Can fail with %OpenFeed.Error{kind: :balance_unavailable} — retryable — while the rest of the API is healthy.

banking_transactions(config, token, account_id, opts \\ [])

@spec banking_transactions(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result([map()])

List transactions for a banking account.

Options

  • :oldest_date / :newest_dateDate or ISO 8601 string. Both filters are preserved across pagination.

energy_account(config, token, account_id, opts \\ [])

@spec energy_account(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result(map())

Get one energy account.

energy_accounts(config, token, opts \\ [])

@spec energy_accounts(OpenFeed.Config.t(), token(), keyword()) :: result([map()])

List the consumer's energy accounts.

energy_balance(config, token, account_id, opts \\ [])

@spec energy_balance(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result(map())

Get an energy account's current balance. See banking_balance/4 on cost.

energy_billing(config, token, account_id, opts \\ [])

@spec energy_billing(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result([map()])

List billing transactions for an energy account.

energy_der(config, token, account_id, meter_id, opts \\ [])

@spec energy_der(OpenFeed.Config.t(), token(), String.t(), String.t(), keyword()) ::
  result(map())

Get a meter's distributed energy resource (DER) configuration.

energy_invoices(config, token, account_id, opts \\ [])

@spec energy_invoices(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result([map()])

List invoices for an energy account.

energy_meter(config, token, account_id, meter_id, opts \\ [])

@spec energy_meter(OpenFeed.Config.t(), token(), String.t(), String.t(), keyword()) ::
  result(map())

Get one meter.

energy_meters(config, token, account_id, opts \\ [])

@spec energy_meters(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  result([map()])

List meters for an energy account.

energy_usage(config, token, account_id, meter_id, opts \\ [])

@spec energy_usage(OpenFeed.Config.t(), token(), String.t(), String.t(), keyword()) ::
  result([map()])

List usage readings for a meter.

Options

  • :oldest_date / :newest_dateDate or ISO 8601 string.

grant(config, token, grant_id, opts \\ [])

@spec grant(OpenFeed.Config.t(), token(), String.t(), keyword()) :: result(map())

Query a grant.

Returns its status, revision, metering state and the account ids in scope. Needs the openfeed-au:grant:self:query scope, which must be requested at authorization time.

revoke_grant(config, token, grant_id, opts \\ [])

@spec revoke_grant(OpenFeed.Config.t(), token(), String.t(), keyword()) ::
  :ok | {:error, OpenFeed.Error.t()}

Revoke a grant.

Needs the openfeed-au:grant:self:revoke scope. Returns :ok on success.

A grant that does not exist, or belongs to another app, returns :not_found rather than :forbidden — OpenFeed does that deliberately, so the endpoint cannot be used to probe for valid grant ids.