ninjaone 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2d9edce18fc48c11d1eee0a7d87d4e3d23f3622c54d522495181f50f2004bb3
4
- data.tar.gz: a99415651e31f4616c478871acc3539abdcc16d452f372a366cdc321be9ed939
3
+ metadata.gz: 69cf374dfc56664fdbbc61533fcffbc84cc8f378cc422641be286b5740d04d8f
4
+ data.tar.gz: e4f573f19bb88b7173a035622e65a86119ca20276806fa4df2ce40d2752adc29
5
5
  SHA512:
6
- metadata.gz: 13fe05ba9d907d7ebb217cdd79dd890e008a5805319e2de4bbcaba6a28d8f5a8f33cbed562f36797d081f823006553bbbdb4815a119a0678461b2b89bfaa5d5e
7
- data.tar.gz: 4481305a4e29b2dc3e3043e05a383225790f0c745d10efcfbe5dc06368e34b5a3d0e7fed9c43c469dd27304276f6ed25f496cfafdce317c2b65c00ba36377bbb
6
+ metadata.gz: '0090ba275e371d7064dee5ca2f432eb239ef6d31aa0aba63849c740834cc0c2cb6456d4d7f588a99475cb9ffa1add1c1349973b61c6c34e5ae3a90ae95b2966f'
7
+ data.tar.gz: 7d07158ecb6ab23ea23587453dfdadaf35df8906c8f5fbefa0c51e220782a866955338ca4dd849e9b49142dfd6c0f428859f60fe8ead3b401c072354489d97e2
data/CHANGELOG.md CHANGED
@@ -8,3 +8,7 @@
8
8
 
9
9
  - Added backup and devices api group
10
10
 
11
+ ## [0.2.1] - 2026-1-16
12
+
13
+ - Simplify api endpoint definition
14
+
data/README.md CHANGED
@@ -66,7 +66,7 @@ client.login
66
66
 
67
67
  |Resource|API endpoint|
68
68
  |:--|:--|
69
- |.auth_token or .login|https://app.ninjarmm.com/apidocs/?links.active=authorization|
69
+ |`login`|https://app.ninjarmm.com/apidocs/?links.active=authorization|
70
70
 
71
71
  ### System
72
72
 
@@ -78,29 +78,29 @@ subscriptions = client.subscriptions
78
78
 
79
79
  |Resource|API endpoint|
80
80
  |:--|:--|
81
- |contacts, contact(id)|List contact and get contact details|
82
- |organizations|list organizations|
83
- |policies|list policies|
84
- |jobs|list active jobs|
85
- |activities|list activities|
86
- |alerts|List active alerts (triggered conditions)|
87
- |automation_scripts|List available automation scripts|
88
- |device_custom_fields|List device custom fields|
89
- |devices|List devices|
90
- |devices_detailed|List devices(deatiled)|
91
- |enabled_notification_channels|List enabled notification channels|
92
- |notification_channels|List all notification channels|
93
- |notification_channels_detailed|List all notification channels detailed|
94
- |groups|List all groups (saved searches)|
95
- |locations|List all locations|
96
- |roles|List device roles|
97
- |tasks|List scheduled tasks|
98
- |software_products|List supported 3rd party software|
99
- |users|List users|
100
- |search_devices(query_string)|Find devices|
101
- |user_end_users|End user list|
102
- |user_technicians|Technicians list|
103
- |user_roles|Get user roles|
81
+ |`contacts`, `contact(id)`|List contact and get contact details|
82
+ |`organizations`|list organizations|
83
+ |`policies`|list policies|
84
+ |`jobs`|list active jobs|
85
+ |`activities`|list activities|
86
+ |`alerts`|List active alerts (triggered conditions)|
87
+ |`automation_scripts`|List available automation scripts|
88
+ |`device_custom_fields`|List device custom fields|
89
+ |`devices`|List devices|
90
+ |`devices_detailed`|List devices(deatiled)|
91
+ |`notification_channels_enabled`|List enabled notification channels|
92
+ |`notification_channels`|List all notification channels|
93
+ |`notification_channels_detailed`|List all notification channels detailed|
94
+ |`groups`|List all groups (saved searches)|
95
+ |`locations`|List all locations|
96
+ |`roles`|List device roles|
97
+ |`tasks`|List scheduled tasks|
98
+ |`software_products`|List supported 3rd party software|
99
+ |`users`|List users|
100
+ |`search_devices(query_string)`|Find devices|
101
+ |`user_end_users`|End user list|
102
+ |`user_technicians`|Technicians list|
103
+ |`user_roles`|Get user roles|
104
104
 
105
105
  ### Organizations
106
106
 
@@ -114,13 +114,13 @@ org_devices = client.organization_devices(org.id)
114
114
 
115
115
  |Resource|API endpoint|
116
116
  |:--|:--|
117
- |.organizations,.organization(id)|List organizations or get one by id|
118
- |.organization_locations(id)|Organization locations|
119
- |.organization_end_users(id)|List users|
120
- |.organization_custom_fields(id)|Organization custom fields|
121
- |.organization_devices(id)|Organization devices|
122
- |.organization_locations_backup_usage(id)|Organization location backup usage|
123
- |.organization_backup_usage_by_location(id, location_id)|Organization locations backup usage|
117
+ |`organizations`,`organization(id)`|List organizations or get one by id|
118
+ |`organization_locations(id)`|Organization locations|
119
+ |`organization_end_users(id)`|List users|
120
+ |`organization_custom_fields(id)`|Organization custom fields|
121
+ |`organization_devices(id)`|Organization devices|
122
+ |`organization_locations_backup_usage(id)`|Organization location backup usage|
123
+ |`organization_backup_usage_by_location(id, location_id)`|Organization locations backup usage|
124
124
 
125
125
  ### Backup
126
126
 
@@ -6,32 +6,10 @@ module NinjaOne
6
6
  #
7
7
  # @see https://app.ninjarmm.com/apidocs/?links.active=core#/Backup Ninja One Developer Documentation - Backup section
8
8
  module Backup
9
- # Dynamically defines methods for interacting with NinjaOne API resources.
10
- #
11
- # Depending on the arguments, this will define methods to:
12
- # - Fetch all records for a resource
13
- # - Fetch a specific record by ID
14
- #
15
- # @param method [Symbol] The method name for fetching all records.
16
- # @param path [String] The API path for the resource. Defaults to the method name.
17
- #
18
- # @example Defining endpoints
19
- # api_endpoint :companies, :company
20
- # # Defines:
21
- # # - `companies(params = {})` to fetch all companies.
22
- # # - `company(id, params = {})` to fetch a single company by ID.
23
- def self.backup_endpoint(method, path = method.to_s.tr('_', '-'))
24
- # Define method to fetch all records
25
- send(:define_method, method) do |params = {}|
26
- results = get(api_url(path), params)
27
- results.results
28
- end
29
- end
30
9
 
31
10
  # Backup endpoints (GET)
32
- backup_endpoint(:backup_jobs, 'backup/jobs')
33
- backup_endpoint(:backup_integrity_check_jobs, 'backup/integrity-check-jobs')
34
-
11
+ Client::define_endpoint('backup/jobs')
12
+ Client::define_endpoint('backup/integrity-check-jobs')
35
13
  end
36
14
  end
37
15
  end
@@ -6,43 +6,8 @@ module NinjaOne
6
6
  #
7
7
  # @see https://app.ninjarmm.com/apidocs/?links.active=core#/Devices Ninja One Developer Documentation - Device section
8
8
  module Devices
9
- # Defines a device-specific API endpoint method dynamically.
10
- #
11
- # This helper creates instance methods in the form of:
12
- # device_<method>(id, params = {})
13
- #
14
- # Example:
15
- # device_endpoint(:jobs)
16
- # # => defines #device_jobs(id, params = {})
17
- #
18
- # @param method [Symbol]
19
- # The method name suffix to generate (e.g., :jobs, :alerts).
20
- #
21
- # @param path [String]
22
- # The API path segment. Defaults to the method name with
23
- # underscores replaced by hyphens.
24
- #
25
- # @return [void]
26
- def self.device_endpoint(method, path = method.to_s.tr('_', '-'))
27
- # Define method to fetch all records for device
28
- send(:define_method, "device_#{method}") do |id, params = {}|
29
- get(api_url("device/#{id}/#{path}"), params)
30
- end
31
- end
32
9
 
33
- # Retrieves a single device by ID.
34
- #
35
- # @param id [Integer, String]
36
- # The NinjaOne device ID.
37
- #
38
- # @param params [Hash, nil]
39
- # Optional query parameters.
40
- #
41
- # @return [Hash]
42
- # The device details returned by the API.
43
- def device(id, params = nil)
44
- get(api_url("device/#{id}"), params)
45
- end
10
+ Client::define_endpoint(:device, '')
46
11
 
47
12
  # Device-related GET endpoints.
48
13
  #
@@ -54,10 +19,10 @@ module NinjaOne
54
19
  # device_activities(123, since: '2026-01-01T00:00:00Z')
55
20
  #
56
21
  [:jobs, :activities, :alerts, :disks, :processors, :software, :volumes, :windows_services, :custom_fields,
57
- :os_patch_installs, :software_patch_installs, :last_logged_on_user, :network_interfaces, :os_patches, :software_patches].each do |m|
58
- device_endpoint(m)
22
+ :os_patch_installs, :software_patch_installs, :last_logged_on_user, :network_interfaces, :os_patches, :software_patches].each do |resource|
23
+ Client::define_endpoint(:device, resource.to_s.gsub('_','-'))
59
24
  end
60
- device_endpoint(:policy_overrides, 'policy/overrides')
25
+ Client::define_endpoint(:device, 'policy/overrides')
61
26
  end
62
27
  end
63
28
  end
@@ -6,41 +6,18 @@ module NinjaOne
6
6
  #
7
7
  # @see https://app.ninjarmm.com/apidocs/?links.active=core#/organization Ninja One Developer Documentation
8
8
  module Organizations
9
- # Dynamically defines methods for interacting with NinjaOne API resources.
10
- #
11
- # Depending on the arguments, this will define methods to:
12
- # - Fetch all records for a resource
13
- # - Fetch a specific record by ID
14
- #
15
- # @param method [Symbol] The method name for fetching all records.
16
- # @param singular_method [Symbol, nil] The method name for fetching a single record by ID. Optional.
17
- # @param path [String] The API path for the resource. Defaults to the method name.
18
- #
19
- # @example Defining endpoints
20
- # api_endpoint :companies, :company
21
- # # Defines:
22
- # # - `companies(params = {})` to fetch all companies.
23
- # # - `company(id, params = {})` to fetch a single company by ID.
24
- def self.api_endpoint_suffix(method, suffix)
25
- # Define method to fetch a single record by ID
26
- name = "#{method}_#{suffix.gsub(/[-\/]/,'_')}"
27
9
 
28
- send(:define_method, name) do |id, params = {}|
29
- get(api_url("#{method}/#{id}/#{suffix}"), params)
30
- end
31
- end
32
-
33
- api_endpoint_suffix(:organization, 'locations')
34
- api_endpoint_suffix(:organization, 'end-users')
35
- api_endpoint_suffix(:organization, 'custom-fields')
36
- api_endpoint_suffix(:organization, 'devices')
37
- api_endpoint_suffix(:organization, 'locations/backup/usage')
10
+ Client::define_endpoint(:organization, 'locations')
11
+ Client::define_endpoint(:organization, 'end-users')
12
+ Client::define_endpoint(:organization, 'custom-fields')
13
+ Client::define_endpoint(:organization, 'devices')
14
+ Client::define_endpoint(:organization, 'locations/backup/usage')
38
15
 
39
16
  # Returns a location backup usage
40
17
  def organization_backup_usage_by_location(id, location_id, params={})
41
18
  get(api_url("organization/#{id}/locations/#{location_id}/backup/usage"), params)
42
19
  rescue Faraday::ServerError
43
- # it looks like a server error is thrown when no backup is available; fake it by returning anempty array
20
+ # it looks like a server error is thrown when no backup is available; fake it by returning an empty array
44
21
  []
45
22
  end
46
23
  end
@@ -7,28 +7,30 @@ module NinjaOne
7
7
  # @see https://app.ninjarmm.com/apidocs/?links.active=core#/system Ninja One Developer Documentation
8
8
  module System
9
9
 
10
- Client::api_endpoint(:contacts, :contact)
11
- Client::api_endpoint(:organizations,:organization)
12
- Client::api_endpoint(:organizations_detailed)
13
- Client::api_endpoint(:policies)
14
- Client::api_endpoint(:jobs)
15
- Client::api_endpoint(:activities)
16
- Client::api_endpoint(:alerts)
17
- Client::api_endpoint(:automation_scripts, nil, 'automation/scripts')
18
- Client::api_endpoint(:devices)
19
- Client::api_endpoint(:devices_detailed)
20
- Client::api_endpoint(:enabled_notification_channels, nil, 'notification-channels/enabled')
21
- Client::api_endpoint(:notification_channels)
22
- Client::api_endpoint(:groups)
23
- Client::api_endpoint(:locations)
24
- Client::api_endpoint(:roles)
25
- Client::api_endpoint(:tasks)
26
- Client::api_endpoint(:software_products)
27
- Client::api_endpoint(:users)
28
- Client::api_endpoint(:user_end_users, nil, 'user/end-users')
29
- Client::api_endpoint(:user_roles, nil, 'user/roles')
30
- Client::api_endpoint(:user_technicians, nil, 'user/technicians')
31
- Client::api_endpoint(:devices_search, nil, 'devices/search')
10
+ Client::define_endpoint(:contacts)
11
+ Client::define_endpoint(:contact, '')
12
+ Client::define_endpoint(:organizations)
13
+ Client::define_endpoint(:organization, '')
14
+ Client::define_endpoint('organizations-detailed')
15
+ Client::define_endpoint(:policies)
16
+ Client::define_endpoint(:jobs)
17
+ Client::define_endpoint(:activities)
18
+ Client::define_endpoint(:alerts)
19
+ Client::define_endpoint('automation/scripts')
20
+ Client::define_endpoint(:devices)
21
+ Client::define_endpoint('devices-detailed')
22
+ Client::define_endpoint('notification-channels/enabled')
23
+ Client::define_endpoint('notification-channels')
24
+ Client::define_endpoint(:groups)
25
+ Client::define_endpoint(:locations)
26
+ Client::define_endpoint(:roles)
27
+ Client::define_endpoint(:tasks)
28
+ Client::define_endpoint('software-products')
29
+ Client::define_endpoint(:users)
30
+ Client::define_endpoint('user/end-users')
31
+ Client::define_endpoint('user/roles')
32
+ Client::define_endpoint('user/technicians')
33
+ Client::define_endpoint('devices/search')
32
34
 
33
35
  def search_devices(query_string, options={})
34
36
  devices_search(options.merge({q:query_string}))
@@ -9,34 +9,50 @@ module NinjaOne
9
9
  # @note All methods are grouped in separate modules for better organization and follow the structure provided in the official API documentation.
10
10
  # @see https://developers.skykick.com/Guides/Authentication
11
11
  class Client < API
12
+
13
+ # Constructs url resource name from url path
14
+ #
15
+ # @param path [String] Resource name
16
+ # @return [String] translated from /- to _
17
+ def self.resource_to_name(path)
18
+ path.to_s.gsub(/[-\/]/,'_')
19
+ end
20
+
12
21
  # Dynamically defines methods for interacting with NinjaOne API resources.
13
22
  #
14
23
  # Depending on the arguments, this will define methods to:
15
- # - Fetch all records for a resource
16
- # - Fetch a specific record by ID
24
+ # - Fetch all records for the given scope
25
+ # - Fetch a resource specific record by ID
26
+ #
27
+ # @param scope [Symbol] The method name for fetching all records.
28
+ # @param resource [String] If given, fetches all records for scope by id. If empty string, it will load single scope record
17
29
  #
18
- # @param method [Symbol] The method name for fetching all records.
19
- # @param singular_method [Symbol, nil] The method name for fetching a single record by ID. Optional.
20
- # @param path [String] The API path for the resource. Defaults to the method name.
30
+ # Paging is not supported.
21
31
  #
22
32
  # @example Defining endpoints
23
33
  # api_endpoint :companies, :company
24
34
  # # Defines:
25
35
  # # - `companies(params = {})` to fetch all companies.
26
36
  # # - `company(id, params = {})` to fetch a single company by ID.
27
- def self.api_endpoint(method, singular_method = nil, path = method.to_s.tr('_', '-'))
28
- # Define method to fetch all records
29
- send(:define_method, method) do |params = {}|
30
- get_paged(api_url(path), params)
31
- end
32
- # Define method to fetch a single record by ID
33
- if singular_method
34
- send(:define_method, singular_method) do |id, params = {}|
35
- get(api_url("#{singular_method}/#{id}"), params)
37
+ def self.define_endpoint(scope, resource = nil)
38
+ if resource
39
+ name = self.resource_to_name(scope)
40
+ name = "#{name}_#{self.resource_to_name(resource)}" if resource && !resource.empty?
41
+ # change to nil if resource is empty so we ar eable to generate /scope/id/resource
42
+ # but also /scope/id without training /
43
+ resource = resource&.empty? ? nil : resource
44
+ send(:define_method, name) do |id, params = {}|
45
+ get(api_url([scope, id, resource].compact.join('/')), params)
46
+ end
47
+ else
48
+ name = self.resource_to_name(scope)
49
+ send(:define_method, name) do |params = {}|
50
+ get(api_url(scope), params)
36
51
  end
37
52
  end
38
53
  end
39
54
 
55
+
40
56
  # Dynamically require all files in the `client` directory.
41
57
  # This will load additional API modules as separate files for better modularity and code organization.
42
58
  Dir[File.expand_path('client/*.rb', __dir__)].each { |f| require f }
@@ -56,6 +72,5 @@ module NinjaOne
56
72
  def api_url(path)
57
73
  "/v2/#{path}"
58
74
  end
59
-
60
75
  end
61
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NinjaOne
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninjaone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janco Tanis
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-01-15 00:00:00.000000000 Z
10
+ date: 2026-01-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: faraday