ninjaone 0.1.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: b308dc5c61be46c792940ed58dc52596fa4146a1573e49db047396b1f959df61
4
- data.tar.gz: 5cf673637b6af95d97ce82d81fd42970e47608aba6f018412b1d9c219f069c6a
3
+ metadata.gz: 69cf374dfc56664fdbbc61533fcffbc84cc8f378cc422641be286b5740d04d8f
4
+ data.tar.gz: e4f573f19bb88b7173a035622e65a86119ca20276806fa4df2ce40d2752adc29
5
5
  SHA512:
6
- metadata.gz: 07a6c00f22eaaebcf0053a140641f642c93d89cdf898626c08dd72f364a87e55a16266d690571be0a4252e3502265d94619a79c34f7da692b584cce6edb7e410
7
- data.tar.gz: d0a45f7032e93a8581e8a49976fdc7e7e2928cf18f657dd707fedadef5352e0ca84dd48b21ed25d434d9737c3c7597d4acca35bcfb775ffd5782759b0b916b3a
6
+ metadata.gz: '0090ba275e371d7064dee5ca2f432eb239ef6d31aa0aba63849c740834cc0c2cb6456d4d7f588a99475cb9ffa1add1c1349973b61c6c34e5ae3a90ae95b2966f'
7
+ data.tar.gz: 7d07158ecb6ab23ea23587453dfdadaf35df8906c8f5fbefa0c51e220782a866955338ca4dd849e9b49142dfd6c0f428859f60fe8ead3b401c072354489d97e2
data/CHANGELOG.md CHANGED
@@ -4,3 +4,11 @@
4
4
 
5
5
  - Initial release
6
6
 
7
+ ## [0.2.0] - 2026-1-15
8
+
9
+ - Added backup and devices api group
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,51 @@ 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
+
125
+ ### Backup
126
+
127
+ All apis related to backup
128
+
129
+ ```ruby
130
+ # get failed jobs using status filter
131
+ failed_jobs = client.backup_jobs(sf:'status = FAILED')
132
+ ```
133
+
134
+ |Resource|API endpoint|
135
+ |:--|:--|
136
+ |`backup_jobs(params)`|Returns list of backup jobs. Params is a hash for filtering the result|
137
+ |`backup_integrity_check_jobs(params)`|Returns a list of integrity check jobs|
138
+
139
+ ### Devices
140
+
141
+ All apis related to devices.
142
+
143
+ | Resource | API endpoint |
144
+ |:--|:--|
145
+ | `device(id, params = {})` | Retrieves the details of a single device by its device ID. |
146
+ | `device_jobs(id, params = {})` | Retrieves all jobs associated with the specified device. |
147
+ | `device_activities(id, params = {})` | Retrieves activities for the specified device (e.g. filtered using `since`). |
148
+ | `device_alerts(id, params = {})` | Retrieves alerts related to the specified device. |
149
+ | `device_disks(id, params = {})` | Retrieves disk information for the specified device. |
150
+ | `device_processors(id, params = {})` | Retrieves processor information for the specified device. |
151
+ | `device_software(id, params = {})` | Retrieves installed software for the specified device. |
152
+ | `device_volumes(id, params = {})` | Retrieves volume information for the specified device. |
153
+ | `device_windows_services(id, params = {})` | Retrieves Windows services for the specified device. |
154
+ | `device_custom_fields(id, params = {})` | Retrieves custom fields associated with the specified device. |
155
+ | `device_os_patch_installs(id, params = {})` | Retrieves operating system patch installation records for the specified device. |
156
+ | `device_software_patch_installs(id, params = {})` | Retrieves software patch installation records for the specified device. |
157
+ | `device_last_logged_on_user(id, params = {})` | Retrieves information about the last logged-on user of the device. |
158
+ | `device_network_interfaces(id, params = {})` | Retrieves network interface information for the specified device. |
159
+ | `device_os_patches(id, params = {})` | Retrieves available or installed operating system patches for the device. |
160
+ | `device_software_patches(id, params = {})` | Retrieves available or installed software patches for the device. |
161
+ | `device_policy_overrides(id, params = {})` | Retrieves policy overrides applied to the specified device. |
124
162
 
125
163
 
126
164
  ## Contributing
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NinjaOne
4
+ class Client
5
+ # Contains Backup-related API calls for Ninja One.
6
+ #
7
+ # @see https://app.ninjarmm.com/apidocs/?links.active=core#/Backup Ninja One Developer Documentation - Backup section
8
+ module Backup
9
+
10
+ # Backup endpoints (GET)
11
+ Client::define_endpoint('backup/jobs')
12
+ Client::define_endpoint('backup/integrity-check-jobs')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NinjaOne
4
+ class Client
5
+ # Contains Device-related API calls for Ninja One.
6
+ #
7
+ # @see https://app.ninjarmm.com/apidocs/?links.active=core#/Devices Ninja One Developer Documentation - Device section
8
+ module Devices
9
+
10
+ Client::define_endpoint(:device, '')
11
+
12
+ # Device-related GET endpoints.
13
+ #
14
+ # Each symbol below dynamically generates a method:
15
+ # device_<endpoint>(id, params = {})
16
+ #
17
+ # Example:
18
+ # device_jobs(123)
19
+ # device_activities(123, since: '2026-01-01T00:00:00Z')
20
+ #
21
+ [:jobs, :activities, :alerts, :disks, :processors, :software, :volumes, :windows_services, :custom_fields,
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('_','-'))
24
+ end
25
+ Client::define_endpoint(:device, 'policy/overrides')
26
+ end
27
+ end
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 }
@@ -46,6 +62,8 @@ module NinjaOne
46
62
  # such as managing backups and handling alerts.
47
63
  include NinjaOne::Client::System
48
64
  include NinjaOne::Client::Organizations
65
+ include NinjaOne::Client::Backup
66
+ include NinjaOne::Client::Devices
49
67
 
50
68
  # Constructs the full API URL for a given path.
51
69
  #
@@ -54,6 +72,5 @@ module NinjaOne
54
72
  def api_url(path)
55
73
  "/v2/#{path}"
56
74
  end
57
-
58
75
  end
59
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NinjaOne
4
- VERSION = '0.1.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.1.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: 2025-12-10 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
@@ -108,6 +108,8 @@ files:
108
108
  - lib/ninjaone/api.rb
109
109
  - lib/ninjaone/authentication.rb
110
110
  - lib/ninjaone/client.rb
111
+ - lib/ninjaone/client/backup.rb
112
+ - lib/ninjaone/client/devices.rb
111
113
  - lib/ninjaone/client/organizations.rb
112
114
  - lib/ninjaone/client/system.rb
113
115
  - lib/ninjaone/error.rb