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
-
#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
-
.upload!(filepath, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Uploads file to API server.
-
.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.
-
#to_document ⇒ GroupDocs::Document
Converts file to GroupDocs::Document.
Methods included from Api::Helpers::Path
Methods inherited from Api::Entity
#initialize, #inspect, #to_hash
Constructor Details
This class inherits a constructor from GroupDocs::Api::Entity
Instance Attribute Details
#access ⇒ Symbol
Converts access mode to human-readable format.
98 99 100 |
# File 'lib/groupdocs/storage/file.rb', line 98 def access @access end |
#created_on ⇒ Time
Converts timestamp which is return by API server to Time object.
84 85 86 |
# File 'lib/groupdocs/storage/file.rb', line 84 def created_on @created_on end |
#file_type ⇒ Symbol
Returns file type in human-readable format.
96 97 98 |
# File 'lib/groupdocs/storage/file.rb', line 96 def file_type @file_type end |
#guid ⇒ Object
76 77 78 |
# File 'lib/groupdocs/storage/file.rb', line 76 def guid @guid end |
#id ⇒ Object
74 75 76 |
# File 'lib/groupdocs/storage/file.rb', line 74 def id @id end |
#known ⇒ Object
80 81 82 |
# File 'lib/groupdocs/storage/file.rb', line 80 def known @known end |
#modified_on ⇒ Time
Converts timestamp which is return by API server to Time object.
86 87 88 |
# File 'lib/groupdocs/storage/file.rb', line 86 def modified_on @modified_on end |
#name ⇒ Object
90 91 92 |
# File 'lib/groupdocs/storage/file.rb', line 90 def name @name end |
#path ⇒ Object
100 101 102 |
# File 'lib/groupdocs/storage/file.rb', line 100 def path @path end |
#size ⇒ Object
78 79 80 |
# File 'lib/groupdocs/storage/file.rb', line 78 def size @size end |
#thumbnail ⇒ Object
82 83 84 |
# File 'lib/groupdocs/storage/file.rb', line 82 def thumbnail @thumbnail end |
#type ⇒ Symbol
Returns type in human-readable format.
94 95 96 |
# File 'lib/groupdocs/storage/file.rb', line 94 def type @type end |
#url ⇒ Object
88 89 90 |
# File 'lib/groupdocs/storage/file.rb', line 88 def url @url end |
#version ⇒ Object
92 93 94 |
# File 'lib/groupdocs/storage/file.rb', line 92 def version @version end |
Class Method Details
.upload!(filepath, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Uploads file to API server.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/groupdocs/storage/file.rb', line 35 def self.upload!(filepath, = {}, access = {}) [:path] ||= '' [:name] ||= Object::File.basename(filepath) path = prepare_path("#{options[:path]}/#{options[: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_web!(url, access = {}) ⇒ GroupDocs::Storage::File
Uploads web page as file.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/groupdocs/storage/file.rb', line 61 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.
260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/groupdocs/storage/file.rb', line 260 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.
238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/groupdocs/storage/file.rb', line 238 def copy!(path, = {}, access = {}) [:name] ||= name path = prepare_path("#{path}/#{options[: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.
279 280 281 282 283 284 285 |
# File 'lib/groupdocs/storage/file.rb', line 279 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.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/groupdocs/storage/file.rb', line 174 def download!(path, access = {}) response = Api::Request.new do |request| request[:access] = access request[:method] = :DOWNLOAD request[:path] = "/storage/{{client_id}}/files/#{id}" end.execute! filepath = "#{path}/#{name}" Object::File.open(filepath, 'w') do |file| file.write(response) end filepath end |
#move!(path, options = {}, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/groupdocs/storage/file.rb', line 200 def move!(path, = {}, access = {}) [:name] ||= name path = prepare_path("#{path}/#{options[: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.
294 295 296 297 298 299 300 |
# File 'lib/groupdocs/storage/file.rb', line 294 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.
223 224 225 |
# File 'lib/groupdocs/storage/file.rb', line 223 def rename!(name, access = {}) move!(path, { name: name }, access) end |
#to_document ⇒ GroupDocs::Document
Converts file to GroupDocs::Document.
307 308 309 |
# File 'lib/groupdocs/storage/file.rb', line 307 def to_document Document.new(file: self) end |