Class: GroupDocs::Storage::File
- Inherits:
-
Api::Entity
- Object
- Api::Entity
- GroupDocs::Storage::File
- Includes:
- Api::Helpers::AccessMode, Api::Helpers::Path
- Defined in:
- lib/groupdocs/storage/file.rb
Constant Summary collapse
- DOCUMENT_TYPES =
%w(Undefined Cells Words Slides Pdf Html Image)
Instance Attribute Summary collapse
-
#access ⇒ Symbol
Converts access mode to human-readable format.
-
#created_on ⇒ Time
Converts timestamp which is return by API server to Time object.
-
#file_type ⇒ Symbol
Returns file type in human-readable format.
- #guid ⇒ Object
- #id ⇒ Object
- #known ⇒ Object
- #local_path ⇒ Object
-
#modified_on ⇒ Time
Converts timestamp which is return by API server to Time object.
- #name ⇒ Object
- #path ⇒ Object
- #size ⇒ Object
- #thumbnail ⇒ Object
-
#type ⇒ Symbol
Returns type in human-readable format.
- #url ⇒ Object
- #version ⇒ Object
Class Method Summary collapse
-
.decompress!(filepath, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Uploads and unzip as file.
-
.get_shared_file!(path, name, user_email, file_path) ⇒ Object
Get shared file.
-
.upload!(filepath, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Uploads file to API server.
-
.upload_google!(path, file_id, access = {}) ⇒ GroupDocs::Storage::File
Uploads google page as file.
-
.upload_web!(url, access = {}) ⇒ GroupDocs::Storage::File
Uploads web page as file.
Instance Method Summary collapse
-
#compress!(access = {}) ⇒ GroupDocs::Storage::File
Compresses file on server to given archive type.
-
#copy!(path, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
-
#delete!(access = {}) ⇒ Object
Deletes file from server.
-
#download!(path, access = {}) ⇒ String
Downloads file to given path.
-
#move!(path, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
-
#move_to_trash!(access = {}) ⇒ Object
Moves file to trash on server.
-
#rename!(name, access = {}) ⇒ GroupDocs::Storage::File
Renames file to new one.
-
#restore_to_trash!(path, access = {}) ⇒ Object
Restore file from trash on server.
-
#to_document ⇒ GroupDocs::Document
Converts file to GroupDocs::Document.
-
#upload_cancel!(path, access = {}) ⇒ Object
Added in release 1.5.8.
Methods included from Api::Helpers::Path
Methods inherited from Api::Entity
#initialize, #inspect, #to_hash
Methods included from Api::Helpers::Accessor
Constructor Details
This class inherits a constructor from GroupDocs::Api::Entity
Instance Attribute Details
#access ⇒ Symbol
Converts access mode to human-readable format.
179 180 181 |
# File 'lib/groupdocs/storage/file.rb', line 179 def access @access end |
#created_on ⇒ Time
Converts timestamp which is return by API server to Time object.
165 166 167 |
# File 'lib/groupdocs/storage/file.rb', line 165 def created_on @created_on end |
#file_type ⇒ Symbol
Returns file type in human-readable format.
177 178 179 |
# File 'lib/groupdocs/storage/file.rb', line 177 def file_type @file_type end |
#guid ⇒ Object
157 158 159 |
# File 'lib/groupdocs/storage/file.rb', line 157 def guid @guid end |
#id ⇒ Object
155 156 157 |
# File 'lib/groupdocs/storage/file.rb', line 155 def id @id end |
#known ⇒ Object
161 162 163 |
# File 'lib/groupdocs/storage/file.rb', line 161 def known @known end |
#local_path ⇒ Object
183 184 185 |
# File 'lib/groupdocs/storage/file.rb', line 183 def local_path @local_path end |
#modified_on ⇒ Time
Converts timestamp which is return by API server to Time object.
167 168 169 |
# File 'lib/groupdocs/storage/file.rb', line 167 def modified_on @modified_on end |
#name ⇒ Object
171 172 173 |
# File 'lib/groupdocs/storage/file.rb', line 171 def name @name end |
#path ⇒ Object
181 182 183 |
# File 'lib/groupdocs/storage/file.rb', line 181 def path @path end |
#size ⇒ Object
159 160 161 |
# File 'lib/groupdocs/storage/file.rb', line 159 def size @size end |
#thumbnail ⇒ Object
163 164 165 |
# File 'lib/groupdocs/storage/file.rb', line 163 def thumbnail @thumbnail end |
#type ⇒ Symbol
Returns type in human-readable format.
175 176 177 |
# File 'lib/groupdocs/storage/file.rb', line 175 def type @type end |
#url ⇒ Object
169 170 171 |
# File 'lib/groupdocs/storage/file.rb', line 169 def url @url end |
#version ⇒ Object
173 174 175 |
# File 'lib/groupdocs/storage/file.rb', line 173 def version @version end |
Class Method Details
.decompress!(filepath, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Uploads and unzip as file.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/groupdocs/storage/file.rb', line 135 def self.decompress!(filepath, = {}, access = {}) [:path] ||= '' [:name] ||= Object::File.basename(filepath) path = prepare_path("#{[:path]}/#{[:name]}") api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/decompress/#{path}/" request[:request_body] = Object::File.new(filepath, 'rb') end api.add_params(:archiveType => [:archiveType]) if [:archiveType] json = api.execute! json[:files].map do |file| File.new(file) end end |
.get_shared_file!(path, name, user_email, file_path) ⇒ Object
Get shared file.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/groupdocs/storage/file.rb', line 65 def self.get_shared_file!(path, name, user_email, file_path) response = Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/storage/shared/#{user_email}/#{file_path}" end.execute! filepath = "#{path}/#{name}" Object::File.open(filepath, 'wb') do |file| file.write(response) end filepath end |
.upload!(filepath, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Uploads file to API server.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/groupdocs/storage/file.rb', line 40 def self.upload!(filepath, = {}, access = {}) [:path] ||= '' [:name] ||= Object::File.basename(filepath) path = prepare_path("#{[:path]}/#{[:name]}") api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/folders/#{path}" request[:request_body] = Object::File.new(filepath, 'rb') end api.add_params(:description => [:description]) if [:description] json = api.execute! Storage::File.new(json) end |
.upload_google!(path, file_id, access = {}) ⇒ GroupDocs::Storage::File
Uploads google page as file.
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/groupdocs/storage/file.rb', line 110 def self.upload_google!(path, file_id, access = {}) api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/google/files/#{path}" end api.add_params(:file_id => file_id) json = api.execute! Storage::File.new(json) end |
.upload_web!(url, access = {}) ⇒ GroupDocs::Storage::File
Uploads web page as file.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/groupdocs/storage/file.rb', line 89 def self.upload_web!(url, access = {}) api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = '/storage/{{client_id}}/urls' end api.add_params(:url => url) json = api.execute! Storage::File.new(json) end |
Instance Method Details
#compress!(access = {}) ⇒ GroupDocs::Storage::File
Compresses file on server to given archive type.
343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/groupdocs/storage/file.rb', line 343 def compress!(access = {}) json = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/files/#{id}/archive/zip" end.execute! # add filename for further file operations json[:name] = "#{name}.zip" Storage::File.new(json) end |
#copy!(path, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/groupdocs/storage/file.rb', line 321 def copy!(path, = {}, access = {}) [:name] ||= name path = prepare_path("#{path}/#{[:name]}") json = Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:headers] = { :'Groupdocs-Copy' => id } request[:path] = "/storage/{{client_id}}/files/#{path}" end.execute! Storage::File.new(json[:dst_file]) end |
#delete!(access = {}) ⇒ Object
Deletes file from server.
362 363 364 365 366 367 368 |
# File 'lib/groupdocs/storage/file.rb', line 362 def delete!(access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :DELETE request[:path] = "/storage/{{client_id}}/files/#{guid}" end.execute! end |
#download!(path, access = {}) ⇒ String
Downloads file to given path.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/groupdocs/storage/file.rb', line 257 def download!(path, access = {}) response = Api::Request.new do |request| request[:access] = access request[:method] = :DOWNLOAD request[:path] = "/storage/{{client_id}}/files/#{guid}" end.execute! filepath = "#{path}/#{name}" Object::File.open(filepath, 'wb') do |file| file.write(response) end filepath end |
#move!(path, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/groupdocs/storage/file.rb', line 283 def move!(path, = {}, access = {}) [:name] ||= name path = prepare_path("#{path}/#{[:name]}") json = Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:headers] = { :'Groupdocs-Move' => id } request[:path] = "/storage/{{client_id}}/files/#{path}" end.execute! Storage::File.new(json[:dst_file]) end |
#move_to_trash!(access = {}) ⇒ Object
Moves file to trash on server.
377 378 379 380 381 382 383 |
# File 'lib/groupdocs/storage/file.rb', line 377 def move_to_trash!(access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/storage/{{client_id}}/trash/#{path}/#{name}" end.execute! end |
#rename!(name, access = {}) ⇒ GroupDocs::Storage::File
Renames file to new one.
306 307 308 |
# File 'lib/groupdocs/storage/file.rb', line 306 def rename!(name, access = {}) move!(path, { :name => name }, access) end |
#restore_to_trash!(path, access = {}) ⇒ Object
Restore file from trash on server.
392 393 394 395 396 397 398 |
# File 'lib/groupdocs/storage/file.rb', line 392 def restore_to_trash!(path, access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :DELETE request[:path] = "/storage/{{client_id}}/trash/#{path}" end.execute! end |
#to_document ⇒ GroupDocs::Document
Converts file to GroupDocs::Document.
405 406 407 |
# File 'lib/groupdocs/storage/file.rb', line 405 def to_document Document.new(:file => self) end |
#upload_cancel!(path, access = {}) ⇒ Object
Added in release 1.5.8
Cancel file upload
419 420 421 422 423 424 425 |
# File 'lib/groupdocs/storage/file.rb', line 419 def upload_cancel!(path, access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/storage/{{client_id}}/cancelUpload/#{id}/#{path}" end.execute! end |