Method: JSS::APIObject.all
- Defined in:
- lib/jss/api_object.rb
.all(refresh = false, api: JSS.api) ⇒ Array<Hash{:name=>String, :id=> Integer}>
Return an Array of Hashes for all objects of this subclass in the JSS.
This method is only valid in subclasses of JSS::APIObject, and is the parsed JSON output of an API query for the resource defined in the subclass's RSRC_BASE
e.g. for JSS::Computer, with the RSRC_BASE of :computers, This method retuens the output of the 'JSSResource/computers' resource, which is a list of all computers in the JSS.
Each item in the Array is a Hash with at least two keys, :id and :name. The class methods .all_ids and .all_names provide easier access to those dataas mapped Arrays.
Some API classes provide other keys in each Hash, e.g. :udid (for computers and mobile devices) or :is_smart (for groups).
For those keys that are listed in a subclass's lookup_keys method,
there are matching methods .all_(key)s which return an array
just of those values, from the values of this hash. For example,
.all_udids will use the .all array to return an array of just udids,
if the subclass defines :udid in its OTHER_LOOKUP_KEYS (See 'Lookup Keys'
in the class comments/docs above)
Subclasses should provide appropriate .all_xxx class methods for accessing any other other values as Arrays, e.g. JSS::Computer.all_managed
-- Caching
The results of the first call to .all for each subclass is cached in the .object_list_cache of the given JSS::APIConnection and that cache is used for all future calls, so as to not requery the server every time.
To force requerying to get updated data, provided a truthy argument. I usually use :refresh, so that it's obvious what I'm doing, but true, 1, or anything besides false or nil will work.
The various methods that use the output of this method also take the refresh parameter which will be passed here as needed.
-- Alternate API connections
To query an APIConnection other than the currently active one, provide one via the api: named parameter.
450 451 452 453 454 455 456 457 458 459 |
# File 'lib/jss/api_object.rb', line 450 def self.all(refresh = false, api: JSS.api) (self) cache = api.object_list_cache cache_key = self::RSRC_LIST_KEY api.flushcache(cache_key) if refresh return cache[cache_key] if cache[cache_key] cache[cache_key] = api.get_rsrc(self::RSRC_BASE)[cache_key] end |