Class: Lumberg::Cpanel::FileManager
- Defined in:
- lib/lumberg/cpanel/file_manager.rb
Overview
Public: This module provides access to file functions such as listing directories and viewing files.
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Whm::Base
Class Method Summary collapse
Instance Method Summary collapse
-
#disk_usage ⇒ Object
Public: Retrieve disk usage statistics about your account.
-
#list(options = {}) ⇒ Object
Public: list files and attributes contained within a specified directory.
-
#operate(options = {}) ⇒ Object
Public: Perform an operation on a file or group of files.
-
#show(options = {}) ⇒ Object
Public: View a file within your home directory.
-
#stat(options = {}) ⇒ Object
Public: Retrieve information about specific files.
Methods inherited from Base
Methods inherited from Whm::Base
Constructor Details
This class inherits a constructor from Lumberg::Cpanel::Base
Class Method Details
.api_module ⇒ Object
6 |
# File 'lib/lumberg/cpanel/file_manager.rb', line 6 def self.api_module; "Fileman"; end |
Instance Method Details
#disk_usage ⇒ Object
Public: Retrieve disk usage statistics about your account.
Returns Hash API response.
100 101 102 |
# File 'lib/lumberg/cpanel/file_manager.rb', line 100 def disk_usage perform_request({ api_function: 'getdiskinfo' }) end |
#list(options = {}) ⇒ Object
Public: list files and attributes contained within a specified directory
options - Hash options for API call params (default: {})
:check_leaf - Boolean value of "1" will cause the function to add
"isleaf" parameter to the output key, e.g: true value
(1) indicates a directory that has no subdirectories
(default: '')
:directory - String directory that contains the files you wish to
browse, and '/' represents your home directory.
(default: 'your home directory')
:list - A Boolean value of "1" indicates the function to look for
keys that begin with "filepath-*". These keys are used to
indicate specific files to list (default: '')
:path - String parameter allows you to specify files you want listed
with the output if :list is set to "1". This can be any
number of parameters such as "filelist-A", "filelist-B", etc.
Each of these keys indicate a file you wish to view
(default:'')
:need_mime - A Boolean value of "1" indicates that you would like the
function to add the 'mimename' and 'mimetype' to output
(default: '')
:show_dot_files - A Boolean value of "1" indicates that you'd like
the function to add dotfiles to output
(default: '')
:types - String filter allowing you to specify which file types you
wish to view. Acceptable values include "dir", "file" and
"special". Separate each type using a pipe (|) to add
multiple values. (default: '')
Examples
api_args = { host: "x.x.x.x", hash: "pass", api_username: "user" }
file_manager = Lumberg::Cpanel::FileManager.new(api_args.dup)
file_manager.list
Returns Hash API response.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lumberg/cpanel/file_manager.rb', line 52 def list( = {}) [:dir] = .delete(:directory) [:filelist] = .delete(:list) [:filepath] = .delete(:path) [:needmime] = .delete(:need_mime) [:checkleaf] = .delete(:check_leaf) [:showdotfiles] = .delete(:show_dot_files) perform_request({ api_function: 'listfiles' }.merge()) end |
#operate(options = {}) ⇒ Object
Public: Perform an operation on a file or group of files. You can use this function to copy, move, rename, chmod, extract and compress, link and unlink, and trash files and directories.
options - Hash options for API call params (default: {})
:name - String naming the operation to perform. Acceptable values
include 'copy', 'move', 'rename', 'chmod', 'extract',
'compress', 'link', 'unlink', and 'trash' (move to .trash
directory)
:source_files - String files on which you wish to perform the
operation. You can include multiple files by
separating each file with a comma (,). Do not add
spaces.
:destination_files - String list of destination filenames. If
multiple sourcefiles are listed with multiple
destination files ('destfiles'), the function
attempts to handle each transaction on a 1-to-1
basis. If only 1 file is specified in
'sourcefiles', it will be moved, or copied, or
etc. to the first directory listed.
:decode_uri - Boolean value. Entering '1' will cause the function to
decode the URI-encoded variables :source_files and
:destination_files
:metadata - String parameter which contains any added values required
by the named operation. When using 'compress', tihs would
be the archive type. Acceptable values for the compress
operation include: tar, gz, bz2, zip, tar.gz and tar.bz2.
The chmod operation requires octal octal permissions like
0755 or 0700.
Returns Hash API response
135 136 137 138 139 140 141 142 |
# File 'lib/lumberg/cpanel/file_manager.rb', line 135 def operate(={}) [:op] = .delete(:name) [:doubledecode] = .delete(:decode_uri) [:sourcefiles] = .delete(:source_files) [:destfiles] = .delete(:destination_files) perform_request({ api_function: "fileop" }.merge()) end |
#show(options = {}) ⇒ Object
Public: View a file within your home directory. This function also display additional information about the file such as the contents of a tarball, a link to an image and more
options - Hash options for API call params (default: {})
:directory - String directory in which the file is located. Path must
be relative to user's home, e.g: 'public_html/files/'
(default: '')
:file - String path to the file you wish to view
Returns Hash API response.
74 75 76 77 78 |
# File 'lib/lumberg/cpanel/file_manager.rb', line 74 def show( = {}) [:dir] = .delete(:directory) perform_request({ api_function: 'viewfile' }.merge()) end |
#stat(options = {}) ⇒ Object
Public: Retrieve information about specific files
options - Hash options for API call params (default: {})
:directory - String directory whose files you wish to review, (e.g:
/home/user/public_html/files). (default: 'your home')
:file - String name of the file whose statistics you wish to review.
You may define multiple files by separating each value with a
pipe, e.g: 'file1|file2|file3'
Returns Hash API response.
91 92 93 94 95 |
# File 'lib/lumberg/cpanel/file_manager.rb', line 91 def stat( = {}) [:dir] = .delete(:directory) perform_request({ api_function: 'statfiles' }.merge()) end |