Ruby SDK

Configuration

Client options, environment variables, timeouts, retries and which calls need the secret key.

Scute::Client holds the app id, the secret key and the HTTP settings. Create one and reuse it.

scute = Scute::Client.new(  app_id: ENV["SCUTE_APP_ID"],  secret: ENV["SCUTE_SECRET"],  base_url: "https://api.scute.io",  open_timeout: 5,  read_timeout: 10,  retries: 1)

Options#

app_idStringrequired
The app id. Defaults to ENV["SCUTE_APP_ID"]. Missing raises Scute::ConfigurationError.
secretString
The app's secret key. Defaults to ENV["SCUTE_SECRET"]. Needed for every call except token verification and the user-session calls.
base_urlString
API base URL. Defaults to ENV["SCUTE_BASE_URL"], then https://api.scute.io.
client_ipString
The end user's IP address, sent as X-Scute-Client-IP on secret-key calls. One IPv4 or IPv6 address; anything else raises ArgumentError. See Rack middleware and client IP.
open_timeoutInteger
Seconds to open the connection. Default 5.
read_timeoutInteger
Seconds to wait for the answer. Default 10.
retriesInteger
Retries on a network error, for idempotent calls only. Default 1.
transport#call
Replaces Net::HTTP. Anything that responds to call(method, url, headers, body) and returns [status, body].

Environment variables#

VariableUsed forDefault
SCUTE_APP_IDapp_idnone (required)
SCUTE_SECRETsecretnone
SCUTE_BASE_URLbase_urlhttps://api.scute.io

The controller concerns and Scute::Harness create their own client with Scute::Client.new, so they read the same variables.

Which calls need the secret key#

CallCredential
tokens.verify (without remote: true)none: reads the app's public JWKS
sessions.current_user, sessions.refresh, sessions.sign_outthe user's own token
tokens.verify(token, remote: true)the user's own token
users.*, sessions.list, sessions.revokesecret key
authz.*, agents.*secret key

A secret-key call without a secret raises Scute::ConfigurationError ("This call needs the app's secret key") before any request is made.

Retries#

The client retries once (retries: 1) on a network error (connection refused or reset, host unreachable, timeouts, DNS, EOFError, TLS errors) for GET requests and for calls that are safe to repeat: authz.check, authz.check_batch, authz.filter and users.update. Calls that create something (users, tasks, challenges, requests) are never retried. When the retries run out the client raises Scute::ConnectionError.

Requests#

Every request sends Accept: application/json, Content-Type: application/json and User-Agent: scute-ruby/<version>. Secret-key calls send Authorization: Bearer <secret>.

Copies and inspect#

scute.with_client_ip(ip) returns a copy of the client with another client IP. The original is unchanged.

scute.inspect shows the app id and secret="***", never the key. scute.secret? is true when a secret is set.