Class: Smplkit::Logging::LogGroupsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/logging/client.rb

Overview

Surface for client.logging.log_groups.* (sync).

Instance Method Summary collapse

Constructor Details

#initialize(http_client) ⇒ LogGroupsClient

Returns a new instance of LogGroupsClient.



291
292
293
# File 'lib/smplkit/logging/client.rb', line 291

def initialize(http_client)
  @api = SmplkitGeneratedClient::Logging::LogGroupsApi.new(http_client)
end

Instance Method Details

#_create_log_group(group) ⇒ Object

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.



348
349
350
351
# File 'lib/smplkit/logging/client.rb', line 348

def _create_log_group(group)
  response = ApiSupport::ErrorMapping.call { @api.create_log_group(log_group_body(group)) }
  Helpers.log_group_resource_to_model(self, ApiSupport::ResourceShim.from_model(response.data))
end

#_update_log_group(group) ⇒ Object

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.



354
355
356
357
# File 'lib/smplkit/logging/client.rb', line 354

def _update_log_group(group)
  response = ApiSupport::ErrorMapping.call { @api.update_log_group(group.key, log_group_body(group)) }
  Helpers.log_group_resource_to_model(self, ApiSupport::ResourceShim.from_model(response.data))
end

#delete(id) ⇒ void

This method returns an undefined value.

Delete a log group by id.

Parameters:

  • id (String)

    Identifier of the log group to delete.

Raises:



342
343
344
345
# File 'lib/smplkit/logging/client.rb', line 342

def delete(id)
  ApiSupport::ErrorMapping.call { @api.delete_log_group(id) }
  nil
end

#get(id) ⇒ SmplLogGroup

Fetch a single log group by id.

Parameters:

  • id (String)

    Identifier of the log group to fetch.

Returns:

Raises:



332
333
334
335
# File 'lib/smplkit/logging/client.rb', line 332

def get(id)
  response = ApiSupport::ErrorMapping.call { @api.get_log_group(id) }
  Helpers.log_group_resource_to_model(self, ApiSupport::ResourceShim.from_model(response.data))
end

#get_group_entry(key) ⇒ Object

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.

Fetch one log group as a resolution-cache entry. Used by the group_changed WS handler.



374
375
376
377
# File 'lib/smplkit/logging/client.rb', line 374

def get_group_entry(key)
  response = ApiSupport::ErrorMapping.call { @api.get_log_group(key) }
  group_entry_from_resource(ApiSupport::ResourceShim.from_model(response.data))
end

#list(page_number: nil, page_size: nil) ⇒ Array<SmplLogGroup>

List log groups for the authenticated account.

Parameters:

  • page_number (Integer, nil) (defaults to: nil)

    1-based page index to fetch. When omitted, the server returns the first page.

  • page_size (Integer, nil) (defaults to: nil)

    Maximum number of log groups per page. When omitted, the server applies its default page size.

Returns:

  • (Array<SmplLogGroup>)

    The log groups on the requested page.



317
318
319
320
321
322
323
324
325
# File 'lib/smplkit/logging/client.rb', line 317

def list(page_number: nil, page_size: nil)
  opts = {}
  opts[:page_number] = page_number unless page_number.nil?
  opts[:page_size] = page_size unless page_size.nil?
  response = ApiSupport::ErrorMapping.call { @api.list_log_groups(opts) }
  (response.data || []).map do |r|
    Helpers.log_group_resource_to_model(self, ApiSupport::ResourceShim.from_model(r))
  end
end

#list_group_entriesObject

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.

Runtime entry — walks every page and returns an id-keyed Hash of resolution-cache entries (level, group, environments). The group key carries the *parent group id* so the resolution algorithm can walk the chain with the same key shape it uses for loggers.



365
366
367
368
# File 'lib/smplkit/logging/client.rb', line 365

def list_group_entries
  rows = ApiSupport::PaginatedFetch.collect { |opts| @api.list_log_groups(opts) }
  rows.to_h { |r| group_entry_from_resource(ApiSupport::ResourceShim.from_model(r)) }
end

#new(id, name: nil, group: nil) ⇒ SmplLogGroup

Build a new unsaved log group. The returned SmplLogGroup is local only; call its SmplLogGroup#save to persist it.

Parameters:

  • id (String)

    Identifier for the log group.

  • name (String, nil) (defaults to: nil)

    Human-readable display name. Defaults to a title-cased version of id when omitted.

  • group (String, nil) (defaults to: nil)

    Identifier of the parent log group, when nesting groups. nil for a top-level group.

Returns:

  • (SmplLogGroup)

    An unsaved log group bound to this client.



304
305
306
307
308
# File 'lib/smplkit/logging/client.rb', line 304

def new(id, name: nil, group: nil)
  SmplLogGroup.new(
    self, key: id, name: name.nil? ? Smplkit::Helpers.key_to_display_name(id) : name, group: group
  )
end