Class: OpConnect::Client
- Inherits:
-
Object
- Object
- OpConnect::Client
- Includes:
- Files, Items, Vaults, Configurable, Connection
- Defined in:
- lib/op_connect/client.rb,
lib/op_connect/client/files.rb,
lib/op_connect/client/items.rb,
lib/op_connect/client/vaults.rb
Overview
Client for the OpConnect API.
Defined Under Namespace
Instance Attribute Summary
Attributes included from Configurable
#access_token, #adapter, #api_endpoint, #stubs, #user_agent
Instance Method Summary collapse
-
#activity(**params) ⇒ Array<APIRequest>
Retrieve a list of API requests that have been made.
-
#health ⇒ ServerHealth
Query the state of the server and its service dependencies.
-
#heartbeat ⇒ Boolean
Simple “ping” endpoint to check whether the server is active.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#inspect ⇒ String
Text representation of the client, masking tokens.
-
#metrics ⇒ String
Returns Prometheus metrics collected by the server.
Methods included from Files
#get_file, #get_file_content, #list_files
Methods included from Items
#create_item, #delete_item, #get_item, #list_items, #replace_item, #update_item
Methods included from Vaults
Methods included from Connection
#connection, #delete, #get, #last_response, #patch, #post, #put
Methods included from Configurable
#configure, keys, #reset!, #same_options?
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 |
# File 'lib/op_connect/client.rb', line 15 def initialize( = {}) OpConnect::Configurable.keys.each do |key| value = .key?(key) ? [key] : OpConnect.instance_variable_get(:"@#{key}") instance_variable_set(:"@#{key}", value) end end |
Instance Method Details
#activity(**params) ⇒ Array<APIRequest>
Retrieve a list of API requests that have been made.
42 43 44 |
# File 'lib/op_connect/client.rb', line 42 def activity(**params) get("activity", params: params).body.map { |a| APIRequest.new(a) } end |
#health ⇒ ServerHealth
Query the state of the server and its service dependencies.
61 62 63 |
# File 'lib/op_connect/client.rb', line 61 def health ServerHealth.new get("/health").body end |
#heartbeat ⇒ Boolean
Simple “ping” endpoint to check whether the server is active.
50 51 52 53 54 55 |
# File 'lib/op_connect/client.rb', line 50 def heartbeat return true if get("/heartbeat").status == 200 false rescue OpConnect::Error false end |
#inspect ⇒ String
Text representation of the client, masking tokens.
26 27 28 29 30 |
# File 'lib/op_connect/client.rb', line 26 def inspect inspected = super inspected.gsub!(@access_token, ("*" * 24).to_s) if @access_token inspected end |
#metrics ⇒ String
Returns Prometheus metrics collected by the server.
72 73 74 |
# File 'lib/op_connect/client.rb', line 72 def metrics get("/metrics").body end |