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 data as mapped Arrays.
Some API classes provide other data in each Hash, e.g. :udid (for computers and mobile devices) or :is_smart (for groups).
Subclasses implementing those API classes should provide .all_xxx class methods for accessing those other values as mapped Arrays, e.g. JSS::Computer.all_udids
The results of the first query for each subclass is stored in the .object_list_cache of the given JSS::APIConnection and returned at every future call, so as to not requery the server every time.
To force requerying to get updated data, provided a non-false 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.
To query an APIConnection other than the currently active one, provide one via the api: named parameter.
163 164 165 166 167 168 |
# File 'lib/jss/api_object.rb', line 163 def self.all(refresh = false, api: JSS.api) raise JSS::UnsupportedError, '.all can only be called on subclasses of JSS::APIObject' if self == JSS::APIObject api.object_list_cache[self::RSRC_LIST_KEY] = nil if refresh return api.object_list_cache[self::RSRC_LIST_KEY] if api.object_list_cache[self::RSRC_LIST_KEY] api.object_list_cache[self::RSRC_LIST_KEY] = api.get_rsrc(self::RSRC_BASE)[self::RSRC_LIST_KEY] end |