Class: GroupDocs::Storage::File
- Inherits:
-
Api::Entity
- Object
- Api::Entity
- GroupDocs::Storage::File
- Extended by:
- Extensions::Lookup
- Includes:
- Api::Helpers::AccessMode
- Defined in:
- lib/groupdocs/storage/file.rb
Constant Summary collapse
- DOCUMENT_TYPES =
{ undefined: -1, cells: 0, words: 1, slides: 2, pdf: 3, html: 4, image: 5, }
Constants included from Api::Helpers::AccessMode
Api::Helpers::AccessMode::MODES
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 ⇒ Object
- #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 document type in human-readable format.
- #url ⇒ Object
- #version ⇒ Object
Class Method Summary collapse
-
.all!(path = '/', access = {}) ⇒ Array<GroupDocs::Storage::File>
Returns an array of all files on server starting with given path.
-
.upload!(filepath, upload_path = '/', access = {}) ⇒ GroupDocs::Storage::File
Uploads file to API server.
Instance Method Summary collapse
-
#compress!(access = {}) ⇒ GroupDocs::Storage::File
Compresses file on server to given archive type.
-
#copy!(path, 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, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
-
#rename!(name, access = {}) ⇒ GroupDocs::Storage::File
Renames file to new one.
-
#to_document ⇒ GroupDocs::Document
Converts file to GroupDocs::Document.
Methods included from Extensions::Lookup
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.
96 97 98 |
# File 'lib/groupdocs/storage/file.rb', line 96 def access @access end |
#created_on ⇒ Time
Converts timestamp which is return by API server to Time object.
82 83 84 |
# File 'lib/groupdocs/storage/file.rb', line 82 def created_on @created_on end |
#file_type ⇒ Object
94 95 96 |
# File 'lib/groupdocs/storage/file.rb', line 94 def file_type @file_type end |
#guid ⇒ Object
74 75 76 |
# File 'lib/groupdocs/storage/file.rb', line 74 def guid @guid end |
#id ⇒ Object
72 73 74 |
# File 'lib/groupdocs/storage/file.rb', line 72 def id @id end |
#known ⇒ Object
78 79 80 |
# File 'lib/groupdocs/storage/file.rb', line 78 def known @known end |
#modified_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 modified_on @modified_on end |
#name ⇒ Object
88 89 90 |
# File 'lib/groupdocs/storage/file.rb', line 88 def name @name end |
#path ⇒ Object
98 99 100 |
# File 'lib/groupdocs/storage/file.rb', line 98 def path @path end |
#size ⇒ Object
76 77 78 |
# File 'lib/groupdocs/storage/file.rb', line 76 def size @size end |
#thumbnail ⇒ Object
80 81 82 |
# File 'lib/groupdocs/storage/file.rb', line 80 def thumbnail @thumbnail end |
#type ⇒ Symbol
Returns document type in human-readable format.
92 93 94 |
# File 'lib/groupdocs/storage/file.rb', line 92 def type @type end |
#url ⇒ Object
86 87 88 |
# File 'lib/groupdocs/storage/file.rb', line 86 def url @url end |
#version ⇒ Object
90 91 92 |
# File 'lib/groupdocs/storage/file.rb', line 90 def version @version end |
Class Method Details
.all!(path = '/', access = {}) ⇒ Array<GroupDocs::Storage::File>
Returns an array of all files on server starting with given path.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/groupdocs/storage/file.rb', line 57 def self.all!(path = '/', access = {}) files = Array.new folder = GroupDocs::Storage::Folder.new(path: path) folder.list!({}, access).each do |entity| if entity.is_a?(GroupDocs::Storage::Folder) files += all!("#{path}/#{entity.name}", access) else files << entity end end files end |
.upload!(filepath, upload_path = '/', access = {}) ⇒ GroupDocs::Storage::File
Uploads file to API server.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/groupdocs/storage/file.rb', line 34 def self.upload!(filepath, upload_path = '/', access = {}) Api::Helpers::Path.verify_starts_with_root(upload_path) Api::Helpers::Path.append_file_name(upload_path, filepath) json = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/folders#{upload_path}" request[:request_body] = Object::File.new(filepath, 'rb') end.execute! Storage::File.new(json) end |
Instance Method Details
#compress!(access = {}) ⇒ GroupDocs::Storage::File
Compresses file on server to given archive type.
247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/groupdocs/storage/file.rb', line 247 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! # HACK add filename for further file operations json[:name] = "#{name}.zip" Storage::File.new(json) end |
#copy!(path, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/groupdocs/storage/file.rb', line 225 def copy!(path, access = {}) Api::Helpers::Path.verify_starts_with_root(path) Api::Helpers::Path.append_file_name(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.
266 267 268 269 270 271 272 |
# File 'lib/groupdocs/storage/file.rb', line 266 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.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/groupdocs/storage/file.rb', line 163 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, access = {}) ⇒ GroupDocs::Storage::File
Moves file to given path.
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/groupdocs/storage/file.rb', line 188 def move!(path, access = {}) Api::Helpers::Path.verify_starts_with_root(path) Api::Helpers::Path.append_file_name(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 |
#rename!(name, access = {}) ⇒ GroupDocs::Storage::File
Renames file to new one.
211 212 213 |
# File 'lib/groupdocs/storage/file.rb', line 211 def rename!(name, access = {}) move!("#{path}#{name}", access) end |
#to_document ⇒ GroupDocs::Document
Converts file to GroupDocs::Document.
279 280 281 |
# File 'lib/groupdocs/storage/file.rb', line 279 def to_document Document.new(file: self) end |