Class: NinjaOne::API

Inherits:
Object
  • Object
show all
Includes:
Authentication, WrAPI::Authentication, WrAPI::Connection, WrAPI::Request
Defined in:
lib/ninjaone/api.rb

Overview

The ‘NinjaOne::API` class manages the core configuration and settings for the API client. It allows customization of options like endpoint, user agent, and pagination handling. This class copies configuration settings from the NinjaOne singleton and provides methods to retrieve the client configuration.

Direct Known Subclasses

Client

Instance Method Summary collapse

Methods included from Authentication

#auth_token

Constructor Details

#initialize(options = {}) ⇒ NinjaOne::API

Initializes a new ‘NinjaOne::API` instance with the given options. The options are merged with the global NinjaOne settings to allow both global and per-instance customization.

Examples:

Create a new API instance with custom options:

api = NinjaOne::API.new(endpoint: "https://custom-api.endpoint.com", user_agent: "MyApp UA/1.0")

Parameters:

  • options (Hash) (defaults to: {})

    A hash of configuration options. These options can override the global NinjaOne configuration.



25
26
27
28
29
30
31
32
# File 'lib/ninjaone/api.rb', line 25

def initialize(options = {})
  # Merge the provided options with the global NinjaOne configuration.

  options = NinjaOne.options.merge(options)
  # Set each configuration key dynamically using the merged options.

  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#configHash

Retrieves the current API configuration as a hash.

Examples:

Retrieve the current API configuration:

api = NinjaOne::API.new
api.config  # => { :endpoint => "https://apis.skykick.com", :user_agent => "NinjaOne API/1.0", ... }

Returns:

  • (Hash)

    A hash containing the current configuration settings. The keys in the hash are the same as ‘VALID_OPTIONS_KEYS`.



42
43
44
45
46
47
48
49
# File 'lib/ninjaone/api.rb', line 42

def config
  conf = {}
  # Iterate over each valid configuration key and retrieve its current value.

  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    conf[key] = send key
  end
  conf
end