Sha256: 1e0ce3505f94d6218362a78c270714a0ffe72198784f4a316ad940cd2e28cc5d

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'box/item'

module Box
  # Represents a file stored on Box. Any attributes or actions typical to
  # a Box file can be accessed through this class.

  class File < Item
    # (see Item.type)
    def self.type; 'file'; end

    # Download this file to the specified path.
    #
    # @param [String] path The path to write the file.
    def download(path)
      @api.download(path, id)
    end

    # Overwrite this file, using the file at the specified path
    #
    # @param [String] path The path to the file to upload.
    # @return [File] self
    def upload_overwrite(path)
      info = @api.overwrite(path, id)['files']['file']

      clear_info
      update_info(info)

      self
    end

    # Upload a new copy of this file. The name will be "file (#).ext"
    # for the each additional copy.
    #
    # @param path (see #upload_overwrite)
    # @return [File] The newly created file.
    def upload_copy(path)
      info = @api.new_copy(path, id)['files']['file']
      parent.delete_info('files')

      self.class.new(api, parent, info)
    end

    protected

    # (see Item#get_info)
    def get_info
      @api.get_file_info(id)['info']
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
box-api-0.1.9 lib/box/file.rb
box-api-0.1.8 lib/box/file.rb