class Aspose::Cloud::AsposeStorage::Folder

This class provides functionality to manage files in a Remote Aspose Folder

Public Class Methods

new() click to toggle source
# File lib/Storage/folder.rb, line 7
def initialize
  @str_uri_folder = Aspose::Cloud::Common::Product.product_uri + '/storage/folder/'
  @str_uri_file = Aspose::Cloud::Common::Product.product_uri + '/storage/file/'
  @str_uri_exist = Aspose::Cloud::Common::Product.product_uri + '/storage/exist/'
  @str_uri_disc = Aspose::Cloud::Common::Product.product_uri + '/storage/disc/'
end

Public Instance Methods

create_folder(folder_name, storage_type = 'Aspose', storage_name='') click to toggle source

Create a New Folder @param string folder_name Name of the folder.

# File lib/Storage/folder.rb, line 80
def create_folder (folder_name, storage_type = 'Aspose', storage_name='')
    raise 'Folder name cannot be empty' if folder_name.empty?
    str_uri = @str_uri_folder + folder_name
    str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.put(signed_uri, '', :accept => :json)
    JSON.parse(response)['Code'].eql? 200
end
delete_file(filename, storage_type = 'Aspose', storage_name = '') click to toggle source

Delete a Particular File @param string filename Name of the file.

# File lib/Storage/folder.rb, line 64
def delete_file(filename, storage_type = 'Aspose', storage_name = '')
    raise 'File name cannot be empty' if filename.empty?

    str_uri = @str_uri_file + filename
    str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.delete(signed_str_uri, {:accept => 'application/json'})
    JSON.parse(response_stream)['Code'].eql? 200
end
delete_folder(folder_name, storage_type = 'Aspose', storage_name='') click to toggle source

Delete a Particular Folder @param string folder_name Name of the folder.

# File lib/Storage/folder.rb, line 94
def delete_folder (folder_name, storage_type = 'Aspose', storage_name='')
    raise 'Folder name cannot be empty' if folder_name.empty?
    str_uri = @str_uri_folder + folder_name
    str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.delete(signed_uri, :accept => 'application/json')
    JSON.parse(response)['Code'].eql? 200
end
file_exists(filename, storage_type = 'Aspose', storage_name = '') click to toggle source

Check if a file exists on the storage @param string filename Name of the file.

# File lib/Storage/folder.rb, line 48
def file_exists(filename, storage_type = 'Aspose', storage_name = '')
    raise('Filename cannot be empty') if filename.empty?

    str_uri = @str_uri_exist + filename
    str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri, {:accept => 'application/json'})
    JSON.parse(response_stream)['FileExist']['IsExist']
end
get_disc_usage(storage_type = 'Aspose', storage_name = '') click to toggle source

Get Disk Usage

# File lib/Storage/folder.rb, line 107
def get_disc_usage (storage_type = 'Aspose', storage_name = '')
    str_uri = @str_uri_disc
    str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.get(signed_uri, :accept => 'application/json')
    JSON.parse(response)['DiscUsage']
end
get_file(file_name, storage_type = 'Aspose', storage_name = '') click to toggle source

Get file from storage @param string file_name Name of the file.

# File lib/Storage/folder.rb, line 120
def get_file (file_name, storage_type = 'Aspose', storage_name = '')
    raise 'Filename cannot be empty' if file_name.empty?

    str_uri = @str_uri_file + file_name
    str_uri += append_storage(storage_name) unless storage_type.eql? 'Aspose'
    str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    RestClient.get(signed_uri, :accept => 'application/json')
end
get_files(remote_folder_path='', storage_type='Aspose', storage_name='') click to toggle source
Retrieves Files and Folder information from a remote folder

end

# File lib/Storage/folder.rb, line 33
def get_files(remote_folder_path='', storage_type='Aspose', storage_name='')
  str_uri = @str_uri_folder + remote_folder_path
  str_uri = str_uri[0..-2] if str_uri[-1].eql? '/'
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

  signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = RestClient.get(signed_uri, :accept => 'application/json')

  JSON.parse(response)['Files']
end
upload_file(local_file, remote_folder='', storage_type='Aspose', storage_name='') click to toggle source
Uploads file from the local path to the remote folder
@param string localFilePath represents full local file path and name.

end

# File lib/Storage/folder.rb, line 18
def upload_file(local_file, remote_folder='', storage_type='Aspose', storage_name='')
  raise 'Local file not specified' if local_file.empty?

  filename = File.basename(local_file)
  str_uri = "#{ Aspose::Cloud::Common::Product.product_uri }/storage/file/#{ remote_folder + '/' unless remote_folder.empty? }#{ filename }"
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,'',storage_name,storage_type)

  signeduri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = JSON.parse(Aspose::Cloud::Common::Utils.upload_file_binary(local_file, signeduri))
  response['Status'].eql? 'OK'
end