Module: Invoance
- Defined in:
- lib/invoance.rb,
lib/invoance/http.rb,
lib/invoance/client.rb,
lib/invoance/config.rb,
lib/invoance/errors.rb,
lib/invoance/version.rb,
lib/invoance/validate.rb,
lib/invoance/audit_verify.rb,
lib/invoance/audit_canonical.rb,
lib/invoance/resources/audit.rb,
lib/invoance/resources/events.rb,
lib/invoance/resources/traces.rb,
lib/invoance/resources/documents.rb,
lib/invoance/resources/attestations.rb
Overview
Invoance — Official Ruby SDK for the Invoance compliance API.
require "invoance"
client = Invoance::Client.new(api_key: "inv_live_abc123")
event = client.events.ingest(event_type: "user.login", payload: { user_id: "u_42" })
Audit-log offline verification helpers live in AuditVerify and AuditCanonical; the content-idempotency-key helper is Resources.content_idempotency_key.
Defined Under Namespace
Modules: AuditCanonical, AuditVerify, Resources, Validate Classes: AuthenticationError, Client, Config, ConflictError, Error, ForbiddenError, Http, NetworkError, NotFoundError, QuotaExceededError, ServerError, TimeoutError, ValidationError
Constant Summary collapse
- STATUS_ERROR_MAP =
Status-code → error-class map. Anything >= 500 not listed maps to ServerError; any other unmapped status maps to the base Error.
{ 400 => ValidationError, 401 => AuthenticationError, 403 => ForbiddenError, 404 => NotFoundError, 409 => ConflictError, 429 => QuotaExceededError }.freeze
- VERSION =
"0.1.0"
Class Method Summary collapse
- .describe_request(ctx) ⇒ Object private
-
.throw_for_status(status_code, body, request_context: nil, retry_after_seconds: nil) ⇒ Object
Raise the appropriate error for a non-2xx response.
Class Method Details
.describe_request(ctx) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 |
# File 'lib/invoance/errors.rb', line 101 def self.describe_request(ctx) ctx ? " on #{ctx[:method]} #{ctx[:path]}" : "" end |
.throw_for_status(status_code, body, request_context: nil, retry_after_seconds: nil) ⇒ Object
Raise the appropriate error for a non-2xx response. No-op on 2xx.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/invoance/errors.rb', line 72 def self.throw_for_status(status_code, body, request_context: nil, retry_after_seconds: nil) return if status_code >= 200 && status_code < 300 b = body || {} error_code = b["error"] || "unknown" = b["message"] = if elsif status_code == 429 && !retry_after_seconds.nil? "HTTP 429#{describe_request(request_context)} — rate limited, retry after #{retry_after_seconds}s" else "HTTP #{status_code}#{describe_request(request_context)} (no response body)" end klass = STATUS_ERROR_MAP[status_code] || (status_code >= 500 ? ServerError : Error) raise klass.new( , status_code: status_code, error_code: error_code, body: b, request_context: request_context, retry_after_seconds: retry_after_seconds ) end |