Class: NVX::SDS::Folder

Inherits:
ItemBase show all
Defined in:
lib/nvx/sds/folder.rb

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

Instance Method Summary collapse

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
# File 'lib/nvx/sds/folder.rb', line 83

def Folder.ListFolder(, 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, )

    p = Pathname.new(path)

    attributes = FSFolderAttributes.new(nil)
    attributes.EmptyRootFolder(p.basename, p.cleanpath, nil)

    return Folder.new(, FSFolderList.new(result.to_s), attributes)
end

Instance Method Details

#CopyFiles(files_to_copy) ⇒ Object

Copies an array of files to the current folder



202
203
204
205
206
207
208
# File 'lib/nvx/sds/folder.rb', line 202

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



184
185
186
187
188
189
190
# File 'lib/nvx/sds/folder.rb', line 184

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_dateObject

Date the folder was created.



102
103
104
# File 'lib/nvx/sds/folder.rb', line 102

def created_date
    @created_date
end

#CreateFolders(folders_to_create) ⇒ Object

Creates the folder path in the current folder



175
176
177
178
179
180
181
# File 'lib/nvx/sds/folder.rb', line 175

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

#filesObject

The array of NVXFile objects.



107
108
109
110
111
112
# File 'lib/nvx/sds/folder.rb', line 107

def files 
    if @files.nil?
        raise "The children were not loaded."
    end
    @files
end

#foldersObject

The array of Folder objects.



115
116
117
118
119
120
# File 'lib/nvx/sds/folder.rb', line 115

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.



145
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
# File 'lib/nvx/sds/folder.rb', line 145

def LoadChildren(page_number, page_size, folder_sort_code = nil, should_sort_descending = nil)
    #empty the file and folder arrays.
    @files.clear
    @folders.clear

    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)
    
    #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



211
212
213
214
215
216
217
# File 'lib/nvx/sds/folder.rb', line 211

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



193
194
195
196
197
198
199
# File 'lib/nvx/sds/folder.rb', line 193

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_countObject

The current paged folders count.



140
141
142
# File 'lib/nvx/sds/folder.rb', line 140

def page_file_count
    @page_file_count
end

#page_folder_countObject

The current paged folders count.



135
136
137
# File 'lib/nvx/sds/folder.rb', line 135

def page_folder_count
    @page_folder_count
end

#Rename(new_name) ⇒ Object

Renames the current folder to the new name



220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/nvx/sds/folder.rb', line 220

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



236
237
238
239
240
241
242
# File 'lib/nvx/sds/folder.rb', line 236

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_countObject

Total number of files outside of paging, this can be used to determine when you need to page.



124
125
126
# File 'lib/nvx/sds/folder.rb', line 124

def total_file_count
    @total_file_count
end

#total_folder_countObject

Total number of folders outside of paging, this can be used to determine when you need to page.



130
131
132
# File 'lib/nvx/sds/folder.rb', line 130

def total_folder_count
    @total_folder_count
end