Module: JSS::Uploadable::ClassMethods

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

Overview

Class/Module Methods

Instance Method Summary collapse

Instance Method Details

#upload(ident, type, local_file, force_ipa_upload: false, api: JSS.api) ⇒ 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.

Parameters:

  • ident (Integer, String)

    A unique identifier for the object taking the upload

  • type (Symbol)

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

  • local_file (String, Pathname)

    String or Pathname pointing to the locally-readable file to be uploaded.

  • force_ipa_upload (Boolean) (defaults to: false)

    Should the server upload the .ipa file to JCDS or AWS if such are confgured for use?

  • api (JSS::APIConnection) (defaults to: JSS.api)

    the connection object for the operation. defaults to the default connection for the JSS module.

Returns:

  • (Boolean)

    was the upload successful?

Raises:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/jss/api_object/uploadable.rb', line 126

def upload(ident, type, local_file, force_ipa_upload: false, api: JSS.api)
  id = valid_id ident, :refresh, api: api
  raise "No #{self::RSRC_OBJECT_KEY} matching '#{ident}'" unless id

  # the type has to be defined in the class including this module.
  raise JSS::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

  api.upload upload_rsrc, local_file
end