ruby-jss 0.9.2 → 0.10.0a1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ruby-jss might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGES.md +13 -1
- data/README.md +7 -7
- data/bin/cgrouper +6 -6
- data/bin/netseg-update +1 -1
- data/lib/jss.rb +1 -0
- data/lib/jss/api_connection.rb +428 -44
- data/lib/jss/api_object.rb +119 -68
- data/lib/jss/api_object/account.rb +12 -12
- data/lib/jss/api_object/advanced_search.rb +12 -12
- data/lib/jss/api_object/categorizable.rb +4 -4
- data/lib/jss/api_object/category.rb +2 -2
- data/lib/jss/api_object/computer.rb +111 -58
- data/lib/jss/api_object/computer_invitation.rb +2 -2
- data/lib/jss/api_object/creatable.rb +19 -8
- data/lib/jss/api_object/criteriable/criteria.rb +8 -8
- data/lib/jss/api_object/distribution_point.rb +14 -48
- data/lib/jss/api_object/extension_attribute.rb +14 -11
- data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +18 -18
- data/lib/jss/api_object/group.rb +7 -7
- data/lib/jss/api_object/ldap_server.rb +51 -60
- data/lib/jss/api_object/locatable.rb +2 -2
- data/lib/jss/api_object/matchable.rb +8 -9
- data/lib/jss/api_object/mobile_device.rb +61 -59
- data/lib/jss/api_object/mobile_device_application.rb +3 -3
- data/lib/jss/api_object/network_segment.rb +24 -19
- data/lib/jss/api_object/package.rb +6 -6
- data/lib/jss/api_object/peripheral.rb +5 -5
- data/lib/jss/api_object/policy.rb +5 -5
- data/lib/jss/api_object/restricted_software.rb +4 -4
- data/lib/jss/api_object/scopable/scope.rb +3 -3
- data/lib/jss/api_object/script.rb +1 -1
- data/lib/jss/api_object/self_servable.rb +3 -3
- data/lib/jss/api_object/self_servable/icon.rb +7 -2
- data/lib/jss/api_object/updatable.rb +2 -2
- data/lib/jss/api_object/uploadable.rb +1 -1
- data/lib/jss/api_object/user.rb +2 -2
- data/lib/jss/composer.rb +37 -10
- data/lib/jss/ruby_extensions/string.rb +51 -42
- data/lib/jss/server.rb +27 -6
- data/lib/jss/utility.rb +44 -0
- data/lib/jss/validate.rb +85 -0
- data/lib/jss/version.rb +1 -1
- metadata +5 -4
@@ -141,7 +141,7 @@ module JSS
|
|
141
141
|
# no change, go home.
|
142
142
|
return nil if new_name == @category_name
|
143
143
|
|
144
|
-
raise JSS::NoSuchItemError, "Category '#{new_cat}' is not known to the JSS" unless JSS::Category.all_names(:ref).include? new_name
|
144
|
+
raise JSS::NoSuchItemError, "Category '#{new_cat}' is not known to the JSS" unless JSS::Category.all_names(:ref, api: @api).include? new_name
|
145
145
|
|
146
146
|
@category_name = new_name
|
147
147
|
@category_id = new_id
|
@@ -149,7 +149,7 @@ module JSS
|
|
149
149
|
end # category =
|
150
150
|
|
151
151
|
# Given a category name or id, return the name and id
|
152
|
-
#
|
152
|
+
# TODO: use APIObject.exist? and/or APIObject.valid_id
|
153
153
|
# @param new_cat[String, Integer] The name or id of a possible category
|
154
154
|
#
|
155
155
|
# @return [Array<String, Integer>] The matching name and id, which may be nil.
|
@@ -158,10 +158,10 @@ module JSS
|
|
158
158
|
# if we were given anything but a string, assume it was an id.
|
159
159
|
if new_cat.is_a? String
|
160
160
|
new_name = new_cat
|
161
|
-
new_id = JSS::Category.category_id_from_name new_cat
|
161
|
+
new_id = JSS::Category.category_id_from_name new_cat, api: @api
|
162
162
|
else
|
163
163
|
new_id = new_cat
|
164
|
-
new_name = JSS::Category.map_all_ids_to(:name)[new_id]
|
164
|
+
new_name = JSS::Category.map_all_ids_to(:name, api: @api)[new_id]
|
165
165
|
end
|
166
166
|
[new_name, new_id]
|
167
167
|
end
|
@@ -50,10 +50,10 @@ module JSS
|
|
50
50
|
# Class Methods
|
51
51
|
#####################################
|
52
52
|
|
53
|
-
def self.category_id_from_name(name)
|
53
|
+
def self.category_id_from_name(name, api: JSS.api)
|
54
54
|
return nil if name.nil?
|
55
55
|
return nil if name.casecmp(JSS::Category::NO_CATEGORY_NAME).zero?
|
56
|
-
JSS::Category.map_all_ids_to(:name).invert[name]
|
56
|
+
JSS::Category.map_all_ids_to(:name, api: api).invert[name]
|
57
57
|
end # self cat id from name
|
58
58
|
|
59
59
|
# Class Constants
|
@@ -44,7 +44,12 @@ module JSS
|
|
44
44
|
# * barcodes 1 and 2
|
45
45
|
# * ip_address
|
46
46
|
# * udid
|
47
|
-
# *
|
47
|
+
# * mac_address & alt_mac_address
|
48
|
+
# * serial_number
|
49
|
+
# Note: Even tho the webUI doesn't allow editing the serial_number,
|
50
|
+
# the API does, and it can be useful for dealing with duplicates
|
51
|
+
# that arise when a logic-board swap causes a new computer record.
|
52
|
+
# to be created.
|
48
53
|
# * location data via the Locatable module
|
49
54
|
# * purchasing data via the Purchasable module
|
50
55
|
# * Extension Attribute values via the Extendable module
|
@@ -333,22 +338,28 @@ module JSS
|
|
333
338
|
# Currently this is read-only in ruby-jss, even tho the API
|
334
339
|
# allows updating.
|
335
340
|
#
|
341
|
+
# @param api[JSS::APIConnection] an API connection to use for the query.
|
342
|
+
# Defaults to the corrently active API. See {JSS::APIConnection}
|
343
|
+
#
|
336
344
|
# @return [Hash] the Computer Checkin Settings from the
|
337
345
|
# currently connected JSS.
|
338
346
|
#
|
339
|
-
def self.checkin_settings
|
340
|
-
|
347
|
+
def self.checkin_settings(api: JSS.api)
|
348
|
+
api.get_rsrc(CHECKIN_RSRC)[CHECKIN_KEY]
|
341
349
|
end
|
342
350
|
|
343
351
|
# Display the current Computer Inventory Collection settings in the JSS.
|
344
352
|
# Currently this is read-only in ruby-jss, even tho the API
|
345
353
|
# allows updating.
|
346
354
|
#
|
355
|
+
# @param api[JSS::APIConnection] an API connection to use for the query.
|
356
|
+
# Defaults to the corrently active API. See {JSS::APIConnection}
|
357
|
+
#
|
347
358
|
# @return [Hash] the Computer Inventpry Collection Settings from the
|
348
359
|
# currently connected JSS.
|
349
360
|
#
|
350
|
-
def self.inventory_collection_settings
|
351
|
-
|
361
|
+
def self.inventory_collection_settings(api: JSS.api)
|
362
|
+
api.get_rsrc(INV_COLLECTION_RSRC)[INV_COLLECTION_KEY]
|
352
363
|
end
|
353
364
|
|
354
365
|
# A larger set of info about the computers in the JSS.
|
@@ -365,82 +376,85 @@ module JSS
|
|
365
376
|
#
|
366
377
|
# @param refresh[Boolean] should the data be re-queried from the API?
|
367
378
|
#
|
379
|
+
# @param api[JSS::APIConnection] an API connection to use for the query.
|
380
|
+
# Defaults to the corrently active API. See {JSS::APIConnection}
|
381
|
+
#
|
368
382
|
# @return [Array<Hash{:name=>String, :id=> Integer}>]
|
369
383
|
#
|
370
|
-
def self.all(refresh = false)
|
371
|
-
|
372
|
-
return
|
373
|
-
|
384
|
+
def self.all(refresh = false, api: JSS.api)
|
385
|
+
api.object_list_cache[RSRC_LIST_KEY] = nil if refresh
|
386
|
+
return api.object_list_cache[RSRC_LIST_KEY] if api.object_list_cache[RSRC_LIST_KEY]
|
387
|
+
api.object_list_cache[RSRC_LIST_KEY] = api.get_rsrc(self::LIST_RSRC)[self::RSRC_LIST_KEY]
|
374
388
|
end
|
375
389
|
|
376
390
|
# @return [Array<String>] all computer serial numbers in the jss
|
377
|
-
def self.all_serial_numbers(refresh = false)
|
378
|
-
all(refresh).map { |i| i[:serial_number] }
|
391
|
+
def self.all_serial_numbers(refresh = false, api: JSS.api)
|
392
|
+
all(refresh, api: api).map { |i| i[:serial_number] }
|
379
393
|
end
|
380
394
|
|
381
395
|
# @return [Array<String>] all computer mac_addresses in the jss
|
382
|
-
def self.all_mac_addresses(refresh = false)
|
383
|
-
all(refresh).map { |i| i[:mac_address] }
|
396
|
+
def self.all_mac_addresses(refresh = false, api: JSS.api)
|
397
|
+
all(refresh, api: api).map { |i| i[:mac_address] }
|
384
398
|
end
|
385
399
|
|
386
400
|
# @return [Array<String>] all computer udids in the jss
|
387
|
-
def self.all_udids(refresh = false)
|
388
|
-
all(refresh).map { |i| i[:udid] }
|
401
|
+
def self.all_udids(refresh = false, api: JSS.api)
|
402
|
+
all(refresh, api: api).map { |i| i[:udid] }
|
389
403
|
end
|
390
404
|
|
391
405
|
# @return [Array<Hash>] all managed computers in the jss
|
392
|
-
def self.all_managed(refresh = false)
|
393
|
-
all(refresh).select { |d| d[:managed] }
|
406
|
+
def self.all_managed(refresh = false, api: JSS.api)
|
407
|
+
all(refresh, api: api).select { |d| d[:managed] }
|
394
408
|
end
|
395
409
|
|
396
410
|
# @return [Array<Hash>] all unmanaged computers in the jss
|
397
|
-
def self.all_unmanaged(refresh = false)
|
398
|
-
all(refresh).reject { |d| d[:managed] }
|
411
|
+
def self.all_unmanaged(refresh = false, api: JSS.api)
|
412
|
+
all(refresh, api: api).reject { |d| d[:managed] }
|
399
413
|
end
|
400
414
|
|
401
415
|
# @return [Array<Hash>] all laptop computers in the jss
|
402
|
-
def self.all_laptops(refresh = false)
|
403
|
-
all(refresh).select { |d| d[:model] =~ /book/i }
|
416
|
+
def self.all_laptops(refresh = false, api: JSS.api)
|
417
|
+
all(refresh, api: api).select { |d| d[:model] =~ /book/i }
|
404
418
|
end
|
405
419
|
|
406
420
|
# @return [Array<Hash>] all macbooks in the jss
|
407
|
-
def self.all_macbooks(refresh = false)
|
408
|
-
all(refresh).select { |d| d[:model] =~ /^macbook\d/i }
|
421
|
+
def self.all_macbooks(refresh = false, api: JSS.api)
|
422
|
+
all(refresh, api: api).select { |d| d[:model] =~ /^macbook\d/i }
|
409
423
|
end
|
410
424
|
|
411
425
|
# @return [Array<Hash>] all macbookpros in the jss
|
412
|
-
def self.all_macbookpros(refresh = false)
|
413
|
-
all(refresh).select { |d| d[:model] =~ /^macbookpro\d/i }
|
426
|
+
def self.all_macbookpros(refresh = false, api: JSS.api)
|
427
|
+
all(refresh, api: api).select { |d| d[:model] =~ /^macbookpro\d/i }
|
414
428
|
end
|
415
429
|
|
416
430
|
# @return [Array<Hash>] all macbookairs in the jss
|
417
|
-
def self.all_macbookairs(refresh = false)
|
418
|
-
all(refresh).select { |d| d[:model] =~ /^macbookair\d/i }
|
431
|
+
def self.all_macbookairs(refresh = false, api: JSS.api)
|
432
|
+
all(refresh, api: api).select { |d| d[:model] =~ /^macbookair\d/i }
|
419
433
|
end
|
420
434
|
|
421
435
|
# @return [Array<Hash>] all xserves in the jss
|
422
|
-
def self.all_xserves(refresh = false)
|
423
|
-
all(refresh).select { |d| d[:model] =~ /serve/i }
|
436
|
+
def self.all_xserves(refresh = false, api: JSS.api)
|
437
|
+
all(refresh, api: api).select { |d| d[:model] =~ /serve/i }
|
424
438
|
end
|
425
439
|
|
426
440
|
# @return [Array<Hash>] all desktop macs in the jss
|
427
|
-
def self.all_desktops(refresh = false)
|
428
|
-
all(refresh).reject { |d| d[:model] =~ /serve|book/i }
|
441
|
+
def self.all_desktops(refresh = false, api: JSS.api)
|
442
|
+
all(refresh, api: api).reject { |d| d[:model] =~ /serve|book/i }
|
429
443
|
end
|
430
444
|
|
431
445
|
# @return [Array<Hash>] all imacs in the jss
|
432
|
-
def self.all_imacs(refresh = false)
|
433
|
-
all(refresh).select { |d| d[:model] =~ /^imac/i }
|
446
|
+
def self.all_imacs(refresh = false, api: JSS.api)
|
447
|
+
all(refresh, api: api).select { |d| d[:model] =~ /^imac/i }
|
434
448
|
end
|
435
449
|
|
436
450
|
# @return [Array<Hash>] all mac minis in the jss
|
437
|
-
def self.all_minis(refresh = false)
|
438
|
-
all(refresh).select { |d| d[:model] =~ /^macmini/i }
|
451
|
+
def self.all_minis(refresh = false, api: JSS.api)
|
452
|
+
all(refresh, api: api).select { |d| d[:model] =~ /^macmini/i }
|
439
453
|
end
|
440
454
|
|
441
455
|
# @return [Array<Hash>] all macpros in the jss
|
442
|
-
def self.all_macpros(refresh = false)
|
443
|
-
all(refresh).select { |d| d[:model] =~ /^macpro/i }
|
456
|
+
def self.all_macpros(refresh = false, api: JSS.api)
|
457
|
+
all(refresh, api: api).select { |d| d[:model] =~ /^macpro/i }
|
444
458
|
end
|
445
459
|
|
446
460
|
# Send an MDM command to one or more managed computers by id or name
|
@@ -455,10 +469,13 @@ module JSS
|
|
455
469
|
#
|
456
470
|
# @param passcode[String] some commands require a 6-character passcode
|
457
471
|
#
|
472
|
+
# @param api[JSS::APIConnection] an API connection to use for the query.
|
473
|
+
# Defaults to the corrently active API. See {JSS::APIConnection}
|
474
|
+
#
|
458
475
|
# @return [String] The uuid of the MDM command sent, if applicable
|
459
476
|
# (blank pushes do not generate uuids)
|
460
477
|
#
|
461
|
-
def self.send_mdm_command(targets, command, passcode = nil)
|
478
|
+
def self.send_mdm_command(targets, command, passcode = nil, api: JSS.api)
|
462
479
|
raise JSS::NoSuchItemError, "Unknown command '#{command}'" unless COMPUTER_MDM_COMMANDS.keys.include? command
|
463
480
|
|
464
481
|
command = COMPUTER_MDM_COMMANDS[command]
|
@@ -475,10 +492,10 @@ module JSS
|
|
475
492
|
|
476
493
|
# make sure its an array of ids
|
477
494
|
targets.map! do |comp|
|
478
|
-
if all_ids.include? comp.to_i
|
495
|
+
if all_ids(api: api).include? comp.to_i
|
479
496
|
comp.to_i
|
480
|
-
elsif all_names.include? comp
|
481
|
-
map_all_ids_to(:name).invert[comp]
|
497
|
+
elsif all_names(api: api).include? comp
|
498
|
+
map_all_ids_to(:name, api: api).invert[comp]
|
482
499
|
else
|
483
500
|
raise JSS::NoSuchItemError, "No computer found matching '#{comp}'"
|
484
501
|
end # if
|
@@ -486,11 +503,12 @@ module JSS
|
|
486
503
|
|
487
504
|
cmd_rsrc << "/id/#{targets.join ','}"
|
488
505
|
|
489
|
-
result =
|
506
|
+
result = api.post_rsrc cmd_rsrc, nil
|
490
507
|
result =~ %r{<command_uuid>(.*)</command_uuid>}
|
491
508
|
Regexp.last_match(1)
|
492
509
|
end # send mdm command
|
493
510
|
|
511
|
+
|
494
512
|
# Attributes
|
495
513
|
#####################################
|
496
514
|
|
@@ -814,6 +832,9 @@ module JSS
|
|
814
832
|
# Get application usage data for this computer
|
815
833
|
# for a given date range.
|
816
834
|
#
|
835
|
+
# TODO: Make this a class method so we can retrieve it without
|
836
|
+
# instantiating the Computer.
|
837
|
+
#
|
817
838
|
# @param start_date [String,Date,DateTime,Time]
|
818
839
|
#
|
819
840
|
# @param end_date [String,Date,DateTime,Time] Defaults to start_date
|
@@ -834,7 +855,7 @@ module JSS
|
|
834
855
|
end
|
835
856
|
start_date = start_date.strftime APPLICATION_USAGE_DATE_FMT
|
836
857
|
end_date = end_date.strftime APPLICATION_USAGE_DATE_FMT
|
837
|
-
data =
|
858
|
+
data = @api.get_rsrc(APPLICATION_USAGE_RSRC + "/id/#{@id}/#{start_date}_#{end_date}")
|
838
859
|
parsed_data = {}
|
839
860
|
data[APPLICATION_USAGE_KEY].each do |day_hash|
|
840
861
|
date = Date.parse day_hash[:date]
|
@@ -854,6 +875,9 @@ module JSS
|
|
854
875
|
# map the array to just those values, so subset: :smart_groups, only: :name
|
855
876
|
# will return an array of names of smartgroups that contain this computer.
|
856
877
|
#
|
878
|
+
# TODO: Make this a class method so we can retrieve it without
|
879
|
+
# instantiating the Computer.
|
880
|
+
#
|
857
881
|
# @param subset[Symbol] Fetch only a subset of data, as an array.
|
858
882
|
# must be one of the symbols in MGMT_DATA_SUBSETS
|
859
883
|
#
|
@@ -880,7 +904,7 @@ module JSS
|
|
880
904
|
@management_data[:full] = nil if refresh
|
881
905
|
return @management_data[:full] if @management_data[:full]
|
882
906
|
mgmt_rsrc = MGMT_DATA_RSRC + "/id/#{@id}"
|
883
|
-
@management_data[:full] =
|
907
|
+
@management_data[:full] = @api.get_rsrc(mgmt_rsrc)[MGMT_DATA_KEY]
|
884
908
|
@management_data[:full]
|
885
909
|
end
|
886
910
|
private :full_management_data
|
@@ -890,7 +914,7 @@ module JSS
|
|
890
914
|
@management_data[subset] = nil if refresh
|
891
915
|
return @management_data[subset] if @management_data[subset]
|
892
916
|
subset_rsrc = MGMT_DATA_RSRC + "/id/#{@id}/subset/#{subset}"
|
893
|
-
@management_data[subset] =
|
917
|
+
@management_data[subset] = @api.get_rsrc(subset_rsrc)[MGMT_DATA_KEY]
|
894
918
|
return @management_data[subset] unless only
|
895
919
|
@management_data[subset].map { |d| d[only] }
|
896
920
|
end
|
@@ -948,6 +972,9 @@ module JSS
|
|
948
972
|
# WARNING! Its huge, better to use a subset a
|
949
973
|
# nd one of the shortcut methods.
|
950
974
|
#
|
975
|
+
# TODO: Make this a class method so we can retrieve it without
|
976
|
+
# instantiating the Computer.
|
977
|
+
#
|
951
978
|
# @param subset[Symbol] the subset to return, rather than full history.
|
952
979
|
#
|
953
980
|
# @param refresh[Boolean] should we re-cache the data from the API?
|
@@ -969,7 +996,7 @@ module JSS
|
|
969
996
|
@history[:full] = nil if refresh
|
970
997
|
return @history[:full] if @history[:full]
|
971
998
|
history_rsrc = HISTORY_RSRC + "/id/#{@id}"
|
972
|
-
@history[:full] =
|
999
|
+
@history[:full] = @api.get_rsrc(history_rsrc)[HISTORY_KEY]
|
973
1000
|
@history[:full]
|
974
1001
|
end
|
975
1002
|
private :full_history
|
@@ -979,7 +1006,7 @@ module JSS
|
|
979
1006
|
@history[subset] = nil if refresh
|
980
1007
|
return @history[subset] if @history[subset]
|
981
1008
|
subset_rsrc = HISTORY_RSRC + "/id/#{@id}/subset/#{subset}"
|
982
|
-
@history[subset] =
|
1009
|
+
@history[subset] = @api.get_rsrc(subset_rsrc)[HISTORY_KEY]
|
983
1010
|
@history[subset]
|
984
1011
|
end
|
985
1012
|
private :history_subset
|
@@ -1074,8 +1101,7 @@ module JSS
|
|
1074
1101
|
def make_unmanaged
|
1075
1102
|
return nil unless managed?
|
1076
1103
|
set_management_to(nil, nil)
|
1077
|
-
|
1078
|
-
self.class.send_mdm_command(@id, :unmanage_device)
|
1104
|
+
@unmange_at_update = true
|
1079
1105
|
end
|
1080
1106
|
|
1081
1107
|
#
|
@@ -1105,10 +1131,35 @@ module JSS
|
|
1105
1131
|
#
|
1106
1132
|
def ip_address=(new_val)
|
1107
1133
|
return nil if @ip_address == new_val
|
1108
|
-
new_val.
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1134
|
+
@ip_address = new_val.empty? ? new_val : JSS::Validate.ip_address(new_val)
|
1135
|
+
@need_to_update = true
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
#
|
1139
|
+
def mac_address=(new_val)
|
1140
|
+
return nil if new_val == @mac_address
|
1141
|
+
@mac_address = new_val.empty? ? new_val : JSS::Validate.mac_address(new_val)
|
1142
|
+
@need_to_update = true
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
#
|
1146
|
+
def alt_mac_address=(new_val)
|
1147
|
+
return nil if new_val == @alt_mac_address
|
1148
|
+
@alt_mac_address = new_val.empty? ? new_val : JSS::Validate.mac_address(new_val)
|
1149
|
+
@need_to_update = true
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
#
|
1153
|
+
def serial_number=(new_val)
|
1154
|
+
return nil if new_val == @serial_number
|
1155
|
+
@serial_number = new_val.empty? ? new_val : JSS::Validate.unique_identifier(JSS::Computer, :serial_number, new_val)
|
1156
|
+
@need_to_update = true
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
#
|
1160
|
+
def udid=(new_val)
|
1161
|
+
return nil if new_val == @udid
|
1162
|
+
@udid = new_val.empty? ? new_val : JSS::Validate.unique_identifier(JSS::Computer, :udid, new_val)
|
1112
1163
|
@need_to_update = true
|
1113
1164
|
end
|
1114
1165
|
|
@@ -1118,7 +1169,8 @@ module JSS
|
|
1118
1169
|
#
|
1119
1170
|
def update
|
1120
1171
|
id = super
|
1121
|
-
|
1172
|
+
remove_mdm_profile if mdm_capable && managed? && @unmange_at_update
|
1173
|
+
@unmange_at_update = false
|
1122
1174
|
id
|
1123
1175
|
end
|
1124
1176
|
|
@@ -1172,7 +1224,7 @@ module JSS
|
|
1172
1224
|
# See JSS::Computer.send_mdm_command
|
1173
1225
|
#
|
1174
1226
|
def blank_push
|
1175
|
-
self.class.send_mdm_command @id, :blank_push
|
1227
|
+
self.class.send_mdm_command @id, :blank_push, api: @api
|
1176
1228
|
end
|
1177
1229
|
alias noop blank_push
|
1178
1230
|
alias send_blank_push blank_push
|
@@ -1182,7 +1234,7 @@ module JSS
|
|
1182
1234
|
# See JSS::Computer.send_mdm_command
|
1183
1235
|
#
|
1184
1236
|
def device_lock(passcode)
|
1185
|
-
self.class.send_mdm_command @id, :device_lock, passcode
|
1237
|
+
self.class.send_mdm_command @id, :device_lock, passcode, api: @api
|
1186
1238
|
end
|
1187
1239
|
alias lock device_lock
|
1188
1240
|
alias lock_device device_lock
|
@@ -1192,7 +1244,7 @@ module JSS
|
|
1192
1244
|
# See JSS::Computer.send_mdm_command
|
1193
1245
|
#
|
1194
1246
|
def erase_device(passcode)
|
1195
|
-
self.class.send_mdm_command @id, :erase_device, passcode
|
1247
|
+
self.class.send_mdm_command @id, :erase_device, passcode, api: @api
|
1196
1248
|
end
|
1197
1249
|
alias erase erase_device
|
1198
1250
|
alias wipe erase_device
|
@@ -1206,7 +1258,7 @@ module JSS
|
|
1206
1258
|
# See JSS::Computer.send_mdm_command
|
1207
1259
|
#
|
1208
1260
|
def remove_mdm_profile
|
1209
|
-
self.class.send_mdm_command
|
1261
|
+
self.class.send_mdm_command @id, :unmanage_device, api: @api
|
1210
1262
|
end
|
1211
1263
|
|
1212
1264
|
# aliases
|
@@ -1246,6 +1298,7 @@ module JSS
|
|
1246
1298
|
general.add_element('ip_address').text = @ip_address
|
1247
1299
|
general.add_element('mac_address').text = @mac_address
|
1248
1300
|
general.add_element('udid').text = @udid
|
1301
|
+
general.add_element('serial_number').text = @serial_number
|
1249
1302
|
|
1250
1303
|
rmgmt = general.add_element('remote_management')
|
1251
1304
|
rmgmt.add_element('managed').text = @managed
|
@@ -58,8 +58,8 @@ module JSS
|
|
58
58
|
# Class Methods
|
59
59
|
#####################################
|
60
60
|
|
61
|
-
def self.all_invitations
|
62
|
-
all.map { |ci| ci[:invitation] }
|
61
|
+
def self.all_invitations(refresh = false, api: JSS.api)
|
62
|
+
all(refresh, api: api).map { |ci| ci[:invitation] }
|
63
63
|
end
|
64
64
|
|
65
65
|
# Class Constants
|
@@ -69,14 +69,18 @@ module JSS
|
|
69
69
|
### Mixed-in Instance Methods
|
70
70
|
#####################################
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
# Create a new object in the JSS.
|
73
|
+
#
|
74
|
+
# @param api[JSS::APIConnection] the API in which to create the object
|
75
|
+
# Defaults to the API used to instantiate this object
|
76
|
+
#
|
77
|
+
# @return [Integer] the jss ID of the newly created object
|
78
|
+
#
|
79
|
+
def create(api: nil)
|
80
|
+
api ||= @api
|
77
81
|
raise JSS::UnsupportedError, "Creating or editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless respond_to? :create
|
78
82
|
raise AlreadyExistsError, "This #{self.class::RSRC_OBJECT_KEY} already exists. Use #update to make changes." if @in_jss
|
79
|
-
|
83
|
+
api.post_rsrc(@rest_rsrc, rest_xml) =~ %r{><id>(\d+)</id><}
|
80
84
|
@id = Regexp.last_match(1).to_i
|
81
85
|
@in_jss = true
|
82
86
|
@need_to_update = false
|
@@ -88,12 +92,16 @@ module JSS
|
|
88
92
|
###
|
89
93
|
### @param name [String] the name for the new object
|
90
94
|
###
|
95
|
+
### @param api[JSS::APIConnection] the API in which to create the object
|
96
|
+
### Defaults to the API used to instantiate this object
|
97
|
+
###
|
91
98
|
### @return [APIObject] An uncreated clone of this APIObject with the given name
|
92
99
|
###
|
93
|
-
def clone(new_name)
|
100
|
+
def clone(new_name, api: nil)
|
101
|
+
api ||= @api
|
94
102
|
raise JSS::UnsupportedError, 'This class is not creatable in via ruby-jss' unless respond_to? :create
|
95
103
|
raise JSS::AlreadyExistsError, "A #{self.class::RSRC_OBJECT_KEY} already exists with that name" if \
|
96
|
-
self.class.all_names.include? new_name
|
104
|
+
self.class.all_names(:refresh, api: api).include? new_name
|
97
105
|
|
98
106
|
orig_in_jss = @in_jss
|
99
107
|
@in_jss = false
|
@@ -101,12 +109,15 @@ module JSS
|
|
101
109
|
@id = nil
|
102
110
|
orig_rsrc = @rest_rsrc
|
103
111
|
@rest_rsrc = "#{self.class::RSRC_BASE}/name/#{CGI.escape new_name}"
|
112
|
+
orig_api = @api
|
113
|
+
@api = api
|
104
114
|
|
105
115
|
new_obj = dup
|
106
116
|
|
107
117
|
@in_jss = orig_in_jss
|
108
118
|
@id = orig_id
|
109
119
|
@rest_rsrc = orig_rsrc
|
120
|
+
@api = orig_api
|
110
121
|
new_obj.name = new_name
|
111
122
|
|
112
123
|
new_obj
|