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.



8
9
10
11
12
13
# File 'lib/Storage/folder.rb', line 8

def initialize
  @str_uri_folder = $product_uri + '/storage/folder'
  @str_uri_file = $product_uri + '/storage/file/'
  @str_uri_exist = $product_uri + '/storage/exist/'
  @str_uri_disc = $product_uri + '/storage/disc/'
end

Instance Method Details

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



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/Storage/folder.rb', line 151

def create_folder (folder_name,storage_type = 'Aspose',storage_name='')
  begin
    if folder_name==''
      raise 'Filename cannot be empty'
    end
    str_uri = @str_uri_folder + folder_name
    if(!storage_name.empty?)
      str_uri += '?storage=' + storage_name
    end
    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.put(signed_uri, :accept=>'application/json')
    json = JSON.parse(response)
    if json['Code'] ==200
      return true
    else
      return false
    end
  rescue Exception => e
    print e
  end
end

#delete_file(filename, storage_type = 'Aspose', storage_name = '') ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/Storage/folder.rb', line 123

def delete_file(filename,storage_type = 'Aspose' , storage_name = '')
  begin

    if(filename == '')
      raise('Filename cannot be empty')
    end                

    str_uri = @str_uri_file + filename
    if(!storage_name.empty?)
      str_uri += '?storage=' + storage_name
    end
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.delete(signed_str_uri, {:accept=>'application/json'})

    stream_hash = JSON.parse(response_stream)

    if(stream_hash['Code'] != 200)
      return false
    else
      return true
    end                

  rescue Exception=>e
    print e
  end
end

#delete_folder(folder_name) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/Storage/folder.rb', line 173

def delete_folder (folder_name)
  begin
    if folder_name==''
      raise 'Filename cannot be empty'
    end
    str_uri = @str_uri_folder + folder_name
    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.delete(signed_uri, :accept=>'application/json')
    json = JSON.parse(response)
    if json['Code'] ==200
      return true
    else
      return false
    end
  rescue Exception => e
    print e
  end
end

#file_exists(filename, storage_type = 'Aspose', storage_name = '') ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/Storage/folder.rb', line 96

def file_exists(filename,storage_type = 'Aspose' , storage_name = '')
  begin
    if(filename == '')
      raise('Filname cannot be empty')
    end

    str_uri = @str_uri_exist + filename
    if(!storage_name.empty?)
      str_uri += '?storage=' + storage_name
    end
    signed_str_uri = Aspose::Cloud::Common::Utils.sign(str_uri)

    response_stream = RestClient.get(signed_str_uri, {:accept=>'application/json'})

    stream_hash = JSON.parse(response_stream)

    if stream_hash['FileExist']['IsExist'] == true
      return true
    else
      return false
    end        

  rescue Exception=>e
    print e
  end
end

#get_disc_usage(storage_type = 'Aspose', storage_name = '') ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/Storage/folder.rb', line 192

def get_disc_usage (storage_type = 'Aspose',storage_name='')
  begin
    str_uri = @str_uri_disc
    if(!storage_name.empty?)
      str_uri += '?storage=' + storage_name
    end
    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.get(signed_uri, :accept=>'application/json')
    json = JSON.parse(response)
    return json['DiscUsage']
  rescue Exception => e
    print e
  end
end

#get_file(file_name, storage_type = 'Aspose', storage_name = '') ⇒ Object

Get file from Aspose server



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/Storage/folder.rb', line 207

def get_file (file_name,storage_type = 'Aspose',storage_name='')
  begin
    if file_name==''
      raise 'Filename cannot be empty'
    end
    str_uri = @str_uri_file + file_name
    if(!storage_name.empty?)
      str_uri += '?storage=' + storage_name
    end
    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.get(signed_uri, :accept=>'application/json')
    return response
  rescue Exception => e
    print e
  end
end

#get_files(remote_folder_path) ⇒ Object

Retrieves Files and Folder information from a remote folder. The method returns an Array of AppFile objects.

  • :remoteFolderPath represents remote folder relative to the root. Pass empty string for the root folder.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/Storage/folder.rb', line 64

def get_files(remote_folder_path)
  str_url = @str_uri_folder
  if not remote_folder_path.empty?
    str_url+remote_folder_path
  end
  signed_uri = Aspose::Cloud::Common::Utils.sign(str_url)
  response = RestClient.get(signed_uri, :accept=>'application/json')
      
  result = JSON.parse(response)
  return result['Files']
  #      urlFolder = $product_uri + '/storage/folder'
  #      urlFile = ''
  #      urlExist = ''
  #      urlDisc = ''
  #      if not remoteFolderPath.empty?
  #        urlFile = $product_uri + '/storage/folder/' + remoteFolderPath 
  #      end             
  #      signedURL = Aspose::Cloud::Common::Utils.sign(urlFolder)
  #      response = RestClient.get(signedURL, :accept => 'application/json')
  #      result = JSON.parse(response.body)
  #      apps = Array.new(result['Files'].size)
  #
  #      for i in 0..result['Files'].size - 1
  #        apps[i] = AppFile.new
  #        apps[i].Name = result['Files'][i]['Name']
  #        apps[i].IsFolder = result['Files'][i]['IsFolder']
  #        apps[i].Size = result['Files'][i]['Size']
  #        apps[i].ModifiedDate = Aspose::Cloud::Common::Utils.parse_date(result['Files'][i]['ModifiedDate'])
  #      end
  #      return apps	 
end

#upload_file(local_file, remote_folder = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Uploads file from the local path to the remote folder.

  • :localFilePath represents full local file path and name

  • :remoteFolderPath represents remote folder relative to the root. Pass empty string for the root folder.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/Storage/folder.rb', line 18

def upload_file(local_file,remote_folder='',storage_type='Aspose',storage_name='')
      
  begin

    if local_file == ''
      raise('Local file not specified')
    end
        

    if(storage_type == 'Aspose')
  
      filename = File.basename(local_file)
  
      if remote_folder.empty?
        struri = $product_uri + '/storage/file/' + filename
      else
        struri = $product_uri + '/storage/file/' + remote_folder + '/' + filename
      end
  
      signeduri = Aspose::Cloud::Common::Utils.sign(struri)
  
    else
  
      filename = File.basename(local_file)
  
      if remote_folder.empty?
        struri = $product_uri + '/storage/file/' + filename + '?storage=' + storage_name
      else
        struri = $product_uri + '/storage/file/' + remote_folder + '/' + filename + '?storage=' + storage_name
      end
            
      signeduri = Aspose::Cloud::Common::Utils.sign(struri)
  
    end

    Aspose::Cloud::Common::Utils.upload_file_binary(local_file,signeduri)	

  rescue Exception=>e
    print e
  end            
end