lib/jss/api_object/uploadable.rb
# Upload a file to the JSS via the REST Resource of the
# object to which this module is mixed in.
#
# @param type[Symbol] 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.
#
# @return [String] The xml response from the server.
#
Upload a file to the JSS via the REST Resource of the
object to which this module is mixed in.
Upload a file to the JSS via the REST Resource of the object to which this module is mixed in .
def upload(type, local_file)
      raise JSS::NoSuchItemError, 'Create this #{self.class::RSRC_OBJECT_KEY} in the JSS before uploading files to it.' unless @id && @in_jss
      raise JSS::InvalidDataError, "#{self.class::RSRC_LIST_KEY} only take uploads of type: :#{self.class::UPLOAD_TYPES.keys.join(', :')}." \
        unless self.class::UPLOAD_TYPES.keys.include? type
      upload_rsrc = "#{UPLOAD_RSRC_PREFIX}/#{self.class::UPLOAD_TYPES[type]}/id/#{@id}"
      file = File.new local_file.to_s, 'rb'
      @api.cnx[upload_rsrc].post name: file
    end
def upload ( type , local_file ) raise JSS :: NoSuchItemError , 'Create this #{self.class::RSRC_OBJECT_KEY} in the JSS before uploading files to it.' unless @id && @in_jss raise JSS :: InvalidDataError , "#{self.class::RSRC_LIST_KEY} only take uploads of type: :#{self.class::UPLOAD_TYPES.keys.join(', :')}." unless self . class :: UPLOAD_TYPES . keys . include? type upload_rsrc = "#{UPLOAD_RSRC_PREFIX}/#{self.class::UPLOAD_TYPES[type]}/id/#{@id}" file = File . new local_file . to_s , 'rb' @api . cnx [ upload_rsrc ] . post name : file end
Upload a file to the JSS via the REST Resource of the
object to which this module is mixed in.
Upload a file to the JSS via the REST Resource of the object to which this module is mixed in .
# the thing's gotta be in the JSS, and have an @id # the type has to be defined in the class of self. # figure out the resource after the UPLOAD_RSRC_PREFIX # make a File object to hand to REST. 'rb' = read,binary # upload it!
The xml response from the server.
The xml response from the server .
String
type
the type of upload happening. Must be one of the keys defined in the class's UPLOAD_TYPES Hash.
the type of upload happening . Must be one of the keys defined in the class ' s UPLOAD_TYPES Hash .
local_file
String or Pathname pointing to the locally-readable file to be uploaded.
String or Pathname pointing to the locally - readable file to be uploaded .