module Jamf::Uploadable::ClassMethods

Class/Module Methods

Public Instance Methods

upload(ident, type, local_file, force_ipa_upload: false, api: nil, cnx: Jamf.cnx) click to toggle source

Upload a file to the JSS to be stored with an item of the class mixing in the Uploadable module.

This class method does not require fetching a Ruby instance first, but the matching instance method will work for a specific instance if it’s already been fetched.

@param ident[Integer, String] A unique identifier for the object taking the upload

@param type the type of upload happening.

Must be one of the keys defined in the class's UPLOAD_TYPES Hash.

@param local_file[String, Pathname] String or Pathname pointing to the

locally-readable file to be uploaded.

@param force_ipa_upload Should the server upload the .ipa file to

JCDS or AWS if such are confgured for use?

@param cnx [Jamf::Connection] the connection object for the operation.

defaults to the default connection for the JSS module.

@return [Boolean] was the upload successful?

    # File lib/jamf/api/classic/api_objects/uploadable.rb
126 def upload(ident, type, local_file, force_ipa_upload: false, api: nil, cnx: Jamf.cnx)
127   cnx = api if api
128 
129   id = valid_id ident, :refresh, cnx: cnx
130   raise "No #{self::RSRC_OBJECT_KEY} matching '#{ident}'" unless id
131 
132   # the type has to be defined in the class including this module.
133   raise Jamf::InvalidDataError, "#{self::RSRC_LIST_KEY} only take uploads of type: :#{self::UPLOAD_TYPES.keys.join(', :')}." \
134     unless self::UPLOAD_TYPES.key? type
135 
136   # figure out the resource after the UPLOAD_RSRC_PREFIX
137   upload_rsrc = "#{UPLOAD_RSRC_PREFIX}/#{self::UPLOAD_TYPES[type]}/id/#{id}"
138 
139   upload_rsrc << "?#{FORCE_IPA_UPLOAD_PARAM}=true" if self::UPLOAD_TYPES[type] == :mobiledeviceapplicationsipa && force_ipa_upload
140 
141   cnx.upload upload_rsrc, local_file
142 end