Class: Invoance::Client
- Inherits:
-
Object
- Object
- Invoance::Client
- Defined in:
- lib/invoance/client.rb
Overview
Instance Attribute Summary collapse
-
#attestations ⇒ Object
readonly
Returns the value of attribute attestations.
-
#audit ⇒ Object
readonly
Returns the value of attribute audit.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#traces ⇒ Object
readonly
Returns the value of attribute traces.
Instance Method Summary collapse
-
#base_url ⇒ String
The resolved base URL in use.
-
#initialize(api_key: nil, base_url: nil, api_version: "v1", timeout: 30, idempotency_key: nil, extra_headers: {}) ⇒ Client
constructor
A new instance of Client.
-
#me ⇒ Hash
Introspect the API key via GET /v1/me.
-
#validate ⇒ Hash
Call the scope-free introspection endpoint (GET /v1/me) to confirm the API key works.
Constructor Details
#initialize(api_key: nil, base_url: nil, api_version: "v1", timeout: 30, idempotency_key: nil, extra_headers: {}) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/invoance/client.rb', line 31 def initialize(api_key: nil, base_url: nil, api_version: "v1", timeout: 30, idempotency_key: nil, extra_headers: {}) @config = Config.new( api_key: api_key, base_url: base_url, api_version: api_version, timeout: timeout, idempotency_key: idempotency_key, extra_headers: extra_headers ) @http = Http.new(@config) @events = Resources::Events.new(@http) @documents = Resources::Documents.new(@http) @attestations = Resources::Attestations.new(@http) @traces = Resources::Traces.new(@http) @audit = Resources::Audit.new(@http) end |
Instance Attribute Details
#attestations ⇒ Object (readonly)
Returns the value of attribute attestations.
23 24 25 |
# File 'lib/invoance/client.rb', line 23 def attestations @attestations end |
#audit ⇒ Object (readonly)
Returns the value of attribute audit.
23 24 25 |
# File 'lib/invoance/client.rb', line 23 def audit @audit end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
23 24 25 |
# File 'lib/invoance/client.rb', line 23 def documents @documents end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
23 24 25 |
# File 'lib/invoance/client.rb', line 23 def events @events end |
#traces ⇒ Object (readonly)
Returns the value of attribute traces.
23 24 25 |
# File 'lib/invoance/client.rb', line 23 def traces @traces end |
Instance Method Details
#base_url ⇒ String
The resolved base URL in use.
52 53 54 |
# File 'lib/invoance/client.rb', line 52 def base_url @config.base_url end |
#me ⇒ Hash
Introspect the API key via GET /v1/me. Requires no scope, so it works for any valid key. Raises like every other resource call.
61 62 63 |
# File 'lib/invoance/client.rb', line 61 def me @http.get("/me") end |
#validate ⇒ Hash
Call the scope-free introspection endpoint (GET /v1/me) to confirm the API key works. NEVER raises.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/invoance/client.rb', line 69 def validate base = @config.base_url begin me { "valid" => true, "reason" => nil, "base_url" => base } rescue AuthenticationError { "valid" => false, "reason" => "Authentication failed — check INVOANCE_API_KEY", "base_url" => base } rescue ForbiddenError { "valid" => true, "reason" => "API key authenticated but the request was blocked (IP access rules)", "base_url" => base } rescue QuotaExceededError { "valid" => true, "reason" => "API key authenticated but currently rate limited", "base_url" => base } rescue NetworkError, TimeoutError => e { "valid" => false, "reason" => "Server unreachable: #{e.}", "base_url" => base } rescue Error => e { "valid" => false, "reason" => e., "base_url" => base } end end |