Method: JSS::Creatable#create

Defined in:
lib/jss/api_object/creatable.rb

#createInteger

Create a new object in the JSS.

Parameters:

  • api (JSS::APIConnection)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (Integer)

    the jss ID of the newly created object

Raises:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/jss/api_object/creatable.rb', line 74

def create
  raise JSS::UnsupportedError, "Creating or editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless creatable?

  raise AlreadyExistsError, "This #{self.class::RSRC_OBJECT_KEY} already exists. Use #update to make changes." if @in_jss

  @api.post_rsrc(rest_rsrc, rest_xml) =~ %r{><id>(\d+)</id><}
  @id = Regexp.last_match(1).to_i
  @in_jss = true
  @need_to_update = false
  @rest_rsrc = "#{self.class::RSRC_BASE}/id/#{@id}"

  # clear any caches for this class
  # so they'll re-cache as needed
  @api.flushcache self.class::RSRC_LIST_KEY

  @id
end