Method: Jamf::APIObject.get_raw

Defined in:
lib/jamf/api/classic/base_classes/api_object.rb

.get_raw(id, format: :json, as_string: false, api: nil, cnx: Jamf.cnx) ⇒ 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 Connection.c_get 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

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    the connection thru which to fetch this object. Defaults to the deault API connection in Jamf.cnx

Returns:

  • (Hash, REXML::Document, String)

    the raw data for the object



1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
# File 'lib/jamf/api/classic/base_classes/api_object.rb', line 1050

def self.get_raw(id, format: :json, as_string: false, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  validate_not_metaclass(self)
  rsrc = "#{self::RSRC_BASE}/id/#{id}"
  data = cnx.c_get rsrc, format, raw_json: as_string
  return data if format == :json || as_string

  REXML::Document.new(**data)
end