Module: Jamf::Uploadable::ClassMethods

Defined in:
lib/jamf/api/classic/api_objects/uploadable.rb

Overview

Class/Module Methods

Instance Method Summary collapse

Instance Method Details

#upload(ident, type, local_file, force_ipa_upload: false, api: nil, cnx: Jamf.cnx) ⇒ Boolean

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.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/jamf/api/classic/api_objects/uploadable.rb', line 126

def upload(ident, type, local_file, force_ipa_upload: false, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  id = valid_id ident, :refresh, cnx: cnx
  raise "No #{self::RSRC_OBJECT_KEY} matching '#{ident}'" unless id

  # the type has to be defined in the class including this module.
  raise Jamf::InvalidDataError, "#{self::RSRC_LIST_KEY} only take uploads of type: :#{self::UPLOAD_TYPES.keys.join(', :')}." \
    unless self::UPLOAD_TYPES.key? type

  # figure out the resource after the UPLOAD_RSRC_PREFIX
  upload_rsrc = "#{UPLOAD_RSRC_PREFIX}/#{self::UPLOAD_TYPES[type]}/id/#{id}"

  upload_rsrc << "?#{FORCE_IPA_UPLOAD_PARAM}=true" if self::UPLOAD_TYPES[type] == :mobiledeviceapplicationsipa && force_ipa_upload

  cnx.upload upload_rsrc, local_file
end