Class: NinjaOne::Client

Inherits:
API
  • Object
show all
Includes:
Organizations, System
Defined in:
lib/ninjaone/client.rb,
lib/ninjaone/client/system.rb,
lib/ninjaone/client/organizations.rb

Overview

Note:

All methods are grouped in separate modules for better organization and follow the structure provided in the official API documentation.

The ‘NinjaOne::Client` class acts as a wrapper for the NinjaOne REST API. This class inherits from the `NinjaOne::API` class and includes modules that group the API methods according to the structure in the NinjaOne API documentation.

Defined Under Namespace

Modules: Organizations, System

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Organizations

api_endpoint_suffix, #organization_backup_usage_by_location

Methods included from System

#search_devices

Methods inherited from API

#config, #initialize

Methods included from Authentication

#auth_token

Constructor Details

This class inherits a constructor from NinjaOne::API

Class Method Details

.api_endpoint(method, singular_method = nil, path = method.to_s.tr('_', '-')) ⇒ Object

Dynamically defines methods for interacting with NinjaOne API resources.

Depending on the arguments, this will define methods to:

  • Fetch all records for a resource

  • Fetch a specific record by ID

Examples:

Defining endpoints

api_endpoint :companies, :company
# Defines:
# - `companies(params = {})` to fetch all companies.
# - `company(id, params = {})` to fetch a single company by ID.

Parameters:

  • method (Symbol)

    The method name for fetching all records.

  • singular_method (Symbol, nil) (defaults to: nil)

    The method name for fetching a single record by ID. Optional.

  • path (String) (defaults to: method.to_s.tr('_', '-'))

    The API path for the resource. Defaults to the method name.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ninjaone/client.rb', line 27

def self.api_endpoint(method, singular_method = nil, path = method.to_s.tr('_', '-'))
  # Define method to fetch all records

  send(:define_method, method) do |params = {}|
    get_paged(api_url(path), params)
  end
  # Define method to fetch a single record by ID

  if singular_method
    send(:define_method, singular_method) do |id, params = {}|
      get(api_url("#{singular_method}/#{id}"), params)
    end
  end
end

Instance Method Details

#api_url(path) ⇒ String

Constructs the full API URL for a given path.

Parameters:

  • path (String)

    The API path.

Returns:

  • (String)

    The full API URL.



54
55
56
# File 'lib/ninjaone/client.rb', line 54

def api_url(path)
  "/v2/#{path}"
end