Class: Files::File
- Inherits:
-
Object
- Object
- Files::File
- Defined in:
- lib/files.com/models/file.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
- #lineno(*_args) ⇒ Object
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #pos ⇒ Object
- #sync ⇒ Object
Class Method Summary collapse
-
.begin_upload(path, params = {}, options = {}) ⇒ Object
Begin File Upload.
- .binread(name, *args) ⇒ Object
- .binwrite(name, *args) ⇒ Object
- .chmod(*_args) ⇒ Object
- .chown(*_args) ⇒ Object
- .client(options = {}) ⇒ Object
-
.copy(path, params = {}, options = {}) ⇒ Object
Copy File/Folder.
- .copy_stream(*_args) ⇒ Object
- .copy_to_child_site(path, site_id, destination, params = {}, options = {}) ⇒ Object
- .copy_to_remote_server(path, remote_server_id, destination, params = {}, options = {}) ⇒ Object
- .copy_to_snapshot(path, snapshot_id, destination, params = {}, options = {}) ⇒ Object
-
.create(path, params = {}, options = {}) ⇒ Object
Parameters: path (required) - string - Path to operate on.
-
.delete(path, params = {}, options = {}) ⇒ Object
Parameters: recursive - boolean - If true, will recursively delete folders.
- .destroy(path, params = {}, options = {}) ⇒ Object
- .directory?(path, options = {}) ⇒ Boolean
-
.download(path, params = {}, options = {}) ⇒ Object
Download File.
- .download_file(path, local_path = nil) ⇒ Object
- .exist?(path, options = {}) ⇒ Boolean
- .exists?(path, options = {}) ⇒ Boolean
-
.find(path, params = {}, options = {}) ⇒ Object
Parameters: path (required) - string - Path to operate on.
- .for_fd(*_args) ⇒ Object
- .foreach(name, *args, &block) ⇒ Object
- .from_path(path, options = {}) ⇒ Object
- .get(path, params = {}, options = {}) ⇒ Object
-
.gpg_decrypt(path, params = {}, options = {}) ⇒ Object
Decrypt a GPG-encrypted file and save it to a destination path.
-
.gpg_encrypt(path, params = {}, options = {}) ⇒ Object
Encrypt a file with GPG and save it to a destination path.
- .identical?(path1, path2) ⇒ Boolean
- .lstat(path) ⇒ Object
-
.move(path, params = {}, options = {}) ⇒ Object
Move File/Folder.
- .move_to_child_site(path, site_id, destination, params = {}, options = {}) ⇒ Object
- .move_to_remote_server(path, remote_server_id, destination, params = {}, options = {}) ⇒ Object
- .move_to_snapshot(path, snapshot_id, destination, params = {}, options = {}) ⇒ Object
- .mtime(path) ⇒ Object
- .open(path, mode = "r", options = {}, &block) ⇒ Object
- .owned?(_path) ⇒ Boolean
- .pipe(*_args) ⇒ Object
- .popen(*_args) ⇒ Object
- .read(name, *args) ⇒ Object
- .readable?(path) ⇒ Boolean
- .readlines(name, *args) ⇒ Object
- .rename(old_path, new_path) ⇒ Object
- .select(*_args) ⇒ Object
- .stat(path) ⇒ Object
- .sysopen(*_args) ⇒ Object
-
.transform(path, params = {}, options = {}) ⇒ Object
Transform a file and save the output to a destination path.
- .try_convert(*_args) ⇒ Object
- .unlink(*paths) ⇒ Object
-
.unzip(path, params = {}, options = {}) ⇒ Object
Extract a ZIP file to a destination folder.
-
.update(path, params = {}, options = {}) ⇒ Object
Parameters: custom_metadata - object - Custom metadata map of keys and values.
- .upload_chunks(io, path, options, upload = nil, etags = [], params: {}) ⇒ Object
- .upload_file(path, destination = nil, options = {}, params: {}) ⇒ Object
- .upload_to_child_site(path, site_id, destination = nil, options = {}, params: {}) ⇒ Object
- .upload_to_remote_server(path, remote_server_id, destination = nil, options = {}, params: {}) ⇒ Object
- .upload_to_snapshot(path, snapshot_id, destination = nil, options = {}, params: {}) ⇒ Object
- .write(*_args) ⇒ Object
- .zero?(path) ⇒ Boolean
-
.zip(params = {}, options = {}) ⇒ Object
Parameters: paths (required) - array(string) - Paths to include in the ZIP.
-
.zip_list_contents(path, params = {}, options = {}) ⇒ Object
List the contents of a ZIP file.
Instance Method Summary collapse
-
#action ⇒ Object
string - The action to perform.
- #action=(value) ⇒ Object
- #advise(*_args) ⇒ Object
- #atime ⇒ Object
- #autoclose=(*_args) ⇒ Object
- #autoclose?(*_args) ⇒ Boolean
-
#begin_upload(params = {}) ⇒ Object
Begin File Upload.
- #binmode ⇒ Object
- #binmode? ⇒ Boolean
- #birthtime ⇒ Object
-
#buffered_upload ⇒ Object
boolean - If true, and the path refers to a destination not stored on Files.com (such as a remote server mount), the upload will be uploaded first to Files.com before being sent to the remote server mount.
- #buffered_upload=(value) ⇒ Object
- #bytes ⇒ Object
- #chars ⇒ Object
- #chmod(*_args) ⇒ Object
- #chown(*_args) ⇒ Object
- #client ⇒ Object
- #close(**kwargs) ⇒ Object
- #close_on_exec=(*args) ⇒ Object
- #close_on_exec?(*args) ⇒ Boolean
- #close_read(*args) ⇒ Object
- #close_write(*args) ⇒ Object
- #closed?(*args) ⇒ Boolean
- #codepoints(*args, &block) ⇒ Object
-
#copy(params = {}) ⇒ Object
Copy File/Folder.
-
#copy_behaviors ⇒ Object
boolean - If copying a folder, also copy supported behaviors to the destination folder tree?.
- #copy_behaviors=(value) ⇒ Object
- #copy_to_child_site(site_id, destination, params = {}) ⇒ Object
- #copy_to_remote_server(remote_server_id, destination, params = {}) ⇒ Object
- #copy_to_snapshot(snapshot_id, destination, params = {}) ⇒ Object
-
#crc32 ⇒ Object
string - File CRC32 checksum.
- #crc32=(value) ⇒ Object
-
#created_at ⇒ Object
date-time - File created date/time.
-
#created_by_api_key_id ⇒ Object
int64 - ID of the API key that created the file/folder.
- #created_by_api_key_id=(value) ⇒ Object
-
#created_by_as2_incoming_message_id ⇒ Object
int64 - ID of the AS2 Incoming Message that created the file/folder.
- #created_by_as2_incoming_message_id=(value) ⇒ Object
-
#created_by_automation_id ⇒ Object
int64 - ID of the Automation that created the file/folder.
- #created_by_automation_id=(value) ⇒ Object
-
#created_by_bundle_registration_id ⇒ Object
int64 - ID of the Bundle Registration that created the file/folder.
- #created_by_bundle_registration_id=(value) ⇒ Object
-
#created_by_id ⇒ Object
int64 - User ID of the User who created the file/folder.
- #created_by_id=(value) ⇒ Object
-
#created_by_inbox_id ⇒ Object
int64 - ID of the Inbox that created the file/folder.
- #created_by_inbox_id=(value) ⇒ Object
-
#created_by_remote_server_id ⇒ Object
int64 - ID of the Remote Server that created the file/folder.
- #created_by_remote_server_id=(value) ⇒ Object
-
#created_by_sync_id ⇒ Object
int64 - ID of the Sync that created the file/folder.
- #created_by_sync_id=(value) ⇒ Object
- #ctime(*_args) ⇒ Object
-
#custom_metadata ⇒ Object
object - Custom metadata map of keys and values.
- #custom_metadata=(value) ⇒ Object
-
#delete(params = {}) ⇒ Object
Parameters: recursive - boolean - If true, will recursively delete folders.
- #destroy(params = {}) ⇒ Object
-
#display_name ⇒ Object
string - File/Folder display name.
- #display_name=(value) ⇒ Object
-
#download(params = {}) ⇒ Object
Download File.
- #download_content(io, range: []) ⇒ Object
- #download_file(output_file) ⇒ Object
-
#download_uri ⇒ Object
string - Link to download file.
- #download_uri=(value) ⇒ Object
- #download_uri_with_load ⇒ Object
- #each(*args, &block) ⇒ Object
- #each_byte(*args, &block) ⇒ Object
- #each_char(*args, &block) ⇒ Object
- #each_codepoint(*args, &block) ⇒ Object
- #each_line(*args, &block) ⇒ Object
- #empty? ⇒ Boolean
- #eof ⇒ Object
- #eof? ⇒ Boolean
- #external_encoding(*args) ⇒ Object
- #fcntl(*_args) ⇒ Object
- #fdatasync(*_args) ⇒ Object
- #fileno(*_args) ⇒ Object
- #flock(*_args) ⇒ Object
- #flush(*_args) ⇒ Object
- #fsync(*args) ⇒ Object
- #getbyte(*args) ⇒ Object
- #getc(*args) ⇒ Object
- #gets(*args) ⇒ Object
-
#gpg_decrypt(params = {}) ⇒ Object
Decrypt a GPG-encrypted file and save it to a destination path.
-
#gpg_encrypt(params = {}) ⇒ Object
Encrypt a file with GPG and save it to a destination path.
-
#initialize(*args) ⇒ File
constructor
A new instance of File.
- #internal_encoding(*_args) ⇒ Object
- #ioctl(*_args) ⇒ Object
-
#is_locked ⇒ Object
boolean - Is this folder locked and unable to be modified?.
- #is_locked=(value) ⇒ Object
- #isatty(*_args) ⇒ Object
-
#last_modified_by_api_key_id ⇒ Object
int64 - ID of the API key that last modified the file/folder.
- #last_modified_by_api_key_id=(value) ⇒ Object
-
#last_modified_by_automation_id ⇒ Object
int64 - ID of the Automation that last modified the file/folder.
- #last_modified_by_automation_id=(value) ⇒ Object
-
#last_modified_by_bundle_registration_id ⇒ Object
int64 - ID of the Bundle Registration that last modified the file/folder.
- #last_modified_by_bundle_registration_id=(value) ⇒ Object
-
#last_modified_by_id ⇒ Object
int64 - User ID of the User who last modified the file/folder.
- #last_modified_by_id=(value) ⇒ Object
-
#last_modified_by_remote_server_id ⇒ Object
int64 - ID of the Remote Server that last modified the file/folder.
- #last_modified_by_remote_server_id=(value) ⇒ Object
-
#last_modified_by_sync_id ⇒ Object
int64 - ID of the Sync that last modified the file/folder.
- #last_modified_by_sync_id=(value) ⇒ Object
-
#length ⇒ Object
int64 - Length of file.
- #length=(value) ⇒ Object
- #lines(*args, &block) ⇒ Object
- #lstat(*_args) ⇒ Object
-
#md5 ⇒ Object
string - File MD5 checksum.
- #md5=(value) ⇒ Object
-
#mime_type ⇒ Object
string - MIME Type.
- #mime_type=(value) ⇒ Object
-
#mkdir_parents ⇒ Object
boolean - Create parent directories if they do not exist?.
- #mkdir_parents=(value) ⇒ Object
-
#move(params = {}) ⇒ Object
Move File/Folder.
- #move_to_child_site(site_id, destination, params = {}) ⇒ Object
- #move_to_remote_server(remote_server_id, destination, params = {}) ⇒ Object
- #move_to_snapshot(snapshot_id, destination, params = {}) ⇒ Object
-
#mtime ⇒ Object
date-time - File last modified date/time, according to the server.
- #mtime=(value) ⇒ Object
- #mv(destination) ⇒ Object
-
#part ⇒ Object
int64 - Part if uploading a part.
- #part=(value) ⇒ Object
-
#parts ⇒ Object
int64 - How many parts to fetch?.
- #parts=(value) ⇒ Object
-
#path ⇒ Object
string - File/Folder path.
- #path=(value) ⇒ Object
-
#permissions ⇒ Object
string - A short string representing the current user's permissions.
- #permissions=(value) ⇒ Object
- #pid(*_args) ⇒ Object
- #pread(*args) ⇒ Object
-
#preview ⇒ Object
Preview - File preview.
- #preview=(value) ⇒ Object
-
#preview_id ⇒ Object
int64 - File preview ID.
- #preview_id=(value) ⇒ Object
- #print(*args) ⇒ Object
- #printf(*args) ⇒ Object
-
#priority_color ⇒ Object
string - Bookmark/priority color of file/folder.
- #priority_color=(value) ⇒ Object
-
#provided_mtime ⇒ Object
date-time - File last modified date/time, according to the client who set it.
- #provided_mtime=(value) ⇒ Object
- #putc(*args) ⇒ Object
- #puts(*args) ⇒ Object
- #pwrite(*args) ⇒ Object
- #read(*args) ⇒ Object
- #read_io(**options) ⇒ Object
- #read_nonblock(*args) ⇒ Object
- #readbyte(*args) ⇒ Object
- #readchar(*args) ⇒ Object
- #readline(*args) ⇒ Object
- #readlines(*args) ⇒ Object
- #readpartial(*args) ⇒ Object
-
#ref ⇒ Object
string -.
- #ref=(value) ⇒ Object
-
#region ⇒ Object
string - Region location.
- #region=(value) ⇒ Object
- #rename(destination) ⇒ Object
- #reopen(*_args) ⇒ Object
-
#restart ⇒ Object
int64 - File byte offset to restart from.
- #restart=(value) ⇒ Object
- #rewind ⇒ Object
- #save ⇒ Object
- #seek(pos) ⇒ Object
- #set_encoding(*_args) ⇒ Object
-
#sha1 ⇒ Object
string - File SHA1 checksum.
- #sha1=(value) ⇒ Object
-
#sha256 ⇒ Object
string - File SHA256 checksum.
- #sha256=(value) ⇒ Object
-
#size ⇒ Object
int64 - File/Folder size.
- #size=(value) ⇒ Object
- #stat(*_args) ⇒ Object
-
#structure ⇒ Object
string - If copying folder, copy just the structure?.
- #structure=(value) ⇒ Object
- #subfolders_locked=(value) ⇒ Object
-
#subfolders_locked? ⇒ Boolean
boolean - Are subfolders locked and unable to be modified?.
- #sysread(*args) ⇒ Object
- #sysseek(*args) ⇒ Object
- #syswrite(*_args) ⇒ Object
- #tell ⇒ Object
- #to_i(*_args) ⇒ Object
- #to_io(*_args) ⇒ Object
- #to_path(*_args) ⇒ Object
-
#transform(params = {}) ⇒ Object
Transform a file and save the output to a destination path.
- #truncate(*_args) ⇒ Object
- #tty?(*_args) ⇒ Boolean
-
#type ⇒ Object
string - Type:
directoryorfile. - #type=(value) ⇒ Object
- #ungetbyte(*_args) ⇒ Object
- #ungetc(*_args) ⇒ Object
-
#unzip(params = {}) ⇒ Object
Extract a ZIP file to a destination folder.
-
#update(params = {}) ⇒ Object
Parameters: custom_metadata - object - Custom metadata map of keys and values.
- #upload_file(local_file) ⇒ Object
-
#with_rename ⇒ Object
boolean - Allow file rename instead of overwrite?.
- #with_rename=(value) ⇒ Object
- #write(*args) ⇒ Object
- #write_nonblock(*args) ⇒ Object
-
#zip_list_contents(params = {}) ⇒ Object
List the contents of a ZIP file.
Constructor Details
#initialize(*args) ⇒ File
Returns a new instance of File.
223 224 225 226 227 228 229 230 231 |
# File 'lib/files.com/models/file.rb', line 223 def initialize(*args) @attributes = (args[0].is_a?(Hash) && args[0]) || {} @options = args[1].is_a?(Hash) && args[1] @options ||= (args[2].is_a?(Hash) && args[2]) || {} @attributes[:path] = args[0] if args[0].is_a?(String) @mode = args[1] || 'r' if args[1].is_a?(String) @write_io = StringIO.new @bytes_written = 0 end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/files.com/models/file.rb', line 5 def attributes @attributes end |
#lineno(*_args) ⇒ Object
468 469 470 |
# File 'lib/files.com/models/file.rb', line 468 def lineno(*_args) @lineno ||= 0 end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/files.com/models/file.rb', line 6 def mode @mode end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/files.com/models/file.rb', line 5 def @options end |
#pos ⇒ Object
490 491 492 |
# File 'lib/files.com/models/file.rb', line 490 def pos @pos ||= 0 end |
#sync ⇒ Object
570 571 572 |
# File 'lib/files.com/models/file.rb', line 570 def sync @sync ||= false end |
Class Method Details
.begin_upload(path, params = {}, options = {}) ⇒ Object
Begin File Upload
Parameters:
mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
with_rename - boolean - Allow file rename instead of overwrite?
buffered_upload - boolean - If true, and the path refers to a destination not stored on Files.com (such as a remote server mount), the upload will be uploaded first to Files.com before being sent to the remote server mount. This can allow clients to upload using parallel parts to a remote server destination that does not offer parallel parts support natively.
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 |
# File 'lib/files.com/models/file.rb', line 1550 def self.begin_upload(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String) raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/file_actions/begin_upload/#{params[:path]}", :post, params, ) response.data.map do |entity_data| FileUploadPart.new(entity_data, ) end end |
.binread(name, *args) ⇒ Object
8 9 10 |
# File 'lib/files.com/models/file.rb', line 8 def self.binread(name, *args) new(name).read(*args) end |
.binwrite(name, *args) ⇒ Object
12 13 14 |
# File 'lib/files.com/models/file.rb', line 12 def self.binwrite(name, *args) new(name).write(*args) end |
.chmod(*_args) ⇒ Object
16 17 18 |
# File 'lib/files.com/models/file.rb', line 16 def self.chmod(*_args) raise NotImplementedError end |
.chown(*_args) ⇒ Object
20 21 22 |
# File 'lib/files.com/models/file.rb', line 20 def self.chown(*_args) raise NotImplementedError end |
.client(options = {}) ⇒ Object
24 25 26 |
# File 'lib/files.com/models/file.rb', line 24 def self.client( = {}) [:client] || ApiClient.active_client end |
.copy(path, params = {}, options = {}) ⇒ Object
Copy File/Folder
Parameters:
destination (required) - string - Copy destination path.
copy_behaviors - boolean - If copying a folder, also copy supported behaviors to the destination folder tree?
structure - boolean - Copy structure only?
overwrite - boolean - Overwrite existing file(s) in the destination?
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 |
# File 'lib/files.com/models/file.rb', line 1401 def self.copy(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/copy/#{params[:path]}", :post, params, ) FileAction.new(response.data, ) end |
.copy_stream(*_args) ⇒ Object
28 29 30 |
# File 'lib/files.com/models/file.rb', line 28 def self.copy_stream(*_args) raise NotImplementedError end |
.copy_to_child_site(path, site_id, destination, params = {}, options = {}) ⇒ Object
76 77 78 |
# File 'lib/files.com/models/file.rb', line 76 def self.copy_to_child_site(path, site_id, destination, params = {}, = {}) copy(path, params.merge(destination: underscore_destination_path("Sites", site_id, destination)), ) end |
.copy_to_remote_server(path, remote_server_id, destination, params = {}, options = {}) ⇒ Object
50 51 52 |
# File 'lib/files.com/models/file.rb', line 50 def self.copy_to_remote_server(path, remote_server_id, destination, params = {}, = {}) copy(path, params.merge(destination: underscore_destination_path("RemoteServers", remote_server_id, destination)), ) end |
.copy_to_snapshot(path, snapshot_id, destination, params = {}, options = {}) ⇒ Object
63 64 65 |
# File 'lib/files.com/models/file.rb', line 63 def self.copy_to_snapshot(path, snapshot_id, destination, params = {}, = {}) copy(path, params.merge(destination: underscore_destination_path("Snapshots", snapshot_id, destination)), ) end |
.create(path, params = {}, options = {}) ⇒ Object
Parameters:
path (required) - string - Path to operate on.
action - string - The action to perform. Can be `append`, `attachment`, `end`, `upload`, `put`, or may not exist
etags[etag] (required) - array(string) - etag identifier.
etags[part] (required) - array(int64) - Part number.
length - int64 - Length of file.
mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
provided_mtime - string - User provided modification time.
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Size of file.
copy_behaviors - boolean - If copying a folder, also copy supported behaviors to the destination folder tree?
structure - string - If copying folder, copy just the structure?
with_rename - boolean - Allow file rename instead of overwrite?
buffered_upload - boolean - If true, and the path refers to a destination not stored on Files.com (such as a remote server mount), the upload will be uploaded first to Files.com before being sent to the remote server mount. This can allow clients to upload using parallel parts to a remote server destination that does not offer parallel parts support natively.
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 |
# File 'lib/files.com/models/file.rb', line 1308 def self.create(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].is_a?(String) raise InvalidParameterError.new("Bad parameter: length must be an Integer") if params[:length] and !params[:length].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String) raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String) raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: structure must be an String") if params[:structure] and !params[:structure].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/files/#{params[:path]}", :post, params, ) File.new(response.data, ) end |
.delete(path, params = {}, options = {}) ⇒ Object
Parameters:
recursive - boolean - If true, will recursively delete folders. Otherwise, will error on non-empty folders.
1346 1347 1348 1349 1350 1351 1352 1353 1354 |
# File 'lib/files.com/models/file.rb', line 1346 def self.delete(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{params[:path]}", :delete, params, ) nil end |
.destroy(path, params = {}, options = {}) ⇒ Object
1356 1357 1358 1359 |
# File 'lib/files.com/models/file.rb', line 1356 def self.destroy(path, params = {}, = {}) delete(path, params, ) nil end |
.directory?(path, options = {}) ⇒ Boolean
32 33 34 |
# File 'lib/files.com/models/file.rb', line 32 def self.directory?(path, = {}) find(path, {}, ).type == "directory" end |
.download(path, params = {}, options = {}) ⇒ Object
Download File
Parameters:
action - string - Can be blank, `redirect` or `stat`. If set to `stat`, we will return file information but without a download URL, and without logging a download. If set to `redirect` we will serve a 302 redirect directly to the file. This is used for integrations with Zapier, and is not recommended for most integrations.
preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'lib/files.com/models/file.rb', line 1279 def self.download(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].is_a?(String) raise InvalidParameterError.new("Bad parameter: preview_size must be an String") if params[:preview_size] and !params[:preview_size].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/files/#{params[:path]}", :get, params, ) File.new(response.data, ) end |
.download_file(path, local_path = nil) ⇒ Object
36 37 38 39 |
# File 'lib/files.com/models/file.rb', line 36 def self.download_file(path, local_path = nil) local_path ||= File.basename(path) new(path).download_file(local_path) end |
.exist?(path, options = {}) ⇒ Boolean
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/files.com/models/file.rb', line 84 def self.exist?(path, = {}) find(path, {}, ) true rescue Error => e if e.code == 404 false else raise e end end |
.exists?(path, options = {}) ⇒ Boolean
95 96 97 |
# File 'lib/files.com/models/file.rb', line 95 def self.exists?(path, = {}) exist?(path, ) end |
.find(path, params = {}, options = {}) ⇒ Object
Parameters:
path (required) - string - Path to operate on.
preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 |
# File 'lib/files.com/models/file.rb', line 1366 def self.find(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: preview_size must be an String") if params[:preview_size] and !params[:preview_size].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/file_actions/metadata/#{params[:path]}", :get, params, ) File.new(response.data, ) end |
.for_fd(*_args) ⇒ Object
99 100 101 |
# File 'lib/files.com/models/file.rb', line 99 def self.for_fd(*_args) raise NotImplementedError end |
.foreach(name, *args, &block) ⇒ Object
103 104 105 |
# File 'lib/files.com/models/file.rb', line 103 def self.foreach(name, *args, &block) new(name).each(*args, &block) end |
.from_path(path, options = {}) ⇒ Object
107 108 109 |
# File 'lib/files.com/models/file.rb', line 107 def self.from_path(path, = {}) find(path, {}, ) end |
.get(path, params = {}, options = {}) ⇒ Object
1377 1378 1379 |
# File 'lib/files.com/models/file.rb', line 1377 def self.get(path, params = {}, = {}) find(path, params, ) end |
.gpg_decrypt(path, params = {}, options = {}) ⇒ Object
Decrypt a GPG-encrypted file and save it to a destination path
Parameters:
destination (required) - string - Destination file path for the decrypted file.
gpg_key_ids - array(int64) - GPG Key IDs to decrypt with. If omitted, every accessible private GPG key in the source workspace is used.
gpg_key_partner_id - int64 - Partner ID whose GPG keys should be used for decryption.
use_all_private_keys - boolean - Use every accessible private GPG key in the source workspace for decryption.
ignore_mdc_error - boolean - Ignore errors from the MDC (modification detection code) check.
overwrite - boolean - Overwrite existing file in the destination?
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 |
# File 'lib/files.com/models/file.rb', line 1468 def self.gpg_decrypt(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: gpg_key_ids must be an Array") if params[:gpg_key_ids] and !params[:gpg_key_ids].is_a?(Array) raise InvalidParameterError.new("Bad parameter: gpg_key_partner_id must be an Integer") if params[:gpg_key_partner_id] and !params[:gpg_key_partner_id].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/gpg_decrypt/#{params[:path]}", :post, params, ) FileAction.new(response.data, ) end |
.gpg_encrypt(path, params = {}, options = {}) ⇒ Object
Encrypt a file with GPG and save it to a destination path
Parameters:
destination (required) - string - Destination file path for the encrypted file.
gpg_key_ids - array(int64) - GPG Key IDs to encrypt with.
gpg_key_partner_id - int64 - Partner ID whose GPG keys should be used for encryption.
signing_key_id - int64 - Optional GPG Key ID to sign with.
armor - boolean - Output ASCII-armored encrypted data.
overwrite - boolean - Overwrite existing file in the destination?
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 |
# File 'lib/files.com/models/file.rb', line 1491 def self.gpg_encrypt(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: gpg_key_ids must be an Array") if params[:gpg_key_ids] and !params[:gpg_key_ids].is_a?(Array) raise InvalidParameterError.new("Bad parameter: gpg_key_partner_id must be an Integer") if params[:gpg_key_partner_id] and !params[:gpg_key_partner_id].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: signing_key_id must be an Integer") if params[:signing_key_id] and !params[:signing_key_id].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/gpg_encrypt/#{params[:path]}", :post, params, ) FileAction.new(response.data, ) end |
.identical?(path1, path2) ⇒ Boolean
111 112 113 |
# File 'lib/files.com/models/file.rb', line 111 def self.identical?(path1, path2) new(path1).crc32 == new(path2).crc32 end |
.lstat(path) ⇒ Object
115 116 117 |
# File 'lib/files.com/models/file.rb', line 115 def self.lstat(path) new(path).stat end |
.move(path, params = {}, options = {}) ⇒ Object
Move File/Folder
Parameters:
destination (required) - string - Move destination path.
overwrite - boolean - Overwrite existing file(s) in the destination?
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
# File 'lib/files.com/models/file.rb', line 1418 def self.move(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/move/#{params[:path]}", :post, params, ) FileAction.new(response.data, ) end |
.move_to_child_site(path, site_id, destination, params = {}, options = {}) ⇒ Object
80 81 82 |
# File 'lib/files.com/models/file.rb', line 80 def self.move_to_child_site(path, site_id, destination, params = {}, = {}) move(path, params.merge(destination: underscore_destination_path("Sites", site_id, destination)), ) end |
.move_to_remote_server(path, remote_server_id, destination, params = {}, options = {}) ⇒ Object
54 55 56 |
# File 'lib/files.com/models/file.rb', line 54 def self.move_to_remote_server(path, remote_server_id, destination, params = {}, = {}) move(path, params.merge(destination: underscore_destination_path("RemoteServers", remote_server_id, destination)), ) end |
.move_to_snapshot(path, snapshot_id, destination, params = {}, options = {}) ⇒ Object
67 68 69 |
# File 'lib/files.com/models/file.rb', line 67 def self.move_to_snapshot(path, snapshot_id, destination, params = {}, = {}) move(path, params.merge(destination: underscore_destination_path("Snapshots", snapshot_id, destination)), ) end |
.mtime(path) ⇒ Object
119 120 121 |
# File 'lib/files.com/models/file.rb', line 119 def self.mtime(path) new(path).mtime end |
.open(path, mode = "r", options = {}, &block) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/files.com/models/file.rb', line 123 def self.open(path, mode = "r", = {}, &block) file = new(path, mode, ) if block yield file file.close end file end |
.owned?(_path) ⇒ Boolean
132 133 134 |
# File 'lib/files.com/models/file.rb', line 132 def self.owned?(_path) raise NotImplementedError end |
.pipe(*_args) ⇒ Object
136 137 138 |
# File 'lib/files.com/models/file.rb', line 136 def self.pipe(*_args) raise NotImplementedError end |
.popen(*_args) ⇒ Object
140 141 142 |
# File 'lib/files.com/models/file.rb', line 140 def self.popen(*_args) raise NotImplementedError end |
.read(name, *args) ⇒ Object
144 145 146 |
# File 'lib/files.com/models/file.rb', line 144 def self.read(name, *args) new(name).read(*args) end |
.readable?(path) ⇒ Boolean
148 149 150 |
# File 'lib/files.com/models/file.rb', line 148 def self.readable?(path) new(path).stat..include?("read") end |
.readlines(name, *args) ⇒ Object
152 153 154 |
# File 'lib/files.com/models/file.rb', line 152 def self.readlines(name, *args) new(name).readlines(*args) end |
.rename(old_path, new_path) ⇒ Object
156 157 158 |
# File 'lib/files.com/models/file.rb', line 156 def self.rename(old_path, new_path) FileAction.move(old_path, destination: new_path) end |
.select(*_args) ⇒ Object
160 161 162 |
# File 'lib/files.com/models/file.rb', line 160 def self.select(*_args) raise NotImplementedError end |
.stat(path) ⇒ Object
164 165 166 |
# File 'lib/files.com/models/file.rb', line 164 def self.stat(path) new(path).stat end |
.sysopen(*_args) ⇒ Object
168 169 170 |
# File 'lib/files.com/models/file.rb', line 168 def self.sysopen(*_args) raise NotImplementedError end |
.transform(path, params = {}, options = {}) ⇒ Object
Transform a file and save the output to a destination path
Parameters:
destination (required) - string - Destination file path for the transformed output.
transform_type (required) - string - Transform type. Supported values are `image_convert`, `document_convert`, and `files_transform_script_execute`.
target_format (required) - string - Destination format to create.
script - string - Files TransformScript source. Required when transform_type is `files_transform_script_execute`.
width - int64 - Maximum output width for image_convert.
height - int64 - Maximum output height for image_convert.
overwrite - boolean - Overwrite existing file in the destination?
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 |
# File 'lib/files.com/models/file.rb', line 1440 def self.transform(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: transform_type must be an String") if params[:transform_type] and !params[:transform_type].is_a?(String) raise InvalidParameterError.new("Bad parameter: target_format must be an String") if params[:target_format] and !params[:target_format].is_a?(String) raise InvalidParameterError.new("Bad parameter: script must be an String") if params[:script] and !params[:script].is_a?(String) raise InvalidParameterError.new("Bad parameter: width must be an Integer") if params[:width] and !params[:width].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: height must be an Integer") if params[:height] and !params[:height].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] raise MissingParameterError.new("Parameter missing: transform_type") unless params[:transform_type] raise MissingParameterError.new("Parameter missing: target_format") unless params[:target_format] response, = Api.send_request("/file_actions/transform/#{params[:path]}", :post, params, ) FileAction.new(response.data, ) end |
.try_convert(*_args) ⇒ Object
172 173 174 |
# File 'lib/files.com/models/file.rb', line 172 def self.try_convert(*_args) raise NotImplementedError end |
.unlink(*paths) ⇒ Object
176 177 178 |
# File 'lib/files.com/models/file.rb', line 176 def self.unlink(*paths) paths.map { |p| delete(p) } end |
.unzip(path, params = {}, options = {}) ⇒ Object
Extract a ZIP file to a destination folder
Parameters:
destination (required) - string - Destination folder path for extracted files.
filename - string - Optional single entry filename to extract.
overwrite - boolean - Overwrite existing files in the destination?
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 |
# File 'lib/files.com/models/file.rb', line 1512 def self.unzip(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: filename must be an String") if params[:filename] and !params[:filename].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/unzip", :post, params, ) FileAction.new(response.data, ) end |
.update(path, params = {}, options = {}) ⇒ Object
Parameters:
custom_metadata - object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
provided_mtime - string - Modified time of file.
priority_color - string - Priority/Bookmark color of file.
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 |
# File 'lib/files.com/models/file.rb', line 1331 def self.update(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: custom_metadata must be an Hash") if params[:custom_metadata] and !params[:custom_metadata].is_a?(Hash) raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String) raise InvalidParameterError.new("Bad parameter: priority_color must be an String") if params[:priority_color] and !params[:priority_color].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/files/#{params[:path]}", :patch, params, ) File.new(response.data, ) end |
.upload_chunks(io, path, options, upload = nil, etags = [], params: {}) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/files.com/models/file.rb', line 180 def self.upload_chunks(io, path, , upload = nil, = [], params: {}) ||= [] bytes_written = 0 request_parts = [:size] && [:size] < 5.megabytes ? 1 : 5 loop do begin_upload = File.begin_upload(path, params.merge(ref: upload&.ref, parts: request_parts, part: (upload&.part_number || 0) + 1), ) if begin_upload.nil? || begin_upload.empty? upload = begin_upload.is_a?(Enumerable) ? begin_upload.shift : begin_upload buf = io.read(upload.partsize) || "" bytes_written += buf.length method = upload.http_method.downcase.to_sym response = client().remote_request(method, upload.upload_uri, { 'Content-Length': buf.length.to_s, 'Content-Type': 'application/octet-stream' }, buf) << { etag: response.headers["ETag"], part: upload.part_number } return upload, , bytes_written if io.eof? end end |
.upload_file(path, destination = nil, options = {}, params: {}) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/files.com/models/file.rb', line 196 def self.upload_file(path, destination = nil, = {}, params: {}) local_file = ::File.open(path, 'r') destination ||= File.basename(path) params[:size] ||= local_file.size upload, = upload_chunks(local_file, destination, , params: params) params = { action: "end", etags: , provided_mtime: local_file.mtime.to_s, ref: upload.ref, size: local_file.size } create(destination, params, ) ensure local_file.close end |
.upload_to_child_site(path, site_id, destination = nil, options = {}, params: {}) ⇒ Object
71 72 73 74 |
# File 'lib/files.com/models/file.rb', line 71 def self.upload_to_child_site(path, site_id, destination = nil, = {}, params: {}) destination ||= ::File.basename(path) upload_file(path, underscore_destination_path("Sites", site_id, destination), , params: params) end |
.upload_to_remote_server(path, remote_server_id, destination = nil, options = {}, params: {}) ⇒ Object
45 46 47 48 |
# File 'lib/files.com/models/file.rb', line 45 def self.upload_to_remote_server(path, remote_server_id, destination = nil, = {}, params: {}) destination ||= ::File.basename(path) upload_file(path, underscore_destination_path("RemoteServers", remote_server_id, destination), , params: params) end |
.upload_to_snapshot(path, snapshot_id, destination = nil, options = {}, params: {}) ⇒ Object
58 59 60 61 |
# File 'lib/files.com/models/file.rb', line 58 def self.upload_to_snapshot(path, snapshot_id, destination = nil, = {}, params: {}) destination ||= ::File.basename(path) upload_file(path, underscore_destination_path("Snapshots", snapshot_id, destination), , params: params) end |
.write(*_args) ⇒ Object
215 216 217 |
# File 'lib/files.com/models/file.rb', line 215 def self.write(*_args) raise NotImplementedError end |
.zero?(path) ⇒ Boolean
219 220 221 |
# File 'lib/files.com/models/file.rb', line 219 def self.zero?(path) new(path).empty? end |
.zip(params = {}, options = {}) ⇒ Object
Parameters:
paths (required) - array(string) - Paths to include in the ZIP.
destination (required) - string - Destination file path for the ZIP.
overwrite - boolean - Overwrite existing file in the destination?
1529 1530 1531 1532 1533 1534 1535 1536 1537 |
# File 'lib/files.com/models/file.rb', line 1529 def self.zip(params = {}, = {}) raise InvalidParameterError.new("Bad parameter: paths must be an Array") if params[:paths] and !params[:paths].is_a?(Array) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: paths") unless params[:paths] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] response, = Api.send_request("/file_actions/zip", :post, params, ) FileAction.new(response.data, ) end |
.zip_list_contents(path, params = {}, options = {}) ⇒ Object
List the contents of a ZIP file
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 |
# File 'lib/files.com/models/file.rb', line 1382 def self.zip_list_contents(path, params = {}, = {}) params ||= {} params[:path] = path raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] response, = Api.send_request("/file_actions/zip_list/#{params[:path]}", :get, params, ) response.data.map do |entity_data| ZipListEntry.new(entity_data, ) end end |
Instance Method Details
#action ⇒ Object
string - The action to perform. Can be append, attachment, end, upload, put, or may not exist
948 949 950 |
# File 'lib/files.com/models/file.rb', line 948 def action @attributes[:action] end |
#action=(value) ⇒ Object
952 953 954 |
# File 'lib/files.com/models/file.rb', line 952 def action=(value) @attributes[:action] = value end |
#advise(*_args) ⇒ Object
257 |
# File 'lib/files.com/models/file.rb', line 257 def advise(*_args); end |
#atime ⇒ Object
259 260 261 |
# File 'lib/files.com/models/file.rb', line 259 def atime mtime end |
#autoclose=(*_args) ⇒ Object
263 |
# File 'lib/files.com/models/file.rb', line 263 def autoclose=(*_args); end |
#autoclose?(*_args) ⇒ Boolean
265 |
# File 'lib/files.com/models/file.rb', line 265 def autoclose?(*_args); end |
#begin_upload(params = {}) ⇒ Object
Begin File Upload
Parameters:
mkdir_parents - boolean - Create parent directories if they do not exist?
part - int64 - Part if uploading a part.
parts - int64 - How many parts to fetch?
ref - string -
restart - int64 - File byte offset to restart from.
size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
with_rename - boolean - Allow file rename instead of overwrite?
buffered_upload - boolean - If true, and the path refers to a destination not stored on Files.com (such as a remote server mount), the upload will be uploaded first to Files.com before being sent to the remote server mount. This can allow clients to upload using parallel parts to a remote server destination that does not offer parallel parts support natively.
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 |
# File 'lib/files.com/models/file.rb', line 1251 def begin_upload(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: part must be an Integer") if params[:part] and !params[:part].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: parts must be an Integer") if params[:parts] and !params[:parts].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: ref must be an String") if params[:ref] and !params[:ref].is_a?(String) raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params[:restart] and !params[:restart].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: size must be an Integer") if params[:size] and !params[:size].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/file_actions/begin_upload/#{@attributes[:path]}", :post, params, @options) end |
#binmode ⇒ Object
267 268 269 |
# File 'lib/files.com/models/file.rb', line 267 def binmode binmode? end |
#binmode? ⇒ Boolean
271 272 273 |
# File 'lib/files.com/models/file.rb', line 271 def binmode? true end |
#birthtime ⇒ Object
275 276 277 |
# File 'lib/files.com/models/file.rb', line 275 def birthtime raise NotImplementedError end |
#buffered_upload ⇒ Object
boolean - If true, and the path refers to a destination not stored on Files.com (such as a remote server mount), the upload will be uploaded first to Files.com before being sent to the remote server mount. This can allow clients to upload using parallel parts to a remote server destination that does not offer parallel parts support natively.
1038 1039 1040 |
# File 'lib/files.com/models/file.rb', line 1038 def buffered_upload @attributes[:buffered_upload] end |
#buffered_upload=(value) ⇒ Object
1042 1043 1044 |
# File 'lib/files.com/models/file.rb', line 1042 def buffered_upload=(value) @attributes[:buffered_upload] = value end |
#bytes ⇒ Object
279 280 281 |
# File 'lib/files.com/models/file.rb', line 279 def bytes read_io.bytes end |
#chars ⇒ Object
283 284 285 |
# File 'lib/files.com/models/file.rb', line 283 def chars read_io.chars end |
#chmod(*_args) ⇒ Object
287 288 289 |
# File 'lib/files.com/models/file.rb', line 287 def chmod(*_args) raise NotImplementedError end |
#chown(*_args) ⇒ Object
291 292 293 |
# File 'lib/files.com/models/file.rb', line 291 def chown(*_args) raise NotImplementedError end |
#client ⇒ Object
295 296 297 |
# File 'lib/files.com/models/file.rb', line 295 def client [:client] || ApiClient.active_client end |
#close(**kwargs) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/files.com/models/file.rb', line 299 def close(**kwargs) flush if @upload = { action: 'end', etags: @etags, provided_mtime: Time.now.to_s, ref: @upload.ref, size: @bytes_written, } .merge!(kwargs) if kwargs file = File.create(path, , @options) @attributes = file.attributes @upload = nil end @write_io.close end |
#close_on_exec=(*args) ⇒ Object
323 324 325 |
# File 'lib/files.com/models/file.rb', line 323 def close_on_exec=(*args) @write_io.close_on_exec = *args end |
#close_on_exec?(*args) ⇒ Boolean
319 320 321 |
# File 'lib/files.com/models/file.rb', line 319 def close_on_exec?(*args) @write_io.close_on_exec? *args end |
#close_read(*args) ⇒ Object
327 328 329 |
# File 'lib/files.com/models/file.rb', line 327 def close_read(*args) @write_io.close_read *args end |
#close_write(*args) ⇒ Object
331 332 333 |
# File 'lib/files.com/models/file.rb', line 331 def close_write(*args) @write_io.close_write *args end |
#closed?(*args) ⇒ Boolean
335 336 337 |
# File 'lib/files.com/models/file.rb', line 335 def closed?(*args) @write_io.closed? *args end |
#codepoints(*args, &block) ⇒ Object
339 340 341 |
# File 'lib/files.com/models/file.rb', line 339 def codepoints(*args, &block) @write_io.codepoints *args, &block end |
#copy(params = {}) ⇒ Object
Copy File/Folder
Parameters:
destination (required) - string - Copy destination path.
copy_behaviors - boolean - If copying a folder, also copy supported behaviors to the destination folder tree?
structure - boolean - Copy structure only?
overwrite - boolean - Overwrite existing file(s) in the destination?
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/files.com/models/file.rb', line 1116 def copy(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] Api.send_request("/file_actions/copy/#{@attributes[:path]}", :post, params, @options) end |
#copy_behaviors ⇒ Object
boolean - If copying a folder, also copy supported behaviors to the destination folder tree?
1011 1012 1013 |
# File 'lib/files.com/models/file.rb', line 1011 def copy_behaviors @attributes[:copy_behaviors] end |
#copy_behaviors=(value) ⇒ Object
1015 1016 1017 |
# File 'lib/files.com/models/file.rb', line 1015 def copy_behaviors=(value) @attributes[:copy_behaviors] = value end |
#copy_to_child_site(site_id, destination, params = {}) ⇒ Object
249 250 251 |
# File 'lib/files.com/models/file.rb', line 249 def copy_to_child_site(site_id, destination, params = {}) self.class.copy_to_child_site(path, site_id, destination, params, @options) end |
#copy_to_remote_server(remote_server_id, destination, params = {}) ⇒ Object
233 234 235 |
# File 'lib/files.com/models/file.rb', line 233 def copy_to_remote_server(remote_server_id, destination, params = {}) self.class.copy_to_remote_server(path, remote_server_id, destination, params, @options) end |
#copy_to_snapshot(snapshot_id, destination, params = {}) ⇒ Object
241 242 243 |
# File 'lib/files.com/models/file.rb', line 241 def copy_to_snapshot(snapshot_id, destination, params = {}) self.class.copy_to_snapshot(path, snapshot_id, destination, params, @options) end |
#crc32 ⇒ Object
string - File CRC32 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
831 832 833 |
# File 'lib/files.com/models/file.rb', line 831 def crc32 @attributes[:crc32] end |
#crc32=(value) ⇒ Object
835 836 837 |
# File 'lib/files.com/models/file.rb', line 835 def crc32=(value) @attributes[:crc32] = value end |
#created_at ⇒ Object
date-time - File created date/time
754 755 756 |
# File 'lib/files.com/models/file.rb', line 754 def created_at @attributes[:created_at] end |
#created_by_api_key_id ⇒ Object
int64 - ID of the API key that created the file/folder
655 656 657 |
# File 'lib/files.com/models/file.rb', line 655 def created_by_api_key_id @attributes[:created_by_api_key_id] end |
#created_by_api_key_id=(value) ⇒ Object
659 660 661 |
# File 'lib/files.com/models/file.rb', line 659 def created_by_api_key_id=(value) @attributes[:created_by_api_key_id] = value end |
#created_by_as2_incoming_message_id ⇒ Object
int64 - ID of the AS2 Incoming Message that created the file/folder
664 665 666 |
# File 'lib/files.com/models/file.rb', line 664 def @attributes[:created_by_as2_incoming_message_id] end |
#created_by_as2_incoming_message_id=(value) ⇒ Object
668 669 670 |
# File 'lib/files.com/models/file.rb', line 668 def (value) @attributes[:created_by_as2_incoming_message_id] = value end |
#created_by_automation_id ⇒ Object
int64 - ID of the Automation that created the file/folder
673 674 675 |
# File 'lib/files.com/models/file.rb', line 673 def created_by_automation_id @attributes[:created_by_automation_id] end |
#created_by_automation_id=(value) ⇒ Object
677 678 679 |
# File 'lib/files.com/models/file.rb', line 677 def created_by_automation_id=(value) @attributes[:created_by_automation_id] = value end |
#created_by_bundle_registration_id ⇒ Object
int64 - ID of the Bundle Registration that created the file/folder
682 683 684 |
# File 'lib/files.com/models/file.rb', line 682 def created_by_bundle_registration_id @attributes[:created_by_bundle_registration_id] end |
#created_by_bundle_registration_id=(value) ⇒ Object
686 687 688 |
# File 'lib/files.com/models/file.rb', line 686 def created_by_bundle_registration_id=(value) @attributes[:created_by_bundle_registration_id] = value end |
#created_by_id ⇒ Object
int64 - User ID of the User who created the file/folder
646 647 648 |
# File 'lib/files.com/models/file.rb', line 646 def created_by_id @attributes[:created_by_id] end |
#created_by_id=(value) ⇒ Object
650 651 652 |
# File 'lib/files.com/models/file.rb', line 650 def created_by_id=(value) @attributes[:created_by_id] = value end |
#created_by_inbox_id ⇒ Object
int64 - ID of the Inbox that created the file/folder
691 692 693 |
# File 'lib/files.com/models/file.rb', line 691 def created_by_inbox_id @attributes[:created_by_inbox_id] end |
#created_by_inbox_id=(value) ⇒ Object
695 696 697 |
# File 'lib/files.com/models/file.rb', line 695 def created_by_inbox_id=(value) @attributes[:created_by_inbox_id] = value end |
#created_by_remote_server_id ⇒ Object
int64 - ID of the Remote Server that created the file/folder
700 701 702 |
# File 'lib/files.com/models/file.rb', line 700 def created_by_remote_server_id @attributes[:created_by_remote_server_id] end |
#created_by_remote_server_id=(value) ⇒ Object
704 705 706 |
# File 'lib/files.com/models/file.rb', line 704 def created_by_remote_server_id=(value) @attributes[:created_by_remote_server_id] = value end |
#created_by_sync_id ⇒ Object
int64 - ID of the Sync that created the file/folder
709 710 711 |
# File 'lib/files.com/models/file.rb', line 709 def created_by_sync_id @attributes[:created_by_sync_id] end |
#created_by_sync_id=(value) ⇒ Object
713 714 715 |
# File 'lib/files.com/models/file.rb', line 713 def created_by_sync_id=(value) @attributes[:created_by_sync_id] = value end |
#ctime(*_args) ⇒ Object
343 344 345 |
# File 'lib/files.com/models/file.rb', line 343 def ctime(*_args) mtime end |
#custom_metadata ⇒ Object
object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
718 719 720 |
# File 'lib/files.com/models/file.rb', line 718 def @attributes[:custom_metadata] end |
#custom_metadata=(value) ⇒ Object
722 723 724 |
# File 'lib/files.com/models/file.rb', line 722 def (value) @attributes[:custom_metadata] = value end |
#delete(params = {}) ⇒ Object
Parameters:
recursive - boolean - If true, will recursively delete folders. Otherwise, will error on non-empty folders.
1083 1084 1085 1086 1087 1088 1089 1090 1091 |
# File 'lib/files.com/models/file.rb', line 1083 def delete(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{@attributes[:path]}", :delete, params, @options) end |
#destroy(params = {}) ⇒ Object
1093 1094 1095 1096 |
# File 'lib/files.com/models/file.rb', line 1093 def destroy(params = {}) delete(params) nil end |
#display_name ⇒ Object
string - File/Folder display name
727 728 729 |
# File 'lib/files.com/models/file.rb', line 727 def display_name @attributes[:display_name] end |
#display_name=(value) ⇒ Object
731 732 733 |
# File 'lib/files.com/models/file.rb', line 731 def display_name=(value) @attributes[:display_name] = value end |
#download(params = {}) ⇒ Object
Download File
Parameters:
action - string - Can be blank, `redirect` or `stat`. If set to `stat`, we will return file information but without a download URL, and without logging a download. If set to `redirect` we will serve a 302 redirect directly to the file. This is used for integrations with Zapier, and is not recommended for most integrations.
preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
with_previews - boolean - Include file preview information?
with_priority_color - boolean - Include file priority color information?
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
# File 'lib/files.com/models/file.rb', line 1053 def download(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: action must be an String") if params[:action] and !params[:action].is_a?(String) raise InvalidParameterError.new("Bad parameter: preview_size must be an String") if params[:preview_size] and !params[:preview_size].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{@attributes[:path]}", :get, params, @options) end |
#download_content(io, range: []) ⇒ Object
361 362 363 |
# File 'lib/files.com/models/file.rb', line 361 def download_content(io, range: []) Files::ApiClient.download_client.stream_download(download_uri_with_load, io, range) end |
#download_file(output_file) ⇒ Object
355 356 357 358 359 |
# File 'lib/files.com/models/file.rb', line 355 def download_file(output_file) ::File.open(output_file, 'wb') do |file| download_content(file) end end |
#download_uri ⇒ Object
string - Link to download file. Provided only in response to a download request.
912 913 914 |
# File 'lib/files.com/models/file.rb', line 912 def download_uri @attributes[:download_uri] end |
#download_uri=(value) ⇒ Object
916 917 918 |
# File 'lib/files.com/models/file.rb', line 916 def download_uri=(value) @attributes[:download_uri] = value end |
#download_uri_with_load ⇒ Object
347 348 349 350 351 352 353 |
# File 'lib/files.com/models/file.rb', line 347 def download_uri_with_load return download_uri if download_uri file = File.download(path, {}, @options) @attributes = file.attributes download_uri end |
#each(*args, &block) ⇒ Object
365 366 367 |
# File 'lib/files.com/models/file.rb', line 365 def each(*args, &block) read_io.each *args, &block end |
#each_byte(*args, &block) ⇒ Object
369 370 371 |
# File 'lib/files.com/models/file.rb', line 369 def each_byte(*args, &block) read_io.each_byte *args, &block end |
#each_char(*args, &block) ⇒ Object
373 374 375 |
# File 'lib/files.com/models/file.rb', line 373 def each_char(*args, &block) read_io.each_char *args, &block end |
#each_codepoint(*args, &block) ⇒ Object
377 378 379 |
# File 'lib/files.com/models/file.rb', line 377 def each_codepoint(*args, &block) read_io.each_codepoint *args, &block end |
#each_line(*args, &block) ⇒ Object
381 382 383 |
# File 'lib/files.com/models/file.rb', line 381 def each_line(*args, &block) each(*args, &block) end |
#empty? ⇒ Boolean
385 386 387 |
# File 'lib/files.com/models/file.rb', line 385 def empty? size == 0 end |
#eof ⇒ Object
389 390 391 |
# File 'lib/files.com/models/file.rb', line 389 def eof eof? end |
#eof? ⇒ Boolean
393 394 395 |
# File 'lib/files.com/models/file.rb', line 393 def eof? @write_io.eof? end |
#external_encoding(*args) ⇒ Object
397 398 399 |
# File 'lib/files.com/models/file.rb', line 397 def external_encoding(*args) internal_encoding *args end |
#fcntl(*_args) ⇒ Object
401 402 403 |
# File 'lib/files.com/models/file.rb', line 401 def fcntl(*_args) raise NotImplementedError end |
#fdatasync(*_args) ⇒ Object
405 406 407 |
# File 'lib/files.com/models/file.rb', line 405 def fdatasync(*_args) flush end |
#fileno(*_args) ⇒ Object
409 410 411 |
# File 'lib/files.com/models/file.rb', line 409 def fileno(*_args) id end |
#flock(*_args) ⇒ Object
413 414 415 |
# File 'lib/files.com/models/file.rb', line 413 def flock(*_args) raise NotImplementedError end |
#flush(*_args) ⇒ Object
417 418 419 420 421 422 423 424 425 426 |
# File 'lib/files.com/models/file.rb', line 417 def flush(*_args) if mode.include? "w" @write_io.rewind if @write_io.is_a?(StringIO) @upload, @etags, bytes_written = File.upload_chunks(@write_io, path, , @upload, @etags, params: @attributes) @bytes_written += bytes_written elsif mode.include? "a" raise NotImplementedError end end |
#fsync(*args) ⇒ Object
428 429 430 |
# File 'lib/files.com/models/file.rb', line 428 def fsync(*args) flush *args end |
#getbyte(*args) ⇒ Object
432 433 434 |
# File 'lib/files.com/models/file.rb', line 432 def getbyte(*args) read_io.getbyte *args end |
#getc(*args) ⇒ Object
436 437 438 |
# File 'lib/files.com/models/file.rb', line 436 def getc(*args) read_io.getc *args end |
#gets(*args) ⇒ Object
440 441 442 |
# File 'lib/files.com/models/file.rb', line 440 def gets(*args) read_io.gets *args end |
#gpg_decrypt(params = {}) ⇒ Object
Decrypt a GPG-encrypted file and save it to a destination path
Parameters:
destination (required) - string - Destination file path for the decrypted file.
gpg_key_ids - array(int64) - GPG Key IDs to decrypt with. If omitted, every accessible private GPG key in the source workspace is used.
gpg_key_partner_id - int64 - Partner ID whose GPG keys should be used for decryption.
use_all_private_keys - boolean - Use every accessible private GPG key in the source workspace for decryption.
ignore_mdc_error - boolean - Ignore errors from the MDC (modification detection code) check.
overwrite - boolean - Overwrite existing file in the destination?
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 |
# File 'lib/files.com/models/file.rb', line 1183 def gpg_decrypt(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: gpg_key_ids must be an Array") if params[:gpg_key_ids] and !params[:gpg_key_ids].is_a?(Array) raise InvalidParameterError.new("Bad parameter: gpg_key_partner_id must be an Integer") if params[:gpg_key_partner_id] and !params[:gpg_key_partner_id].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] Api.send_request("/file_actions/gpg_decrypt/#{@attributes[:path]}", :post, params, @options) end |
#gpg_encrypt(params = {}) ⇒ Object
Encrypt a file with GPG and save it to a destination path
Parameters:
destination (required) - string - Destination file path for the encrypted file.
gpg_key_ids - array(int64) - GPG Key IDs to encrypt with.
gpg_key_partner_id - int64 - Partner ID whose GPG keys should be used for encryption.
signing_key_id - int64 - Optional GPG Key ID to sign with.
armor - boolean - Output ASCII-armored encrypted data.
overwrite - boolean - Overwrite existing file in the destination?
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
# File 'lib/files.com/models/file.rb', line 1206 def gpg_encrypt(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: gpg_key_ids must be an Array") if params[:gpg_key_ids] and !params[:gpg_key_ids].is_a?(Array) raise InvalidParameterError.new("Bad parameter: gpg_key_partner_id must be an Integer") if params[:gpg_key_partner_id] and !params[:gpg_key_partner_id].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: signing_key_id must be an Integer") if params[:signing_key_id] and !params[:signing_key_id].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] Api.send_request("/file_actions/gpg_encrypt/#{@attributes[:path]}", :post, params, @options) end |
#internal_encoding(*_args) ⇒ Object
456 457 458 |
# File 'lib/files.com/models/file.rb', line 456 def internal_encoding(*_args) "".encoding end |
#ioctl(*_args) ⇒ Object
460 461 462 |
# File 'lib/files.com/models/file.rb', line 460 def ioctl(*_args) raise NotImplementedError end |
#is_locked ⇒ Object
boolean - Is this folder locked and unable to be modified?
903 904 905 |
# File 'lib/files.com/models/file.rb', line 903 def is_locked @attributes[:is_locked] end |
#is_locked=(value) ⇒ Object
907 908 909 |
# File 'lib/files.com/models/file.rb', line 907 def is_locked=(value) @attributes[:is_locked] = value end |
#isatty(*_args) ⇒ Object
464 465 466 |
# File 'lib/files.com/models/file.rb', line 464 def isatty(*_args) false end |
#last_modified_by_api_key_id ⇒ Object
int64 - ID of the API key that last modified the file/folder
768 769 770 |
# File 'lib/files.com/models/file.rb', line 768 def last_modified_by_api_key_id @attributes[:last_modified_by_api_key_id] end |
#last_modified_by_api_key_id=(value) ⇒ Object
772 773 774 |
# File 'lib/files.com/models/file.rb', line 772 def last_modified_by_api_key_id=(value) @attributes[:last_modified_by_api_key_id] = value end |
#last_modified_by_automation_id ⇒ Object
int64 - ID of the Automation that last modified the file/folder
777 778 779 |
# File 'lib/files.com/models/file.rb', line 777 def last_modified_by_automation_id @attributes[:last_modified_by_automation_id] end |
#last_modified_by_automation_id=(value) ⇒ Object
781 782 783 |
# File 'lib/files.com/models/file.rb', line 781 def last_modified_by_automation_id=(value) @attributes[:last_modified_by_automation_id] = value end |
#last_modified_by_bundle_registration_id ⇒ Object
int64 - ID of the Bundle Registration that last modified the file/folder
786 787 788 |
# File 'lib/files.com/models/file.rb', line 786 def last_modified_by_bundle_registration_id @attributes[:last_modified_by_bundle_registration_id] end |
#last_modified_by_bundle_registration_id=(value) ⇒ Object
790 791 792 |
# File 'lib/files.com/models/file.rb', line 790 def last_modified_by_bundle_registration_id=(value) @attributes[:last_modified_by_bundle_registration_id] = value end |
#last_modified_by_id ⇒ Object
int64 - User ID of the User who last modified the file/folder
759 760 761 |
# File 'lib/files.com/models/file.rb', line 759 def last_modified_by_id @attributes[:last_modified_by_id] end |
#last_modified_by_id=(value) ⇒ Object
763 764 765 |
# File 'lib/files.com/models/file.rb', line 763 def last_modified_by_id=(value) @attributes[:last_modified_by_id] = value end |
#last_modified_by_remote_server_id ⇒ Object
int64 - ID of the Remote Server that last modified the file/folder
795 796 797 |
# File 'lib/files.com/models/file.rb', line 795 def last_modified_by_remote_server_id @attributes[:last_modified_by_remote_server_id] end |
#last_modified_by_remote_server_id=(value) ⇒ Object
799 800 801 |
# File 'lib/files.com/models/file.rb', line 799 def last_modified_by_remote_server_id=(value) @attributes[:last_modified_by_remote_server_id] = value end |
#last_modified_by_sync_id ⇒ Object
int64 - ID of the Sync that last modified the file/folder
804 805 806 |
# File 'lib/files.com/models/file.rb', line 804 def last_modified_by_sync_id @attributes[:last_modified_by_sync_id] end |
#last_modified_by_sync_id=(value) ⇒ Object
808 809 810 |
# File 'lib/files.com/models/file.rb', line 808 def last_modified_by_sync_id=(value) @attributes[:last_modified_by_sync_id] = value end |
#length ⇒ Object
int64 - Length of file.
957 958 959 |
# File 'lib/files.com/models/file.rb', line 957 def length @attributes[:length] end |
#length=(value) ⇒ Object
961 962 963 |
# File 'lib/files.com/models/file.rb', line 961 def length=(value) @attributes[:length] = value end |
#lines(*args, &block) ⇒ Object
474 475 476 |
# File 'lib/files.com/models/file.rb', line 474 def lines(*args, &block) each_line *args, &block end |
#lstat(*_args) ⇒ Object
478 479 480 |
# File 'lib/files.com/models/file.rb', line 478 def lstat(*_args) stats end |
#md5 ⇒ Object
string - File MD5 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
840 841 842 |
# File 'lib/files.com/models/file.rb', line 840 def md5 @attributes[:md5] end |
#md5=(value) ⇒ Object
844 845 846 |
# File 'lib/files.com/models/file.rb', line 844 def md5=(value) @attributes[:md5] = value end |
#mime_type ⇒ Object
string - MIME Type. This is determined by the filename extension and is not stored separately internally.
867 868 869 |
# File 'lib/files.com/models/file.rb', line 867 def mime_type @attributes[:mime_type] end |
#mime_type=(value) ⇒ Object
871 872 873 |
# File 'lib/files.com/models/file.rb', line 871 def mime_type=(value) @attributes[:mime_type] = value end |
#mkdir_parents ⇒ Object
boolean - Create parent directories if they do not exist?
966 967 968 |
# File 'lib/files.com/models/file.rb', line 966 def mkdir_parents @attributes[:mkdir_parents] end |
#mkdir_parents=(value) ⇒ Object
970 971 972 |
# File 'lib/files.com/models/file.rb', line 970 def mkdir_parents=(value) @attributes[:mkdir_parents] = value end |
#move(params = {}) ⇒ Object
Move File/Folder
Parameters:
destination (required) - string - Move destination path.
overwrite - boolean - Overwrite existing file(s) in the destination?
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 |
# File 'lib/files.com/models/file.rb', line 1133 def move(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] Api.send_request("/file_actions/move/#{@attributes[:path]}", :post, params, @options) end |
#move_to_child_site(site_id, destination, params = {}) ⇒ Object
253 254 255 |
# File 'lib/files.com/models/file.rb', line 253 def move_to_child_site(site_id, destination, params = {}) self.class.move_to_child_site(path, site_id, destination, params, @options) end |
#move_to_remote_server(remote_server_id, destination, params = {}) ⇒ Object
237 238 239 |
# File 'lib/files.com/models/file.rb', line 237 def move_to_remote_server(remote_server_id, destination, params = {}) self.class.move_to_remote_server(path, remote_server_id, destination, params, @options) end |
#move_to_snapshot(snapshot_id, destination, params = {}) ⇒ Object
245 246 247 |
# File 'lib/files.com/models/file.rb', line 245 def move_to_snapshot(snapshot_id, destination, params = {}) self.class.move_to_snapshot(path, snapshot_id, destination, params, @options) end |
#mtime ⇒ Object
date-time - File last modified date/time, according to the server. This is the timestamp of the last Files.com operation of the file, regardless of what modified timestamp was sent.
813 814 815 |
# File 'lib/files.com/models/file.rb', line 813 def mtime @attributes[:mtime] end |
#mtime=(value) ⇒ Object
817 818 819 |
# File 'lib/files.com/models/file.rb', line 817 def mtime=(value) @attributes[:mtime] = value end |
#mv(destination) ⇒ Object
482 483 484 |
# File 'lib/files.com/models/file.rb', line 482 def mv(destination) File.move(path, destination) end |
#part ⇒ Object
int64 - Part if uploading a part.
975 976 977 |
# File 'lib/files.com/models/file.rb', line 975 def part @attributes[:part] end |
#part=(value) ⇒ Object
979 980 981 |
# File 'lib/files.com/models/file.rb', line 979 def part=(value) @attributes[:part] = value end |
#parts ⇒ Object
int64 - How many parts to fetch?
984 985 986 |
# File 'lib/files.com/models/file.rb', line 984 def parts @attributes[:parts] end |
#parts=(value) ⇒ Object
988 989 990 |
# File 'lib/files.com/models/file.rb', line 988 def parts=(value) @attributes[:parts] = value end |
#path ⇒ Object
string - File/Folder path. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
637 638 639 |
# File 'lib/files.com/models/file.rb', line 637 def path @attributes[:path] end |
#path=(value) ⇒ Object
641 642 643 |
# File 'lib/files.com/models/file.rb', line 641 def path=(value) @attributes[:path] = value end |
#permissions ⇒ Object
string - A short string representing the current user's permissions. Can be r (Read),w (Write),d (Delete), l (List) or any combination
885 886 887 |
# File 'lib/files.com/models/file.rb', line 885 def @attributes[:permissions] end |
#permissions=(value) ⇒ Object
889 890 891 |
# File 'lib/files.com/models/file.rb', line 889 def (value) @attributes[:permissions] = value end |
#pid(*_args) ⇒ Object
486 487 488 |
# File 'lib/files.com/models/file.rb', line 486 def pid(*_args) Process.pid end |
#pread(*args) ⇒ Object
494 495 496 |
# File 'lib/files.com/models/file.rb', line 494 def pread(*args) read_io.pread *args end |
#preview ⇒ Object
Preview - File preview
939 940 941 |
# File 'lib/files.com/models/file.rb', line 939 def preview @attributes[:preview] end |
#preview=(value) ⇒ Object
943 944 945 |
# File 'lib/files.com/models/file.rb', line 943 def preview=(value) @attributes[:preview] = value end |
#preview_id ⇒ Object
int64 - File preview ID
930 931 932 |
# File 'lib/files.com/models/file.rb', line 930 def preview_id @attributes[:preview_id] end |
#preview_id=(value) ⇒ Object
934 935 936 |
# File 'lib/files.com/models/file.rb', line 934 def preview_id=(value) @attributes[:preview_id] = value end |
#print(*args) ⇒ Object
498 499 500 |
# File 'lib/files.com/models/file.rb', line 498 def print(*args) @write_io.print *args end |
#printf(*args) ⇒ Object
502 503 504 |
# File 'lib/files.com/models/file.rb', line 502 def printf(*args) @write_io.printf *args end |
#priority_color ⇒ Object
string - Bookmark/priority color of file/folder
921 922 923 |
# File 'lib/files.com/models/file.rb', line 921 def priority_color @attributes[:priority_color] end |
#priority_color=(value) ⇒ Object
925 926 927 |
# File 'lib/files.com/models/file.rb', line 925 def priority_color=(value) @attributes[:priority_color] = value end |
#provided_mtime ⇒ Object
date-time - File last modified date/time, according to the client who set it. Files.com allows desktop, FTP, SFTP, and WebDAV clients to set modified at times. This allows Desktop<->Cloud syncing to preserve modified at times.
822 823 824 |
# File 'lib/files.com/models/file.rb', line 822 def provided_mtime @attributes[:provided_mtime] end |
#provided_mtime=(value) ⇒ Object
826 827 828 |
# File 'lib/files.com/models/file.rb', line 826 def provided_mtime=(value) @attributes[:provided_mtime] = value end |
#putc(*args) ⇒ Object
506 507 508 |
# File 'lib/files.com/models/file.rb', line 506 def putc(*args) @write_io.putc *args end |
#puts(*args) ⇒ Object
510 511 512 |
# File 'lib/files.com/models/file.rb', line 510 def puts(*args) @write_io.puts *args end |
#pwrite(*args) ⇒ Object
514 515 516 |
# File 'lib/files.com/models/file.rb', line 514 def pwrite(*args) @write_io.pwrite *args end |
#read(*args) ⇒ Object
518 519 520 |
# File 'lib/files.com/models/file.rb', line 518 def read(*args) read_io.read *args end |
#read_io(**options) ⇒ Object
444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/files.com/models/file.rb', line 444 def read_io(**) @read_io ||= begin r, w = SizableIO.pipe Thread.new do download_content(w, **) ensure w.close end r.wait!(5) end end |
#read_nonblock(*args) ⇒ Object
522 523 524 |
# File 'lib/files.com/models/file.rb', line 522 def read_nonblock(*args) read_io.read_nonblock *args end |
#readbyte(*args) ⇒ Object
526 527 528 |
# File 'lib/files.com/models/file.rb', line 526 def readbyte(*args) read_io.readbyte *args end |
#readchar(*args) ⇒ Object
530 531 532 |
# File 'lib/files.com/models/file.rb', line 530 def readchar(*args) read_io.readchar *args end |
#readline(*args) ⇒ Object
534 535 536 |
# File 'lib/files.com/models/file.rb', line 534 def readline(*args) read_io.readline *args end |
#readlines(*args) ⇒ Object
538 539 540 |
# File 'lib/files.com/models/file.rb', line 538 def readlines(*args) io.readlines(*args) end |
#readpartial(*args) ⇒ Object
542 543 544 |
# File 'lib/files.com/models/file.rb', line 542 def readpartial(*args) read_io.readpartial *args end |
#ref ⇒ Object
string -
993 994 995 |
# File 'lib/files.com/models/file.rb', line 993 def ref @attributes[:ref] end |
#ref=(value) ⇒ Object
997 998 999 |
# File 'lib/files.com/models/file.rb', line 997 def ref=(value) @attributes[:ref] = value end |
#region ⇒ Object
string - Region location
876 877 878 |
# File 'lib/files.com/models/file.rb', line 876 def region @attributes[:region] end |
#region=(value) ⇒ Object
880 881 882 |
# File 'lib/files.com/models/file.rb', line 880 def region=(value) @attributes[:region] = value end |
#rename(destination) ⇒ Object
546 547 548 |
# File 'lib/files.com/models/file.rb', line 546 def rename(destination) File.rename(path, destination) end |
#reopen(*_args) ⇒ Object
550 551 552 |
# File 'lib/files.com/models/file.rb', line 550 def reopen(*_args) raise NotImplementedError end |
#restart ⇒ Object
int64 - File byte offset to restart from.
1002 1003 1004 |
# File 'lib/files.com/models/file.rb', line 1002 def restart @attributes[:restart] end |
#restart=(value) ⇒ Object
1006 1007 1008 |
# File 'lib/files.com/models/file.rb', line 1006 def restart=(value) @attributes[:restart] = value end |
#rewind ⇒ Object
554 555 556 |
# File 'lib/files.com/models/file.rb', line 554 def rewind @pos = 0 end |
#save ⇒ Object
1266 1267 1268 1269 1270 |
# File 'lib/files.com/models/file.rb', line 1266 def save new_obj = File.create(path, @attributes, @options) @attributes = new_obj.attributes true end |
#seek(pos) ⇒ Object
558 559 560 |
# File 'lib/files.com/models/file.rb', line 558 def seek(pos) @pos = pos end |
#set_encoding(*_args) ⇒ Object
562 563 564 |
# File 'lib/files.com/models/file.rb', line 562 def set_encoding(*_args) raise NotImplementedError end |
#sha1 ⇒ Object
string - File SHA1 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
849 850 851 |
# File 'lib/files.com/models/file.rb', line 849 def sha1 @attributes[:sha1] end |
#sha1=(value) ⇒ Object
853 854 855 |
# File 'lib/files.com/models/file.rb', line 853 def sha1=(value) @attributes[:sha1] = value end |
#sha256 ⇒ Object
string - File SHA256 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
858 859 860 |
# File 'lib/files.com/models/file.rb', line 858 def sha256 @attributes[:sha256] end |
#sha256=(value) ⇒ Object
862 863 864 |
# File 'lib/files.com/models/file.rb', line 862 def sha256=(value) @attributes[:sha256] = value end |
#size ⇒ Object
int64 - File/Folder size
745 746 747 |
# File 'lib/files.com/models/file.rb', line 745 def size @attributes[:size] end |
#size=(value) ⇒ Object
749 750 751 |
# File 'lib/files.com/models/file.rb', line 749 def size=(value) @attributes[:size] = value end |
#stat(*_args) ⇒ Object
566 567 568 |
# File 'lib/files.com/models/file.rb', line 566 def stat(*_args) stats end |
#structure ⇒ Object
string - If copying folder, copy just the structure?
1020 1021 1022 |
# File 'lib/files.com/models/file.rb', line 1020 def structure @attributes[:structure] end |
#structure=(value) ⇒ Object
1024 1025 1026 |
# File 'lib/files.com/models/file.rb', line 1024 def structure=(value) @attributes[:structure] = value end |
#subfolders_locked=(value) ⇒ Object
898 899 900 |
# File 'lib/files.com/models/file.rb', line 898 def subfolders_locked=(value) @attributes[:subfolders_locked?] = value end |
#subfolders_locked? ⇒ Boolean
boolean - Are subfolders locked and unable to be modified?
894 895 896 |
# File 'lib/files.com/models/file.rb', line 894 def subfolders_locked? @attributes[:subfolders_locked?] end |
#sysread(*args) ⇒ Object
574 575 576 |
# File 'lib/files.com/models/file.rb', line 574 def sysread(*args) read *args end |
#sysseek(*args) ⇒ Object
578 579 580 |
# File 'lib/files.com/models/file.rb', line 578 def sysseek(*args) seek *args end |
#syswrite(*_args) ⇒ Object
582 583 584 |
# File 'lib/files.com/models/file.rb', line 582 def syswrite(*_args) raise NotImplementedError end |
#tell ⇒ Object
586 587 588 |
# File 'lib/files.com/models/file.rb', line 586 def tell pos end |
#to_i(*_args) ⇒ Object
590 591 592 |
# File 'lib/files.com/models/file.rb', line 590 def to_i(*_args) fileno end |
#to_io(*_args) ⇒ Object
594 595 596 |
# File 'lib/files.com/models/file.rb', line 594 def to_io(*_args) @write_io end |
#to_path(*_args) ⇒ Object
598 599 600 |
# File 'lib/files.com/models/file.rb', line 598 def to_path(*_args) path end |
#transform(params = {}) ⇒ Object
Transform a file and save the output to a destination path
Parameters:
destination (required) - string - Destination file path for the transformed output.
transform_type (required) - string - Transform type. Supported values are `image_convert`, `document_convert`, and `files_transform_script_execute`.
target_format (required) - string - Destination format to create.
script - string - Files TransformScript source. Required when transform_type is `files_transform_script_execute`.
width - int64 - Maximum output width for image_convert.
height - int64 - Maximum output height for image_convert.
overwrite - boolean - Overwrite existing file in the destination?
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 |
# File 'lib/files.com/models/file.rb', line 1155 def transform(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: transform_type must be an String") if params[:transform_type] and !params[:transform_type].is_a?(String) raise InvalidParameterError.new("Bad parameter: target_format must be an String") if params[:target_format] and !params[:target_format].is_a?(String) raise InvalidParameterError.new("Bad parameter: script must be an String") if params[:script] and !params[:script].is_a?(String) raise InvalidParameterError.new("Bad parameter: width must be an Integer") if params[:width] and !params[:width].is_a?(Integer) raise InvalidParameterError.new("Bad parameter: height must be an Integer") if params[:height] and !params[:height].is_a?(Integer) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] raise MissingParameterError.new("Parameter missing: transform_type") unless params[:transform_type] raise MissingParameterError.new("Parameter missing: target_format") unless params[:target_format] Api.send_request("/file_actions/transform/#{@attributes[:path]}", :post, params, @options) end |
#truncate(*_args) ⇒ Object
602 603 604 |
# File 'lib/files.com/models/file.rb', line 602 def truncate(*_args) raise NotImplementedError end |
#tty?(*_args) ⇒ Boolean
606 607 608 |
# File 'lib/files.com/models/file.rb', line 606 def tty?(*_args) false end |
#type ⇒ Object
string - Type: directory or file.
736 737 738 |
# File 'lib/files.com/models/file.rb', line 736 def type @attributes[:type] end |
#type=(value) ⇒ Object
740 741 742 |
# File 'lib/files.com/models/file.rb', line 740 def type=(value) @attributes[:type] = value end |
#ungetbyte(*_args) ⇒ Object
610 611 612 |
# File 'lib/files.com/models/file.rb', line 610 def ungetbyte(*_args) raise NotImplementedError end |
#ungetc(*_args) ⇒ Object
614 615 616 |
# File 'lib/files.com/models/file.rb', line 614 def ungetc(*_args) raise NotImplementedError end |
#unzip(params = {}) ⇒ Object
Extract a ZIP file to a destination folder
Parameters:
destination (required) - string - Destination folder path for extracted files.
filename - string - Optional single entry filename to extract.
overwrite - boolean - Overwrite existing files in the destination?
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'lib/files.com/models/file.rb', line 1227 def unzip(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: destination must be an String") if params[:destination] and !params[:destination].is_a?(String) raise InvalidParameterError.new("Bad parameter: filename must be an String") if params[:filename] and !params[:filename].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] raise MissingParameterError.new("Parameter missing: destination") unless params[:destination] Api.send_request("/file_actions/unzip", :post, params, @options) end |
#update(params = {}) ⇒ Object
Parameters:
custom_metadata - object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
provided_mtime - string - Modified time of file.
priority_color - string - Priority/Bookmark color of file.
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 |
# File 'lib/files.com/models/file.rb', line 1069 def update(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise InvalidParameterError.new("Bad parameter: provided_mtime must be an String") if params[:provided_mtime] and !params[:provided_mtime].is_a?(String) raise InvalidParameterError.new("Bad parameter: priority_color must be an String") if params[:priority_color] and !params[:priority_color].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/files/#{@attributes[:path]}", :patch, params, @options) end |
#upload_file(local_file) ⇒ Object
618 619 620 |
# File 'lib/files.com/models/file.rb', line 618 def upload_file(local_file) File.upload_file(local_file.path, params: @attributes) end |
#with_rename ⇒ Object
boolean - Allow file rename instead of overwrite?
1029 1030 1031 |
# File 'lib/files.com/models/file.rb', line 1029 def with_rename @attributes[:with_rename] end |
#with_rename=(value) ⇒ Object
1033 1034 1035 |
# File 'lib/files.com/models/file.rb', line 1033 def with_rename=(value) @attributes[:with_rename] = value end |
#write(*args) ⇒ Object
622 623 624 625 626 627 628 629 630 |
# File 'lib/files.com/models/file.rb', line 622 def write(*args) @mode ||= 'w' if args[0].respond_to?(:read) flush if @write_io.size > 0 # rubocop:disable Style/ZeroLengthPredicate @write_io = args[0] else @write_io.write *args end end |
#write_nonblock(*args) ⇒ Object
632 633 634 |
# File 'lib/files.com/models/file.rb', line 632 def write_nonblock(*args) @write_io.write_nonblock *args end |
#zip_list_contents(params = {}) ⇒ Object
List the contents of a ZIP file
1099 1100 1101 1102 1103 1104 1105 1106 1107 |
# File 'lib/files.com/models/file.rb', line 1099 def zip_list_contents(params = {}) params ||= {} params[:path] = @attributes[:path] raise MissingParameterError.new("Current object doesn't have a path") unless @attributes[:path] raise InvalidParameterError.new("Bad parameter: path must be an String") if params[:path] and !params[:path].is_a?(String) raise MissingParameterError.new("Parameter missing: path") unless params[:path] Api.send_request("/file_actions/zip_list/#{@attributes[:path]}", :get, params, @options) end |