Class: Fluence::Gateway::Client
- Inherits:
-
Object
- Object
- Fluence::Gateway::Client
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/fluence/gateway/http_client.rb
Overview
Singleton HTTP client for the Fluence API gateway.
Handles OAuth2 client_credentials authentication transparently: the
service token is fetched on the first request and refreshed on demand.
End-user Bearer tokens can be forwarded per call or for an entire
block, and the target service can be encoded into the URL via the
service: kwarg or the #with_service block helper.
All HTTP verbs (get, post, put, patch, delete) are defined
on both the singleton instance and the class (class-level delegation),
so callers never need to reference .instance explicitly.
Thread-safety: token refresh is guarded by a Mutex; per-block scopes
(#with_user_token, #with_service) are stored in Thread.current
and restored when the block exits, including on exception.
Class Method Summary collapse
-
.delete(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
The parsed JSON response.
-
.get(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
The parsed JSON response.
-
.patch(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
The parsed JSON response.
-
.post(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
The parsed JSON response.
-
.put(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
The parsed JSON response.
-
.with_service(service, &block) ⇒ Object
The block's return value.
-
.with_user_token(token, &block) ⇒ Object
The block's return value.
Instance Method Summary collapse
-
#delete(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
Performs a DELETE request on the gateway.
-
#get(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
Performs a GET request on the gateway.
-
#patch(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Performs a PATCH request on the gateway.
-
#post(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Performs a POST request on the gateway.
-
#put(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Performs a PUT request on the gateway.
-
#with_service(service) { ... } ⇒ Object
Scopes a block of gateway calls to the given backend service.
-
#with_user_token(token) { ... } ⇒ Object
Scopes a block of gateway calls to forward
tokenas the end-user Bearer instead of the cached service token.
Class Method Details
.delete(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
Returns the parsed JSON response.
.get(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
Returns the parsed JSON response.
.patch(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Returns the parsed JSON response.
.post(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Returns the parsed JSON response.
.put(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Returns the parsed JSON response.
.with_service(service, &block) ⇒ Object
Returns the block's return value.
.with_user_token(token, &block) ⇒ Object
Returns the block's return value.
Instance Method Details
#delete(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
Performs a DELETE request on the gateway.
#get(path, user_token: nil, service: nil, **opts) ⇒ Hash, Array
Performs a GET request on the gateway.
#patch(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Performs a PATCH request on the gateway.
#post(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Performs a POST request on the gateway.
#put(path, user_token: nil, service: nil, body: nil, **opts) ⇒ Hash, Array
Performs a PUT request on the gateway.
#with_service(service) { ... } ⇒ Object
Scopes a block of gateway calls to the given backend service.
Paths issued inside the block are automatically prefixed with
/backend/<service>/. When service is a Symbol, underscores are
converted to dashes (:base_valeur → base-valeur); when it is a
String, it is used as-is. The scope is stored in Thread.current
and restored when the block exits, including on exception. A
service: kwarg on a call site always wins over the value set here.
#with_user_token(token) { ... } ⇒ Object
Scopes a block of gateway calls to forward token as the end-user
Bearer instead of the cached service token.
The token is stored in Thread.current so it survives nested calls
on the same thread but does not leak to other threads. Any explicit
user_token: kwarg on a call site always wins over the value set
here. The previous value (if any) is restored when the block exits,
including on exception.