module Jamf::Updatable

A mix-in module that allows objects to be updated in the JSS via the API.

When a Jamf::APIObject subclass includes this module, instances of that subclass can be modified in the JSS using the {#update} or {APIObject#save} methods.

Such classes should define setter methods for any values that they wish to modify, such as the {#name=} method defined here. Those setter methods must:

Classes mixing this module must provide a rest_xml instance method that returns the XML String to be submitted to the API for object updating.

@see_also APIObject#save

Constants

UPDATABLE

Constants

Attributes

need_to_update[R]

@return [Boolean] do we have unsaved changes?

Public Instance Methods

name=(newname) click to toggle source

Change the name of this item Remember to update to push changes to the server.

@param newname the new name

@return [void]

   # File lib/jamf/api/classic/api_objects/updatable.rb
77 def name=(newname)
78   return nil if @name == newname
79   raise Jamf::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless updatable?
80   raise Jamf::InvalidDataError, "Names can't be empty!" if newname.to_s.empty?
81   raise Jamf::AlreadyExistsError, "A #{self.class::RSRC_OBJECT_KEY} named '#{newname}' already exsists in the JSS" \
82     if self.class.all_names(:refresh, cnx: @cnx).include? newname
83   @name = newname
84   @rest_rsrc = "#{self.class::RSRC_BASE}/name/#{CGI.escape @name.to_s}" if @rest_rsrc.include? '/name/'
85   @need_to_update = true
86 end

Private Instance Methods

update_in_jamf() click to toggle source

Save changes to the JSS

@return [Integer] The object id

    # File lib/jamf/api/classic/api_objects/updatable.rb
 92 def update_in_jamf
 93   return nil unless @need_to_update
 94   raise Jamf::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless updatable?
 95 
 96   @cnx.c_put @rest_rsrc, rest_xml
 97   @need_to_update = false
 98   refresh_icon if self_servable?
 99 
100   # clear any cached all-lists or id-maps for this class
101   # so they'll re-cache as needed
102   @cnx.flushcache self.class::RSRC_LIST_KEY
103 
104   @id
105 end