class OpConnect::Client

Client for the OpConnect API.

Public Class Methods

new(options = {}) click to toggle source
# File lib/op_connect/client.rb, line 15
def initialize(options = {})
  OpConnect::Configurable.keys.each do |key|
    value = options.key?(key) ? options[key] : OpConnect.instance_variable_get(:"@#{key}")
    instance_variable_set(:"@#{key}", value)
  end
end

Public Instance Methods

activity(**params) click to toggle source

Retrieve a list of API requests that have been made.

@param params [Hash] Optional parameters. @option params [Integer] :limit How many API Events should be returned

in a single request.

@option params [Integer] :offset How far into the collection of API

Events should the response start.

@return [Array<APIRequest>]

# File lib/op_connect/client.rb, line 42
def activity(**params)
  get("activity", params: params).body.map { |a| APIRequest.new(a) }
end
health() click to toggle source

Query the state of the server and its service dependencies.

@return [ServerHealth] Returns a ‘ServerHealth` object.

# File lib/op_connect/client.rb, line 61
def health
  ServerHealth.new get("/health").body
end
heartbeat() click to toggle source

Simple “ping” endpoint to check whether the server is active.

@return [Boolean] Returns true if the server is active, false otherwise.

# File lib/op_connect/client.rb, line 50
def heartbeat
  return true if get("/heartbeat").status == 200
  false
rescue OpConnect::Error
  false
end
inspect() click to toggle source

Text representation of the client, masking tokens.

@return [String]

Calls superclass method
# 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() click to toggle source

Returns Prometheus metrics collected by the server.

@return [String] Returns a plain text list of Prometheus metrics.

@see prometheus.io/docs/instrumenting/exposition_formats/#text-based-format

Prometheus documentation
# File lib/op_connect/client.rb, line 72
def metrics
  get("/metrics").body
end