Class: ZeroClick::Sellers::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/zeroclick/sellers/railtie.rb

Overview

Rails ergonomics on top of the Rack middleware.

Deliberately thin, and deliberately NOT loaded by require "zeroclick/sellers" — the gem must stay usable from Sinatra, Hanami and plain Rack without Rails on the load path. Rails apps opt in:

# config/application.rb
require "zeroclick/sellers/railtie"

config.zeroclick.api_key = ENV.fetch("ZEROCLICK_API_KEY")
config.zeroclick.signing_secrets = ZeroClick::Sellers.secrets_from_env

Then guard routes in the usual Rails way:

Note there is no seller:config.middleware.use evaluates its arguments in the Application class body, which runs BEFORE the initializer below, so no client exists yet. The middleware resolves one on the first request instead.

config.middleware.use ZeroClick::Sellers::Middleware::Meter,
service_slug: "extractor",
usage: [ZeroClick::Sellers::UsageItem.new(meter_slug: "requests", quantity: 1)]

Inside a controller, the verified caller is on the request env:

zc = request.env["zeroclick.context"]