Module: NinjaOne::Client::Organizations

Included in:
NinjaOne::Client
Defined in:
lib/ninjaone/client/organizations.rb

Overview

Contains Organizations API calls for Ninja One.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.api_endpoint_suffix(method, suffix) ⇒ 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)

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

  • path (String)

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



24
25
26
27
28
29
30
31
# File 'lib/ninjaone/client/organizations.rb', line 24

def self.api_endpoint_suffix(method, suffix)
  # Define method to fetch a single record by ID

  name = "#{method}_#{suffix.gsub(/[-\/]/,'_')}"

  send(:define_method, name) do |id, params = {}|
    get(api_url("#{method}/#{id}/#{suffix}"), params)
  end
end

Instance Method Details

#organization_backup_usage_by_location(id, location_id, params = {}) ⇒ Object

Returns a location backup usage



40
41
42
43
44
45
# File 'lib/ninjaone/client/organizations.rb', line 40

def organization_backup_usage_by_location(id, location_id, params={})
  get(api_url("organization/#{id}/locations/#{location_id}/backup/usage"), params)
rescue Faraday::ServerError
  # it looks like a server error is thrown when no backup is available; fake it by returning anempty array

  []
end