Class: Lich::InternalAPI::ActiveSessions::Client Private
- Inherits:
-
Object
- Object
- Lich::InternalAPI::ActiveSessions::Client
- Defined in:
- documented/internal_api/active_sessions/client.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Client for managing active sessions with the Lich internal API.
This class handles communication with the server, including sending requests and receiving responses.
Constant Summary collapse
- READ_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1
Instance Method Summary collapse
-
#initialize(host:, port:, auth_token:, socket_factory: nil) ⇒ void
constructor
private
Initializes a new Client instance.
-
#ping ⇒ Boolean
private
Sends a ping request to the server to check connectivity.
-
#remove(pid) ⇒ Hash
private
Sends a remove request to the server for the specified process ID.
-
#request(command, payload = {}) ⇒ Hash
private
Sends a request to the server with the specified command and payload.
-
#snapshot ⇒ Hash
private
Sends a snapshot request to the server.
-
#upsert(payload) ⇒ Hash
private
Sends an upsert request to the server with the provided payload.
Constructor Details
#initialize(host:, port:, auth_token:, socket_factory: nil) ⇒ void
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.
Initializes a new Client instance.
23 24 25 26 27 28 |
# File 'documented/internal_api/active_sessions/client.rb', line 23 def initialize(host:, port:, auth_token:, socket_factory: nil) @host = host @port = port @auth_token = auth_token @socket_factory = socket_factory || ->(connect_host, connect_port) { TCPSocket.new(connect_host, connect_port) } end |
Instance Method Details
#ping ⇒ Boolean
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.
Sends a ping request to the server to check connectivity.
56 57 58 |
# File 'documented/internal_api/active_sessions/client.rb', line 56 def ping request('ping').fetch(:ok, false) end |
#remove(pid) ⇒ Hash
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.
Sends a remove request to the server for the specified process ID.
70 71 72 |
# File 'documented/internal_api/active_sessions/client.rb', line 70 def remove(pid) request('remove', pid: pid) end |
#request(command, payload = {}) ⇒ Hash
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.
Sends a request to the server with the specified command and payload.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'documented/internal_api/active_sessions/client.rb', line 35 def request(command, payload = {}) socket = @socket_factory.call(@host, @port) socket.write(JSON.dump(command: command, auth: @auth_token, payload: payload) + "\n") raw = read_response(socket) return { ok: false, error: 'read timeout' } unless raw response = JSON.parse(raw.to_s, symbolize_names: true) return { ok: false, error: 'invalid response type' } unless response.is_a?(Hash) response rescue StandardError => e { ok: false, error: e. } ensure socket&.close rescue nil end |
#snapshot ⇒ Hash
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.
Sends a snapshot request to the server.
76 77 78 |
# File 'documented/internal_api/active_sessions/client.rb', line 76 def snapshot request('snapshot') end |
#upsert(payload) ⇒ Hash
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.
Sends an upsert request to the server with the provided payload.
63 64 65 |
# File 'documented/internal_api/active_sessions/client.rb', line 63 def upsert(payload) request('upsert', payload) end |