Class: Aspose::Cloud::AsposeStorage::Folder

Inherits:
Object
  • Object
show all
Defined in:
lib/Storage/folder.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initializeFolder

Returns a new instance of Folder.



7
8
9
10
11
12
# 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

Instance Method Details

#create_folder(folder_name, storage_type = 'Aspose', storage_name = '') ⇒ Object

Create a New Folder

@param string folder_name Name of the folder.


80
81
82
83
84
85
86
87
88
# 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 = '') ⇒ Object

Delete a Particular File

@param string filename Name of the file.


64
65
66
67
68
69
70
71
72
73
74
# 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 = '') ⇒ Object

Delete a Particular Folder

@param string folder_name Name of the folder.


94
95
96
97
98
99
100
101
102
# 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 = '') ⇒ Object

Check if a file exists on the storage

@param string filename Name of the file.


48
49
50
51
52
53
54
55
56
57
58
# 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 = '') ⇒ Object

Get Disk Usage



107
108
109
110
111
112
113
114
# 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 = '') ⇒ Object

Get file from storage

@param string file_name Name of the file.


120
121
122
123
124
125
126
127
128
129
# 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 = '') ⇒ Object

Retrieves Files and Folder information from a remote folder



33
34
35
36
37
38
39
40
41
42
# 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 = '') ⇒ Object

Uploads file from the local path to the remote folder

@param string localFilePath represents full local file path and name.


18
19
20
21
22
23
24
25
26
27
28
# 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