Getting started
View SourceAurora Meter meters usage, enforces plan entitlements, and (with the Pro package) bills via Stripe — from inside your Phoenix app.
1. Add the dependency
def deps do
[{:aurora_meter, "~> 0.3"}]
end2. Install
With Igniter in your dev deps, one command does steps 2 to 4 (config, supervision child, a starter plans module, the migration):
mix igniter.install aurora_meter
mix ecto.migrate
Without Igniter, generate the migration and follow the printed steps:
mix aurora_meter.gen.migration -r MyApp.Repo
mix ecto.migrate
This generates a thin migration that delegates to AuroraMeter.Migration, which
is versioned: when a later release adds tables, run
mix aurora_meter.gen.migration -r MyApp.Repo --from N for a migration that
applies only the new versions.
3. Define plans
See Plans. Minimal example:
defmodule MyApp.Plans do
use AuroraMeter.Plans
plan :free do
price 0
limit :api_calls, 1_000, :hard
end
end4. Configure and start
# config/config.exs
config :aurora_meter, repo: MyApp.Repo, pubsub: MyApp.PubSub, plans: MyApp.Plans
# application.ex — after the Repo and PubSub
children = [MyApp.Repo, {Phoenix.PubSub, name: MyApp.PubSub}, AuroraMeter]Aurora Meter validates its configuration at boot and raises immediately on a missing or mistyped key.
5. Meter and gate
AuroraMeter.subscribe(org, :free)
AuroraMeter.track(org, :api_calls)
AuroraMeter.check(org, :api_calls) # :ok | {:error, :limit_exceeded}Next: Metering · Entitlements · Configuration.