Method: JSS::APIObject.all_objects

Defined in:
lib/jss/api_object.rb

.all_objects(refresh = false, api: JSS.api) ⇒ Array<APIObject>

Return an Array of JSS::APIObject subclass instances e.g when called on JSS::Package, return a hash of JSS::Package instancesa for every package in the JSS.

WARNING: This may be slow as it has to look up each object individually! use it wisely.

Parameters:

  • refresh (Boolean) (defaults to: false)

    should the data re-queried from the API?

  • api (JSS::APIConnection) (defaults to: JSS.api)

    an API connection to use for the query. Defaults to the corrently active API. See JSS::APIConnection

Returns:



549
550
551
552
553
554
555
556
557
558
559
# File 'lib/jss/api_object.rb', line 549

def self.all_objects(refresh = false, api: JSS.api)
  objects_cache_key ||= "#{self::RSRC_LIST_KEY}_objects".to_sym
  api_cache = api.object_list_cache
  api_cache[objects_cache_key] = nil if refresh

  return api_cache[objects_cache_key] if api_cache[objects_cache_key]
  all = all(refresh, api: api)
  api_cache[objects_cache_key] = all.map do |o|
    fetch id: o[:id], api: api, refresh: false
  end
end