Method: JSS::APIObject.get_raw
- Defined in:
- lib/jss/api_object.rb
.get_raw(id, format: :json, as_string: false, api: JSS.api) ⇒ Hash, ...
Fetch the mostly- or fully-raw JSON or XML data for an object of this subclass.
By default, returns the JSON data parsed into a Hash.
When format: is anything but :json, returns the XML data parsed into a REXML::Document
When as_string: is truthy, returns an unparsed JSON String (or XML String if format: is not :json) as it comes directly from the API.
When fetching raw JSON, the returned Hash will have its keys symbolized.
This can be substantialy faster than instantiating, especially when you don't need
all the ruby goodness of a full instance, but just want a few values for
an object that aren't available in the all data
This is really just a wrapper around JSS::APIConnection#get_rsrc that automatically fills in the RSRC::BASE value for you.
891 892 893 894 895 896 897 898 899 900 |
# File 'lib/jss/api_object.rb', line 891 def self.get_raw(id, format: :json, as_string: false, api: JSS.api) (self) rsrc = "#{self::RSRC_BASE}/id/#{id}" data = api.get_rsrc rsrc, format, raw_json: as_string return data if format == :json || as_string REXML::Document.new(data) rescue RestClient::NotFound raise JSS::NoSuchItemError, "No #{self} with id #{id}" end |