Class: NinjaOne::Client
- Defined in:
- lib/ninjaone/client.rb,
lib/ninjaone/client/users.rb,
lib/ninjaone/client/backup.rb,
lib/ninjaone/client/system.rb,
lib/ninjaone/client/devices.rb,
lib/ninjaone/client/queries.rb,
lib/ninjaone/client/organizations.rb
Overview
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: Backup, Devices, Organizations, Queries, System, Users
Class Method Summary collapse
-
.define_endpoint(scope, resource = nil, paged = false) ⇒ Object
Dynamically defines methods for interacting with NinjaOne API resources.
-
.resource_to_name(path) ⇒ String
Constructs url resource name from url path.
Instance Method Summary collapse
-
#api_url(path) ⇒ String
Constructs the full API URL for a given path.
Methods included from Organizations
#organization_backup_usage_by_location, #organization_location_custom_fields
Methods included from System
Methods inherited from API
Methods included from Authentication
Constructor Details
This class inherits a constructor from NinjaOne::API
Class Method Details
.define_endpoint(scope, resource = nil, paged = false) ⇒ Object
Dynamically defines methods for interacting with NinjaOne API resources.
Depending on the arguments, this will define methods to:
- Fetch all records for the given scope
- Fetch a resource specific record by ID
Paging is not supported.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ninjaone/client.rb', line 37 def self.define_endpoint(scope, resource = nil, paged = false) if resource name = self.resource_to_name(scope) name = "#{name}_#{self.resource_to_name(resource)}" if resource && !resource.empty? # change to nil if resource is empty so we ar eable to generate /scope/id/resource # but also /scope/id without training / resource = resource&.empty? ? nil : resource send(:define_method, name) do |id, params = {}| url = api_url([scope, id, resource].compact.join('/')) paged ? get_paged(url, params) : get(url, params) end else name = self.resource_to_name(scope) send(:define_method, name) do |params = {}| url = api_url(scope) paged ? get_paged(url, params) : get(url, params) end end end |
.resource_to_name(path) ⇒ String
Constructs url resource name from url path
17 18 19 |
# File 'lib/ninjaone/client.rb', line 17 def self.resource_to_name(path) path.to_s.gsub(/[-\/]/,'_') end |
Instance Method Details
#api_url(path) ⇒ String
Constructs the full API URL for a given path.
76 77 78 |
# File 'lib/ninjaone/client.rb', line 76 def api_url(path) "/v2/#{path}" end |