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.

Parameters:

  • id (Integer)

    the id of the object to fetch

  • format (Symbol) (defaults to: :json)

    :json or :xml, defaults to :json

  • as_string (Boolean) (defaults to: false)

    return the raw JSON or XML string as it comes from the API, do not parse into a Hash or REXML::Document

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

    the connection thru which to fetch this object. Defaults to the deault API connection in JSS.api

Returns:

  • (Hash, REXML::Document, String)

    the raw data for the object



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)
  validate_not_metaclass(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