Skip to main content

Ruby SDK

santati is the official Ruby client for the Santati audit-log API, published on RubyGems. Requires Ruby 3.2+.

Install​

gem install santati

or, in a Gemfile:

gem "santati"

Create a client​

require "santati"

client = Santati::Client.new(api_key: ENV.fetch("SANTATI_API_KEY"), trail: "billing")
optiondefaultmeaning
api_keyrequired, non-emptyteam API key (sat_sk_…)
base_urlhttps://api.santati.iotrailing / removed; may carry a path prefix
trailnonedefault trail for emits; never applied to reads
timeout_ms10000per attempt
max_retries2retries after the first attempt
initial_backoff_ms250backoff base
max_backoff_ms8000backoff cap
headersnoneextra headers on every request

trail is the default trail for emits and is never applied to reads. Construction fails with a Santati::ValidationError (with status nil) for an empty key or an Authorization header in headers. Redirects are never followed, so the key is never replayed to another host.

Emit an event​

result = client.events.emit(
event: "invoice.voided",
organization_id: "org_acme",
actor: {type: "user", id: "usr_123", name: "Valentine Michael Smith"},
targets: [{type: "invoice", id: "inv_555"}]
)
puts "#{result.event.id} #{result.duplicate}"

Without an idempotency_key one is generated — a UUIDv4 — and duplicate is true when the server replayed an earlier request. See Idempotency and Event envelope.

Emit a batch​

batch = client.events.emit_batch([
{event: "invoice.voided", organization_id: "org_acme"},
{event: "invoice.paid", organization_id: "org_acme"}
])
puts batch.accepted
puts batch.rejected

A 202 and a 207 both return a result with per-item status (accepted, duplicate or rejected) in batch.results, and the server enforces 500 events / 1 MiB — a 413 arrives as a validation error. See Batching.

List and iterate​

page = client.events.list(trail: "billing", event_prefix: "invoice.", limit: 50)
page.results.each { |event| puts "#{event.id} #{event.event}" }
p page.next_cursor

client.events.iterate(trail: "billing").each { |event| puts event.id }

list accepts trail, event, event_prefix, organization_id, actor_id, actor_type, target_type, target_id, created_after, created_before, q, sort and limit, plus cursor on list only. iterate returns an Enumerator that walks every page lazily. See Searching events.

Errors and retries​

Every failure raises a Santati::Error subclass:

kindwhen
Santati::ValidationErrorlocal validation (status is nil), or HTTP 400, 413, 422
Santati::AuthErrorHTTP 401, 403
Santati::NotFoundErrorHTTP 404
Santati::RateLimitedErrorHTTP 429
Santati::ServerErrorHTTP 5xx
Santati::TransportErrorno response: refused, DNS, TLS, timeout (status is nil)
Santati::ApiErrorany other status, an unexpected 2xx, or an undecodable body

Each carries status, code, field, retry_after and message.

begin
client.events.emit(event: "invoice.voided", organization_id: "org_acme")
rescue Santati::RateLimitedError => e
sleep(e.retry_after) if e.retry_after
retry
rescue Santati::Error => e
warn e.message
end

An emit, a batch and a list retry transport failures, 500/502/503/504 and 429 (unless the code is quota_exceeded) up to max_retries times, re-sending the identical request with the same idempotency keys. A Retry-After header is honoured unless it exceeds max_backoff_ms, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.