Class: OpConnect::Client

Inherits:
Object
  • Object
show all
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

Modules: Files, Items, Vaults

Instance Attribute Summary

Attributes included from Configurable

#access_token, #adapter, #api_endpoint, #stubs, #user_agent

Instance Method Summary collapse

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

#get_vault, #list_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(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

Instance Method Details

#activity(**params) ⇒ Array<APIRequest>

Retrieve a list of API requests that have been made.

Parameters:

  • params (Hash)

    Optional parameters.

Options Hash (**params):

  • :limit (Integer)

    How many API Events should be returned in a single request.

  • :offset (Integer)

    How far into the collection of API Events should the response start.

Returns:



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

#healthServerHealth

Query the state of the server and its service dependencies.

Returns:



61
62
63
# File 'lib/op_connect/client.rb', line 61

def health
  ServerHealth.new get("/health").body
end

#heartbeatBoolean

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

Returns:

  • (Boolean)

    Returns true if the server is active, false otherwise.



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

#inspectString

Text representation of the client, masking tokens.

Returns:

  • (String)


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

#metricsString

Returns Prometheus metrics collected by the server.

Returns:

  • (String)

    Returns a plain text list of Prometheus metrics.

See Also:



72
73
74
# File 'lib/op_connect/client.rb', line 72

def metrics
  get("/metrics").body
end