Class: NVX::SDS::Folder
Overview
Overview
The Folder object is used for all folder operations and to get access to files. The object is initially retrieved by calling Session.GetRootFolder.
Usage
session = Session.new("APP-KEY", "USERNAME", "APP NAME", "PASSWORD")
root_folder = session.GetRootFolder(1, 500, 0, true)
root_folder.folders.each do |folder|
print folder.name
end
Notes
-
The maximum number of items reutrned in a single page is 500
-
The folder sort codes are “Name”, “CreatedDate”, “SizeBytes”, “FileType”
-
LoadChildren must be called to handle paging, due to memory concerns we didnt want to return too many items in one request, doing so could cause problems for people using shared servers with memory caps or other limitations.
Class Method Summary collapse
-
.ListFolder(account_login, path, page_number, page_size, folder_sort_code, should_sort_descending) ⇒ Object
Returns a list of folders with root children loaded.
Instance Method Summary collapse
-
#CopyFiles(files_to_copy) ⇒ Object
Copies an array of files to the current folder.
-
#CopyFolders(folders_to_copy) ⇒ Object
Copies an array of folders to the current folder.
-
#created_date ⇒ Object
Date the folder was created.
-
#CreateFolders(folders_to_create) ⇒ Object
Creates the folder path in the current folder.
-
#files ⇒ Object
The array of NVXFile objects.
-
#folders ⇒ Object
The array of Folder objects.
-
#LoadChildren(page_number, page_size, folder_sort_code = nil, should_sort_descending = nil) ⇒ Object
Loads children NVXFile and Folder objects including any metadata.
-
#MoveFiles(files_to_move) ⇒ Object
Moves an array of files to the current folder.
-
#MoveFolders(folders_to_move) ⇒ Object
Moves an array of folders to the current folder.
-
#page_file_count ⇒ Object
The current paged folders count.
-
#page_folder_count ⇒ Object
The current paged folders count.
-
#Rename(new_name) ⇒ Object
Renames the current folder to the new name.
-
#Sideload(url, file_name, callback_url = nil) ⇒ Object
Saves a URL to the current folder.
-
#total_file_count ⇒ Object
Total number of files outside of paging, this can be used to determine when you need to page.
-
#total_folder_count ⇒ Object
Total number of folders outside of paging, this can be used to determine when you need to page.
Methods inherited from ItemBase
#HostItem, #RemoveHostedItem, #name, #path
Class Method Details
.ListFolder(account_login, path, page_number, page_size, folder_sort_code, should_sort_descending) ⇒ Object
Returns a list of folders with root children loaded. Be sure to call loadChildren to get the paged child folders and files.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nvx/sds/folder.rb', line 83 def Folder.ListFolder(account_login, path, page_number, page_size, folder_sort_code, should_sort_descending) params = [APIParam.new("pageNumber", page_number), APIParam.new("pageSize", page_size), APIParam.new("folderPath", path)] params << APIParam.new("folderSortCode", folder_sort_code) if !folder_sort_code.nil? params << APIParam.new("shouldSortDescending", should_sort_descending) if !should_sort_descending.nil? result = Transport.execute_command_post(APICommand.ListFolder, params, account_login) # add extra / to path to make absolute. p = Pathname.new(path) attributes = FSFolderAttributes.new(nil) attributes.EmptyRootFolder(p.basename, "/" + p.cleanpath, nil) return Folder.new(account_login, FSFolderList.new(result.to_s), attributes) end |
Instance Method Details
#CopyFiles(files_to_copy) ⇒ Object
Copies an array of files to the current folder
210 211 212 213 214 215 216 |
# File 'lib/nvx/sds/folder.rb', line 210 def CopyFiles(files_to_copy) params = [APIParam.new("destFolderPath", @path)] files_to_copy.each do |file| params << APIParam.new("srcFilePath", file) end Transport.execute_command_post(APICommand.CopyFiles, params, @account_login) end |
#CopyFolders(folders_to_copy) ⇒ Object
Copies an array of folders to the current folder
192 193 194 195 196 197 198 |
# File 'lib/nvx/sds/folder.rb', line 192 def CopyFolders(folders_to_copy) params = [APIParam.new("destFolderPath", @path)] folders_to_copy.each do |folder| params << APIParam.new("srcFilePath", folder) end Transport.execute_command_post(APICommand.CopyFolders, params, @account_login) end |
#created_date ⇒ Object
Date the folder was created.
103 104 105 |
# File 'lib/nvx/sds/folder.rb', line 103 def created_date @created_date end |
#CreateFolders(folders_to_create) ⇒ Object
Creates the folder path in the current folder
183 184 185 186 187 188 189 |
# File 'lib/nvx/sds/folder.rb', line 183 def CreateFolders(folders_to_create) params = Array.new folders_to_create.each do |folder| params << APIParam.new("folderPath", folder) end Transport.execute_command_post(APICommand.CreateFolders, params, @account_login) end |
#files ⇒ Object
The array of NVXFile objects.
108 109 110 111 112 113 |
# File 'lib/nvx/sds/folder.rb', line 108 def files if @files.nil? raise "The children were not loaded." end @files end |
#folders ⇒ Object
The array of Folder objects.
116 117 118 119 120 121 |
# File 'lib/nvx/sds/folder.rb', line 116 def folders if @folders.nil? raise "The children were not loaded." end @folders end |
#LoadChildren(page_number, page_size, folder_sort_code = nil, should_sort_descending = nil) ⇒ Object
Loads children NVXFile and Folder objects including any metadata.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/nvx/sds/folder.rb', line 146 def LoadChildren(page_number, page_size, folder_sort_code = nil, should_sort_descending = nil) #empty the file and folder arrays. @files.clear @folders.clear print Newline + Newline + "Path: " + @path + Newline params = [APIParam.new("pageNumber", page_number), APIParam.new("pageSize", page_size), APIParam.new("folderPath", @path)] params << APIParam.new("folderSortCode", folder_sort_code) if !folder_sort_code.nil? params << APIParam.new("shouldSortDescending", should_sort_descending) if !should_sort_descending.nil? #retrieve the folder information for the current path result = Transport.execute_command_post(APICommand.ListFolder, params, @account_login) #Load the folderlist from the xml @fs_folder_list = FSFolderList.new(result.to_s) @total_file_count = @fs_folder_list.total_file_count @total_folder_count = @fs_folder_list.total_folder_count @page_file_count = @fs_folder_list.page_file_count @page_folder_count = @fs_folder_list.page_folder_count #load the folders array from the attributes @fs_folder_list.folder_attributes.each do |folderattrib| @folders << Folder.new(@account_login, nil, folderattrib) end #load the files array from the attributes @fs_folder_list.file_attributes.each do |fileattrib| @files << NVXFile.new(@account_login, fileattrib) end end |
#MoveFiles(files_to_move) ⇒ Object
Moves an array of files to the current folder
219 220 221 222 223 224 225 |
# File 'lib/nvx/sds/folder.rb', line 219 def MoveFiles(files_to_move) params = [APIParam.new("destFolderPath", @path)] files_to_move.each do |file| params << APIParam.new("srcFilePath", file) end Transport.execute_command_post(APICommand.MoveFiles, params, @account_login) end |
#MoveFolders(folders_to_move) ⇒ Object
Moves an array of folders to the current folder
201 202 203 204 205 206 207 |
# File 'lib/nvx/sds/folder.rb', line 201 def MoveFolders(folders_to_move) params = [APIParam.new("destFolderPath", @path)] folders_to_move.each do |folder| params << APIParam.new("srcFilePath", folder) end Transport.execute_command_post(APICommand.MoveFolders, params, @account_login) end |
#page_file_count ⇒ Object
The current paged folders count.
141 142 143 |
# File 'lib/nvx/sds/folder.rb', line 141 def page_file_count @page_file_count end |
#page_folder_count ⇒ Object
The current paged folders count.
136 137 138 |
# File 'lib/nvx/sds/folder.rb', line 136 def page_folder_count @page_folder_count end |
#Rename(new_name) ⇒ Object
Renames the current folder to the new name
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/nvx/sds/folder.rb', line 228 def Rename(new_name) if @path.to_s == @account_login.root_path.to_s then raise("You cannot rename the root folder") end Transport.execute_command_post(APICommand.RenameFolder, [APIParam.new("folderPath", @path), APIParam.new("newFolderName", new_name)], @account_login) splitpath = @path.to_s.split("/") splitpath.delete(splitpath.last) splitpath << new_name @path = splitpath.join("/") end |
#Sideload(url, file_name, callback_url = nil) ⇒ Object
Saves a URL to the current folder
244 245 246 247 248 249 250 |
# File 'lib/nvx/sds/folder.rb', line 244 def Sideload(url, file_name, callback_url = nil) params = [APIParam.new("targetURL", url), APIParam.new("destFilePath", @path.to_s + "/" + file_name)] params << APIParam.new("callbackURL", callback_url) if !callback_url.nil? print params Transport.execute_command_post(APICommand.Sideload, params, @account_login) end |
#total_file_count ⇒ Object
Total number of files outside of paging, this can be used to determine when you need to page.
125 126 127 |
# File 'lib/nvx/sds/folder.rb', line 125 def total_file_count @total_file_count end |
#total_folder_count ⇒ Object
Total number of folders outside of paging, this can be used to determine when you need to page.
131 132 133 |
# File 'lib/nvx/sds/folder.rb', line 131 def total_folder_count @total_folder_count end |