Method: Jamf::JSONObject#initialize

Defined in:
lib/jamf/api/base_classes/json_object.rb

#initialize(data, cnx: Jamf.cnx) ⇒ JSONObject

Make an instance. Data comes from the API

Parameters:

  • data (Hash)

    the data for constructing a new object.

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

    the API connection for the object

Raises:



850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
# File 'lib/jamf/api/base_classes/json_object.rb', line 850

def initialize(data, cnx: Jamf.cnx)
  raise Jamf::InvalidDataError, 'Invalid JSONObject data - must be a Hash' unless data.is_a? Hash

  @cnx = cnx
  @unsaved_changes = {} if self.class.mutable?

  creating = data.delete :creating_from_create

  if creating
    self.class::OBJECT_MODEL.keys.each do |attr_name|
      next unless data.key? attr_name
      # use our setters for each value so that they are in the unsaved changes
      send "#{attr_name}=", data[attr_name]
    end
    return
  end

  parse_init_data data
end