ruby-jss 1.2.3 → 1.2.4a1

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.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jamf.rb +169 -0
  3. data/lib/jamf/api/abstract_classes/collection_resource.rb +422 -0
  4. data/lib/jamf/api/abstract_classes/generic_reference.rb +145 -0
  5. data/lib/jamf/api/abstract_classes/json_object.rb +1074 -0
  6. data/lib/jamf/api/abstract_classes/prestage.rb +219 -0
  7. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +126 -0
  8. data/lib/jamf/api/abstract_classes/resource.rb +250 -0
  9. data/lib/jamf/api/abstract_classes/singleton_resource.rb +87 -0
  10. data/lib/jamf/api/attribute_classes/ip_address.rb +66 -0
  11. data/lib/jamf/api/attribute_classes/timestamp.rb +144 -0
  12. data/lib/jamf/api/connection.rb +734 -0
  13. data/lib/jamf/api/connection/api_error.rb +111 -0
  14. data/lib/jamf/api/connection/api_error_styleguide.rb +96 -0
  15. data/lib/jamf/api/connection/token.rb +220 -0
  16. data/lib/jamf/api/json_objects/account_prefs.rb +79 -0
  17. data/lib/jamf/api/json_objects/android_details.rb +139 -0
  18. data/lib/jamf/api/json_objects/appletv_details.rb +110 -0
  19. data/lib/jamf/api/json_objects/attachment.rb +68 -0
  20. data/lib/jamf/api/json_objects/cellular_network.rb +151 -0
  21. data/lib/jamf/api/json_objects/change_log_entry.rb +77 -0
  22. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +67 -0
  23. data/lib/jamf/api/json_objects/country.rb +51 -0
  24. data/lib/jamf/api/json_objects/extension_attribute_value.rb +128 -0
  25. data/lib/jamf/api/json_objects/installed_application.rb +59 -0
  26. data/lib/jamf/api/json_objects/installed_certificate.rb +53 -0
  27. data/lib/jamf/api/json_objects/installed_configuration_profile.rb +67 -0
  28. data/lib/jamf/api/json_objects/installed_ebook.rb +58 -0
  29. data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +59 -0
  30. data/lib/jamf/api/json_objects/inventory_preload_extension_attribute.rb +52 -0
  31. data/lib/jamf/api/json_objects/ios_details.rb +244 -0
  32. data/lib/jamf/api/json_objects/location.rb +95 -0
  33. data/lib/jamf/api/json_objects/md_prestage_name.rb +57 -0
  34. data/lib/jamf/api/json_objects/md_prestage_names.rb +82 -0
  35. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +165 -0
  36. data/lib/jamf/api/json_objects/mobile_device_details.rb +219 -0
  37. data/lib/jamf/api/json_objects/mobile_device_security.rb +101 -0
  38. data/lib/jamf/api/json_objects/prestage_assignment.rb +61 -0
  39. data/lib/jamf/api/json_objects/prestage_location.rb +104 -0
  40. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +132 -0
  41. data/lib/jamf/api/json_objects/prestage_scope.rb +54 -0
  42. data/lib/jamf/api/json_objects/prestage_sync_status.rb +63 -0
  43. data/lib/jamf/api/json_objects/purchasing_data.rb +125 -0
  44. data/lib/jamf/api/mixins/abstract.rb +58 -0
  45. data/lib/jamf/api/mixins/bulk_deletable.rb +39 -0
  46. data/lib/jamf/api/mixins/change_log.rb +136 -0
  47. data/lib/jamf/api/mixins/extendable.rb +75 -0
  48. data/lib/jamf/api/mixins/immutable.rb +39 -0
  49. data/lib/jamf/api/mixins/locatable.rb +124 -0
  50. data/lib/jamf/api/mixins/lockable.rb +48 -0
  51. data/lib/jamf/api/mixins/referable.rb +92 -0
  52. data/lib/jamf/api/mixins/searchable.rb +202 -0
  53. data/lib/jamf/api/mixins/uncreatable.rb +40 -0
  54. data/lib/jamf/api/mixins/undeletable.rb +40 -0
  55. data/lib/jamf/api/resources/collection_resources/account.rb +163 -0
  56. data/lib/jamf/api/resources/collection_resources/building.rb +114 -0
  57. data/lib/jamf/api/resources/collection_resources/category.rb +82 -0
  58. data/lib/jamf/api/resources/collection_resources/computer.rb +49 -0
  59. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +80 -0
  60. data/lib/jamf/api/resources/collection_resources/department.rb +79 -0
  61. data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +45 -0
  62. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +274 -0
  63. data/lib/jamf/api/resources/collection_resources/md_prestage.rb +139 -0
  64. data/lib/jamf/api/resources/collection_resources/mobile_device.rb +315 -0
  65. data/lib/jamf/api/resources/collection_resources/script.rb +190 -0
  66. data/lib/jamf/api/resources/collection_resources/site.rb +77 -0
  67. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +131 -0
  68. data/lib/jamf/api/resources/singleton_resources/authorization.rb +88 -0
  69. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +139 -0
  70. data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +95 -0
  71. data/lib/jamf/client.rb +301 -0
  72. data/lib/jamf/client/jamf_binary.rb +132 -0
  73. data/lib/jamf/client/jamf_helper.rb +298 -0
  74. data/lib/jamf/client/management_action.rb +114 -0
  75. data/lib/jamf/compatibility.rb +88 -0
  76. data/lib/jamf/composer.rb +190 -0
  77. data/lib/jamf/configuration.rb +281 -0
  78. data/lib/jamf/exceptions.rb +107 -0
  79. data/lib/jamf/ruby_extensions.rb +36 -0
  80. data/lib/jamf/ruby_extensions/array.rb +35 -0
  81. data/lib/jamf/ruby_extensions/array/predicates.rb +46 -0
  82. data/lib/jamf/ruby_extensions/array/utils.rb +47 -0
  83. data/lib/jamf/ruby_extensions/filetest.rb +32 -0
  84. data/lib/jamf/ruby_extensions/filetest/predicates.rb +46 -0
  85. data/lib/jamf/ruby_extensions/hash.rb +33 -0
  86. data/lib/jamf/ruby_extensions/hash/backports.rb +92 -0
  87. data/lib/jamf/ruby_extensions/ipaddr.rb +37 -0
  88. data/lib/jamf/ruby_extensions/ipaddr/utils.rb +95 -0
  89. data/lib/jamf/ruby_extensions/object.rb +30 -0
  90. data/lib/jamf/ruby_extensions/object/predicates.rb +51 -0
  91. data/lib/jamf/ruby_extensions/pathname.rb +39 -0
  92. data/lib/jamf/ruby_extensions/pathname/predicates.rb +50 -0
  93. data/lib/jamf/ruby_extensions/pathname/utils.rb +75 -0
  94. data/lib/jamf/ruby_extensions/string.rb +35 -0
  95. data/lib/jamf/ruby_extensions/string/backports.rb +66 -0
  96. data/lib/jamf/ruby_extensions/string/conversions.rb +65 -0
  97. data/lib/jamf/ruby_extensions/string/predicates.rb +47 -0
  98. data/lib/jamf/utility.rb +423 -0
  99. data/lib/jamf/validate.rb +224 -0
  100. data/lib/jamf/version.rb +32 -0
  101. data/lib/jpapi.rb +26 -0
  102. data/lib/jss/version.rb +1 -1
  103. metadata +104 -4
@@ -0,0 +1,219 @@
1
+ # Copyright 2019 Pixar
2
+
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ # with the following modification; you may not use this file except in
6
+ # compliance with the Apache License and the following modification to it:
7
+ # Section 6. Trademarks. is deleted and replaced with:
8
+ #
9
+ # 6. Trademarks. This License does not grant permission to use the trade
10
+ # names, trademarks, service marks, or product names of the Licensor
11
+ # and its affiliates, except as required to comply with Section 4(c) of
12
+ # the License and to reproduce the content of the NOTICE file.
13
+ #
14
+ # You may obtain a copy of the Apache License at
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the Apache License with the above modification is
20
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ # KIND, either express or implied. See the Apache License for the specific
22
+ # language governing permissions and limitations under the Apache License.
23
+ #
24
+ #
25
+
26
+ # The Module
27
+ module Jamf
28
+
29
+ # Classes
30
+ #####################################
31
+
32
+ # A building defined in the JSS
33
+ class Prestage < Jamf::CollectionResource
34
+
35
+ extend Jamf::Abstract
36
+ include Jamf::Lockable
37
+
38
+ # Constants
39
+ #####################################
40
+
41
+ # Object Model / Attributes
42
+ # See APIObject class documentation for details
43
+ # of how the OBJECT_MODEL hash works.
44
+ #####################################
45
+ OBJECT_MODEL = {
46
+
47
+ # @!attribute [r] id
48
+ # @return [Integer]
49
+ id: {
50
+ class: :integer,
51
+ identifier: :primary,
52
+ readonly: true
53
+ },
54
+
55
+ # @!attribute displayName
56
+ # @return [String]
57
+ displayName: {
58
+ class: :string,
59
+ identifier: true,
60
+ validator: :non_empty_string,
61
+ required: true,
62
+ aliases: %i[name]
63
+ },
64
+
65
+ # @!attribute isMandatory
66
+ # @return [Boolean]
67
+ isMandatory: {
68
+ class: :boolean
69
+ },
70
+
71
+ # @!attribute isMdmRemovable
72
+ # @return [Boolean]
73
+ isMdmRemovable: {
74
+ class: :boolean
75
+ },
76
+
77
+ # @!attribute supportPhoneNumber
78
+ # @return [String]
79
+ supportPhoneNumber: {
80
+ class: :string
81
+ },
82
+
83
+ # @!attribute supportEmailAddress
84
+ # @return [String]
85
+ supportEmailAddress: {
86
+ class: :string
87
+ },
88
+
89
+ # @!attribute department
90
+ # @return [String]
91
+ department: {
92
+ class: :string
93
+ },
94
+
95
+ # @!attribute isDefaultPrestage
96
+ # @return [Boolean]
97
+ isDefaultPrestage: {
98
+ class: :boolean
99
+ },
100
+
101
+ # @!attribute enrollmentSiteId
102
+ # @return [Integer]
103
+ enrollmentSiteId: {
104
+ class: :integer
105
+ },
106
+
107
+ # @!attribute isKeepExistingSiteMembership
108
+ # @return [Boolean]
109
+ isKeepExistingSiteMembership: {
110
+ class: :boolean
111
+ },
112
+
113
+ # @!attribute isKeepExistingLocationInformation
114
+ # @return [Boolean]
115
+ isKeepExistingLocationInformation: {
116
+ class: :boolean
117
+ },
118
+
119
+ # @!attribute isRequireAuthentication
120
+ # @return [Boolean]
121
+ isRequireAuthentication: {
122
+ class: :boolean
123
+ },
124
+
125
+ # @!attribute authenticationPrompt
126
+ # @return [String]
127
+ authenticationPrompt: {
128
+ class: :string
129
+ },
130
+
131
+ # @!attribute isEnableDeviceBasedActivationLock
132
+ # @return [Boolean]
133
+ isEnableDeviceBasedActivationLock: {
134
+ class: :boolean
135
+ },
136
+
137
+ # @!attribute deviceEnrollmentProgramInstanceId
138
+ # @return [Integer]
139
+ deviceEnrollmentProgramInstanceId: {
140
+ class: :integer
141
+ },
142
+
143
+ # @!attribute locationInformation
144
+ # @return [Jamf::ComputerPrestageSkipSetupItems]
145
+ locationInformation: {
146
+ class: Jamf::PrestageLocation,
147
+ aliases: %i[location]
148
+ },
149
+
150
+ # @!attribute skipSetupItems
151
+ # @return [Jamf::ComputerPrestageSkipSetupItems]
152
+ purchasingInformation: {
153
+ class: Jamf::PrestagePurchasingData,
154
+ aliases: %i[purchasing]
155
+ },
156
+
157
+ # @!attribute anchorCertificates
158
+ # @return [Array<String>]
159
+ anchorCertificates: {
160
+ class: :string,
161
+ multi: true
162
+ },
163
+
164
+ # @!attribute enrollmentCustomizationId
165
+ # @return [Integer]
166
+ enrollmentCustomizationId: {
167
+ class: :integer
168
+ },
169
+
170
+ # @!attribute profileUUID
171
+ # @return [String]
172
+ profileUUID: {
173
+ class: :string
174
+ },
175
+
176
+ # @!attribute siteId
177
+ # @return [Integer]
178
+ siteId: {
179
+ class: :integer
180
+ }
181
+
182
+ }.freeze
183
+
184
+ SCOPE_RSRC = 'scope'.freeze
185
+
186
+ SERIALS_KEY = :serialsByPrestageId
187
+
188
+ SYNC_RSRC = 'sync'.freeze
189
+
190
+ # Class Methods
191
+ #####################################
192
+
193
+ # Return all scoped computer serial numbers and the id of the prestage
194
+ # they are assigned to
195
+ #
196
+ # @param cnx[Jamf::Connection] the API connection to use
197
+ #
198
+ # @return [Hash {String => Integer}] The Serials and prestage IDs
199
+ #
200
+ def self.serials_by_prestage_id(cnx: Jamf.cnx)
201
+ @serials_by_prestage_rsrc ||= "#{self::RSRC_VERSION}/#{self::RSRC_PATH}/#{SCOPE_RSRC}"
202
+ cnx.get(@serials_by_prestage_rsrc)[SERIALS_KEY].transform_keys!(&:to_s)
203
+ end
204
+
205
+ # Instance Methods
206
+ #####################################
207
+
208
+ def scope(refresh = false)
209
+ @scope = nil if refresh
210
+ return @scope if @scope
211
+
212
+ @scope_rsrc ||= "#{self.class::RSRC_VERSION}/#{self.class::RSRC_PATH}/#{@id}/#{SCOPE_RSRC}"
213
+
214
+ @scope = Jamf::PrestageScope.new @cnx.get @scope_rsrc
215
+ end
216
+
217
+ end # class
218
+
219
+ end # module
@@ -0,0 +1,126 @@
1
+ # Copyright 2019 Pixar
2
+
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ # with the following modification; you may not use this file except in
6
+ # compliance with the Apache License and the following modification to it:
7
+ # Section 6. Trademarks. is deleted and replaced with:
8
+ #
9
+ # 6. Trademarks. This License does not grant permission to use the trade
10
+ # names, trademarks, service marks, or product names of the Licensor
11
+ # and its affiliates, except as required to comply with Section 4(c) of
12
+ # the License and to reproduce the content of the NOTICE file.
13
+ #
14
+ # You may obtain a copy of the Apache License at
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the Apache License with the above modification is
20
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ # KIND, either express or implied. See the Apache License for the specific
22
+ # language governing permissions and limitations under the Apache License.
23
+ #
24
+ #
25
+
26
+ # The module
27
+ module Jamf
28
+
29
+ # A class that represents the 'Skip' settings for
30
+ # various Setup options in a DEP prestage
31
+ # The object model here includes the attributes common
32
+ # to both Computer and MobileDevice prestages
33
+ class PrestageSkipSetupItems < Jamf::JSONObject
34
+
35
+ extend Jamf::Abstract
36
+
37
+ OBJECT_MODEL = {
38
+
39
+ # @!attribute Appearance
40
+ # @return [Boolean]
41
+ Appearance: {
42
+ class: :boolean,
43
+ aliases: %i[appearance]
44
+ },
45
+
46
+ # @!attribute AppleID
47
+ # @return [Boolean]
48
+ AppleID: {
49
+ class: :boolean,
50
+ aliases: %i[appleID appleid apple_id]
51
+ },
52
+
53
+ # @!attribute Biometric
54
+ # @return [Boolean]
55
+ Biometric: {
56
+ class: :boolean,
57
+ aliases: %i[biometric]
58
+ },
59
+
60
+ # @!attribute Diagnostics
61
+ # @return [Boolean]
62
+ Diagnostics: {
63
+ class: :boolean,
64
+ aliases: %i[diagnostics]
65
+ },
66
+
67
+ # @!attribute DisplayTone
68
+ # @return [Boolean]
69
+ DisplayTone: {
70
+ class: :boolean,
71
+ aliases: %i[displaytone display_tone]
72
+ },
73
+
74
+ # @!attribute Location
75
+ # @return [Boolean]
76
+ Location: {
77
+ class: :boolean,
78
+ aliases: %i[location]
79
+ },
80
+
81
+ # @!attribute Payment
82
+ # @return [Boolean]
83
+ Payment: {
84
+ class: :boolean,
85
+ aliases: %i[payment]
86
+ },
87
+
88
+ # @!attribute Privacy
89
+ # @return [Boolean]
90
+ Privacy: {
91
+ class: :boolean,
92
+ aliases: %i[privacy]
93
+ },
94
+
95
+ # @!attribute Restore
96
+ # @return [Boolean]
97
+ Restore: {
98
+ class: :boolean,
99
+ aliases: %i[restore]
100
+ },
101
+
102
+ # @!attribute ScreenTime
103
+ # @return [Boolean]
104
+ ScreenTime: {
105
+ class: :boolean,
106
+ aliases: %i[screenTime screentime]
107
+ },
108
+
109
+ # @!attribute Siri
110
+ # @return [Boolean]
111
+ Siri: {
112
+ class: :boolean,
113
+ aliases: %i[siri]
114
+ },
115
+
116
+ # @!attribute TOS
117
+ # @return [Boolean]
118
+ TOS: {
119
+ class: :boolean,
120
+ aliases: %i[tos terms_of_service]
121
+ }
122
+ }.freeze
123
+
124
+ end # class location
125
+
126
+ end # module
@@ -0,0 +1,250 @@
1
+ # Copyright 2019 Pixar
2
+
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ # with the following modification; you may not use this file except in
6
+ # compliance with the Apache License and the following modification to it:
7
+ # Section 6. Trademarks. is deleted and replaced with:
8
+ #
9
+ # 6. Trademarks. This License does not grant permission to use the trade
10
+ # names, trademarks, service marks, or product names of the Licensor
11
+ # and its affiliates, except as required to comply with Section 4(c) of
12
+ # the License and to reproduce the content of the NOTICE file.
13
+ #
14
+ # You may obtain a copy of the Apache License at
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the Apache License with the above modification is
20
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ # KIND, either express or implied. See the Apache License for the specific
22
+ # language governing permissions and limitations under the Apache License.
23
+ #
24
+ #
25
+
26
+ # The module
27
+ module Jamf
28
+
29
+ # Classes
30
+ #####################################
31
+
32
+ # @see_also Jamf::JSONObject
33
+ #
34
+ # Jamf::Resource represents a thing directly accessible in the API. It
35
+ # will contain one or more API endpoints.
36
+ #
37
+ # A resource has a base URI path in the API used for
38
+ # interacting with the resource and directly-related sub-resources.
39
+ #
40
+ # For example, the device-reenrollment settings are a resource at the url path
41
+ #
42
+ # > .../uapi/v1/reenrollment
43
+ #
44
+ # and the related sub-resource for the change history of the reenrollment
45
+ # settings is at
46
+ #
47
+ # > .../uapi/v1/reenrollment/history
48
+ #
49
+ # All resources based at .../uapi/v1/reenrollment are encapsulated
50
+ # in the class {Jamf::ReEnrollmentSettings}, a descendent of Jamf::Resource
51
+ #
52
+ # There are two types of resources: Singletons and Collections.
53
+ #
54
+ # **Singleton resources** have only one instance available in the API, and they
55
+ # cannot be create or deleted, only fetched and usually updated, tho some cant
56
+ # be updated either, e.g. Jamf::AppStoreCountryCodes. The device-reenrollment
57
+ # settings mentioned above are an example of a Singleton resource.
58
+ # When the resource is fetched from the API, it is cached, and (usually) future
59
+ # fetching will return the same instance. See {Jamf::SingletonResource} for
60
+ # details.
61
+ #
62
+ # **Collection resources** have more than one resource within them, and those
63
+ # can (usually) be created and deleted as well as fetched and updated.
64
+ # The entire collection (or a part of it) can also be fetched as an Array.
65
+ # When the whole collection is fetched, the result is cached for future use.
66
+ # See {Jamf::CollectionResource} for details.
67
+ #
68
+ # # Instantiating Resources
69
+ #
70
+ # For all subclasses of Jamf::Resource, using the ruby standard .new class
71
+ # method to instantiate an object will raise an exception. We do this to avoid
72
+ # the ambiguity of the word 'new' in this context.
73
+ #
74
+ # Normally in ruby, .new means 'make a new instance of this class in memory'.
75
+ # But with Jamf Resoureces, when making a new instance in memory, we might be
76
+ # making an instance of a resource that already exists in Jamf Pro, or perhaps
77
+ # making an instance of a 'new' thing that we want to create in Jamf Pro,
78
+ # but doesn't exist there at the moment.
79
+ #
80
+ # While we could look at the parameters passed to decide which of those two
81
+ # things we're doing, (and require specific parameters for each action), that
82
+ # doesn't change the fact that a human _reading_ the line:
83
+ #
84
+ # a_building = Jamf::Building.new name: 'Main Building'
85
+ #
86
+ # sounds like we want to create a new building in the JSS, when in fact we're
87
+ # just retrieving one that's already there.
88
+ #
89
+ # To make the code more readable and totally clear, .new is not allowed for
90
+ # making instances of Jamf::Resources. Instead, use the class method .fetch
91
+ # to retrieve existing resources, like so:
92
+ #
93
+ # a_building = Jamf::Building.fetch name: 'Main Building'
94
+ #
95
+ # This makes it clear what the code is doing, and when you get the error that
96
+ # there's no building with that name, the error makes sense, which it
97
+ # wouldn't if you were creating a new building in the JSS.
98
+ #
99
+ # Likewise, to make a new one in Jamf Pro, use .create, as in:
100
+ #
101
+ # a_building = Jamf::Building.create name: 'Main Building'
102
+ #
103
+ # This makes it obvious that we're creating a new building in the JSS
104
+ #
105
+ # In both cases, the instance method #save is used to send your changes to the
106
+ # API. If the resource already exists, the changes will be applied to the
107
+ # server with #save. If it doesn't yet exist, it will be created by #save.
108
+ #
109
+ #
110
+ # # Subclassing
111
+ #
112
+ #
113
+ # ### Required Constant: RSRC_VERSION
114
+ #
115
+ # The version of the resource model supported by ruby-jss for this class.
116
+ #
117
+ # Every resource in the Jamf Pro API has a version as part of its URL path.
118
+ # For example, in the full resource URL:
119
+ #
120
+ # https://your.jamf.server:port/uapi/v1/reenrollment
121
+ #
122
+ # the resource version is `v1`. At any given time, the API may have many
123
+ # versions of a resource available - v2 might be released with new values
124
+ # available or deprecated values removed, but v1 remains and is unchanged.
125
+ #
126
+ # Each subclass of Jamf::Resource must define RSRC_VERSION as a
127
+ # String, e.g. 'v1', which defines the version supported by the subclass.
128
+ #
129
+ # As new versions are released by Jamf, when the changes are implemented
130
+ # in ruby-jss, the RSRC_VERSION is updated.
131
+ #
132
+ # ## Required Constant: OBJECT_MODEL
133
+ #
134
+ # This is required of all {Jamf::JSONObject} subclasses. Refer to that
135
+ # documentation for full details about implementing the OBJECT_MODEL constant.
136
+ #
137
+ # ## Required Constant: RSRC_PATH
138
+ #
139
+ # This is the URI path to the resource, relative to the API base and version
140
+ # ('uapi/vX/').
141
+ #
142
+ # Examples:
143
+ #
144
+ # 1. For SingletonResource class {Jamf::Settings::ReEnrollment}, the URL to
145
+ # the resource is:
146
+ #
147
+ # https://your.jamf.server:port/uapi/v1/reenrollment
148
+ #
149
+ # and that URL is used to GET and PUT data, and as a base for the change
150
+ # log data.
151
+ #
152
+ # The constant {Jamf::Settings::ReEnrollment::RSRC_PATH} must be
153
+ # `'reenrollment'`
154
+ #
155
+ # 2. For CollectionResource class {Jamf::MobileDevice}, the URL to the
156
+ # collection Array is:
157
+ #
158
+ # https://your.jamf.server:port/uapi/v1/mobile-devices
159
+ #
160
+ # and that URL is used to GET lists of mobileDevice data and POST data
161
+ # to create a new mobile device.
162
+ # It is also the base URL for GET, PATCH, PUT and DELETE for individual
163
+ # mobileDevices, and their details and change log data.
164
+ #
165
+ # The constant {Jamf::MobileDevice::RSRC_PATH} must be
166
+ # `'mobile-devices'`
167
+ #
168
+ # ## Required Constant: RSRC_VERSION
169
+ #
170
+ # As shown in the examples above, the URL paths for resources have a
171
+ # version number between 'uapi' and the RSRC_PATH
172
+ #
173
+ # Both SingletonResources and CollectionResources must defing the constant
174
+ # RSRC_VERSION as a string containing that version, e.g. 'v1'
175
+ #
176
+ # ruby-jss doesn't support the older resource paths that don't have a version
177
+ # in their path.
178
+ #
179
+ # @abstract
180
+ #
181
+ class Resource < Jamf::JSONObject
182
+
183
+ extend Jamf::Abstract
184
+
185
+ # Constants
186
+ #####################################
187
+
188
+ # These methods are allowed to call .new
189
+ NEW_CALLERS = ['fetch', 'create', 'all', 'block in all'].freeze
190
+
191
+ # The resource version for previewing new features
192
+ RSRC_PREVIEW_VERSION = 'preview'.freeze
193
+
194
+ # Public Class Methods
195
+ #####################################
196
+
197
+ # the resource path for this resource
198
+ # @return [String]
199
+ def self.rsrc_path
200
+ "#{self::RSRC_VERSION}/#{self::RSRC_PATH}"
201
+ end
202
+
203
+ def self.preview_path
204
+ "#{RSRC_PREVIEW_VERSION}/#{self::RSRC_PATH}"
205
+ end
206
+
207
+ # Disallow direct use of ruby's .new class method for creating instances.
208
+ # Require use of .fetch or .create.
209
+ #
210
+ def self.new(data, cnx: Jamf.cnx)
211
+ calling_method = caller_locations(1..1).first.label
212
+ raise Jamf::UnsupportedError, "Use .fetch or .create to instantiate Jamf::Resource's" unless NEW_CALLERS.include? calling_method
213
+
214
+ super
215
+ end
216
+
217
+ # Attributes
218
+ #####################################
219
+
220
+ # @return [String] the resouce path for this object
221
+ attr_reader :rsrc_path
222
+
223
+
224
+ # Instance Methods
225
+ #####################################
226
+
227
+ # TODO: error handling
228
+ def save
229
+ raise Jamf::UnsupportedError, "#{self.class} objects cannot be changed" unless self.class.mutable?
230
+
231
+ return unless unsaved_changes?
232
+
233
+ exist? ? update_in_jamf : create_in_jamf
234
+ clear_unsaved_changes
235
+
236
+ @id ? @id : :saved
237
+ end
238
+
239
+ # Private Instance Methods
240
+ #####################################
241
+ private
242
+
243
+ # TODO: handle PATCH when it becomes a thing
244
+ def update_in_jamf
245
+ @cnx.put( rsrc_path, to_jamf)
246
+ end
247
+
248
+ end # class APIObject
249
+
250
+ end # module JAMF