lib/jss/api_object/mdm.rb
# Convert the targets provided for sending a command into
# the final list of computers or mobile devices.
#
# @param targets[String,Integer,Array] See {#send_mdm_command}
#
# @param expand_groups[Boolean] Should groups be expanded into member ids?
#
# @param api[JSS::APIConnection] an API connection to use.
#
# @return [Array<Integer>] The ids of the target devices for a command
#
Convert the targets provided for sending a command into
the final list of computers or mobile devices.
Convert the targets provided for sending a command into the final list of computers or mobile devices .
def raw_targets_to_ids(targets, api: JSS.api, expand_groups: true)
        targets = targets.is_a?(Array) ? targets : [targets]
        api.flushcache self::RSRC_LIST_KEY
        targets.map! do |md|
          id = valid_id md, api: api
          raise JSS::NoSuchItemError, "No #{self} matches identifier: #{md}" unless id
          id
        end 
        if expand_groups && GROUP_TARGETS.include?(self::MDM_COMMAND_TARGET)
          target_ids = []
          targets.each { |group_id| target_ids += fetch(id: group_id).member_ids }
          targets = target_ids
        end
        all_mgd = map_all_ids_to(:managed, api: api).select { |_id, mgd| mgd }.keys
        targets.each do |target_id|
          raise JSS::UnmanagedError, "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd.include? target_id
        end
        targets
      end
def raw_targets_to_ids ( targets , api : JSS . api , expand_groups : true ) targets = targets . is_a? ( Array ) ? targets : [ targets ] api . flushcache self :: RSRC_LIST_KEY targets . map! do | md | id = valid_id md , api : api raise JSS :: NoSuchItemError , "No #{self} matches identifier: #{md}" unless id id end if expand_groups && GROUP_TARGETS . include? ( self :: MDM_COMMAND_TARGET ) target_ids = [ ] targets . each { | group_id | target_ids += fetch ( id : group_id ) . member_ids } targets = target_ids end all_mgd = map_all_ids_to ( :managed , api : api ) . select { | _id , mgd | mgd } . keys targets . each do | target_id | raise JSS :: UnmanagedError , "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd . include? target_id end targets end
Convert the targets provided for sending a command into
the final list of computers or mobile devices.
Convert the targets provided for sending a command into the final list of computers or mobile devices .
# flush caches before checking ids and managment # make sure its an array of ids # map! # expand group members if needed # make sure all of them are managed, or else the API will raise a 400 # 'Bad Request' when sending the command to an unmanaged target
The ids of the target devices for a command
The ids of the target devices for a command
Array<Integer>
targets
None
api
an API connection to use.
an API connection to use .
expand_groups
None