nvx-sds 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +64 -0
- data/README +80 -0
- data/lib/nvx/sds/APIClasses/accountfeatureusage.rb +60 -0
- data/lib/nvx/sds/APIClasses/accountinfo.rb +30 -0
- data/lib/nvx/sds/APIClasses/accountlimit.rb +25 -0
- data/lib/nvx/sds/APIClasses/contactinfo.rb +74 -0
- data/lib/nvx/sds/APIClasses/fsfileattributes.rb +50 -0
- data/lib/nvx/sds/APIClasses/fsfolderattributes.rb +53 -0
- data/lib/nvx/sds/APIClasses/fsfolderlist.rb +70 -0
- data/lib/nvx/sds/APIClasses/metadatainfo.rb +26 -0
- data/lib/nvx/sds/APIClasses/responsecodes.rb +97 -0
- data/lib/nvx/sds/APIClasses/soapupload.rb +52 -0
- data/lib/nvx/sds/APIClasses/utilities.rb +97 -0
- data/lib/nvx/sds/SOAP/TransferClient.rb +68 -0
- data/lib/nvx/sds/SOAP/default.rb +80 -0
- data/lib/nvx/sds/SOAP/defaultDriver.rb +70 -0
- data/lib/nvx/sds/accountlogin.rb +68 -0
- data/lib/nvx/sds/apicommand.rb +251 -0
- data/lib/nvx/sds/apiparam.rb +33 -0
- data/lib/nvx/sds/countries.rb +257 -0
- data/lib/nvx/sds/folder.rb +236 -0
- data/lib/nvx/sds/hosteditem.rb +115 -0
- data/lib/nvx/sds/itembase.rb +53 -0
- data/lib/nvx/sds/masteraccount.rb +74 -0
- data/lib/nvx/sds/nvxfile.rb +173 -0
- data/lib/nvx/sds/session.rb +110 -0
- data/lib/nvx/sds/transport.rb +129 -0
- data/lib/nvx_sds.rb +19 -0
- data/tests/TestUpload.txt +9 -0
- data/tests/accountlogintest.rb +19 -0
- data/tests/apicommandtest.rb +186 -0
- data/tests/apiparamtest.rb +24 -0
- data/tests/countriestest.rb +20 -0
- data/tests/foldertest.rb +26 -0
- data/tests/fsfolderlisttest.rb +127 -0
- data/tests/masteraccounttest.rb +69 -0
- data/tests/sessiontest.rb +187 -0
- data/tests/testconfig.rb +14 -0
- data/tests/transporttest.rb +19 -0
- data/tests/unittests_gemtest.rb +17 -0
- data/tests/uploadtest.rb +22 -0
- metadata +102 -0
@@ -0,0 +1,236 @@
|
|
1
|
+
# = Overview
|
2
|
+
# The Folder object is used for all folder operations and to get access to
|
3
|
+
# files. The object is initially retrieved by calling Session.GetRootFolder.
|
4
|
+
#
|
5
|
+
# = Usage
|
6
|
+
# session = Session.new("APP-KEY", "USERNAME", "APP NAME", "PASSWORD")
|
7
|
+
# root_folder = session.GetRootFolder(1, 500, 0, true)
|
8
|
+
#
|
9
|
+
# root_folder.folders.each do |folder|
|
10
|
+
# print folder.name
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# = Notes
|
14
|
+
# * The maximum number of items reutrned in a single page is 500
|
15
|
+
# * The folder sort codes are "Name", "CreatedDate", "SizeBytes", "FileType"
|
16
|
+
# * LoadChildren must be called to handle paging, due to memory concerns we didnt want to return too many items
|
17
|
+
# in one request, doing so could cause problems for people using shared servers with memory caps or
|
18
|
+
# other limitations.
|
19
|
+
module NVX
|
20
|
+
module SDS
|
21
|
+
|
22
|
+
$:.unshift File.dirname(__FILE__)
|
23
|
+
|
24
|
+
require 'pathname'
|
25
|
+
require 'itembase'
|
26
|
+
require 'apiparam'
|
27
|
+
require 'apicommand'
|
28
|
+
require 'transport'
|
29
|
+
require 'nvxfile'
|
30
|
+
require 'apiclasses/fsfolderlist'
|
31
|
+
|
32
|
+
# = Overview
|
33
|
+
# The Folder object is used for all folder operations and to get access to
|
34
|
+
# files. The object is initially retrieved by calling Session.GetRootFolder.
|
35
|
+
#
|
36
|
+
# = Usage
|
37
|
+
# session = Session.new("APP-KEY", "USERNAME", "APP NAME", "PASSWORD")
|
38
|
+
# root_folder = session.GetRootFolder(1, 500, 0, true)
|
39
|
+
#
|
40
|
+
# root_folder.folders.each do |folder|
|
41
|
+
# print folder.name
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# = Notes
|
45
|
+
# * The maximum number of items reutrned in a single page is 500
|
46
|
+
# * The folder sort codes are "Name", "CreatedDate", "SizeBytes", "FileType"
|
47
|
+
# * LoadChildren must be called to handle paging, due to memory concerns we didnt want to return too many items
|
48
|
+
# in one request, doing so could cause problems for people using shared servers with memory caps or
|
49
|
+
# other limitations.
|
50
|
+
class Folder < ItemBase
|
51
|
+
|
52
|
+
# Private constructor use the ListFolder or look in the Folders to get
|
53
|
+
# this object directly.
|
54
|
+
private
|
55
|
+
def initialize(account_login, fs_folder_list, fs_folder_attributes)
|
56
|
+
super(account_login, fs_folder_attributes)
|
57
|
+
@folders = Array.new
|
58
|
+
@files = Array.new
|
59
|
+
@account_login = account_login
|
60
|
+
|
61
|
+
if !fs_folder_list.nil?
|
62
|
+
@fs_folder_list = fs_folder_list
|
63
|
+
|
64
|
+
@total_file_count = @fs_folder_list.total_file_count
|
65
|
+
@total_folder_count = @fs_folder_list.total_folder_count
|
66
|
+
@page_file_count = @fs_folder_list.page_file_count
|
67
|
+
@page_folder_count = @fs_folder_list.page_folder_count
|
68
|
+
|
69
|
+
fs_folder_list.folder_attributes.each do |attribute|
|
70
|
+
@folders << Folder.new(account_login, nil, attribute)
|
71
|
+
end
|
72
|
+
|
73
|
+
fs_folder_list.file_attributes.each do |attribute|
|
74
|
+
@files << NVXFile.new(account_login, attribute)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
public
|
81
|
+
# Returns a list of folders with root children loaded. Be sure to call loadChildren to
|
82
|
+
# get the paged child folders and files.
|
83
|
+
def Folder.ListFolder(account_login, path, page_number, page_size, folder_sort_code, should_sort_descending)
|
84
|
+
params = [APIParam.new("pageNumber", page_number),
|
85
|
+
APIParam.new("pageSize", page_size),
|
86
|
+
APIParam.new("folderPath", path)]
|
87
|
+
|
88
|
+
params << APIParam.new("folderSortCode", folder_sort_code) if !folder_sort_code.nil?
|
89
|
+
params << APIParam.new("shouldSortDescending", should_sort_descending) if !should_sort_descending.nil?
|
90
|
+
|
91
|
+
result = Transport.execute_command_post(APICommand.ListFolder, params, account_login)
|
92
|
+
|
93
|
+
p = Pathname.new(path)
|
94
|
+
|
95
|
+
attributes = FSFolderAttributes.new(nil)
|
96
|
+
attributes.EmptyRootFolder(p.basename, p.cleanpath, nil)
|
97
|
+
|
98
|
+
return Folder.new(account_login, FSFolderList.new(result.to_s), attributes)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Date the folder was created.
|
102
|
+
def created_date
|
103
|
+
@created_date
|
104
|
+
end
|
105
|
+
|
106
|
+
# The array of NVXFile objects.
|
107
|
+
def files
|
108
|
+
if @files.nil?
|
109
|
+
raise "The children were not loaded."
|
110
|
+
end
|
111
|
+
@files
|
112
|
+
end
|
113
|
+
|
114
|
+
# The array of Folder objects.
|
115
|
+
def folders
|
116
|
+
if @folders.nil?
|
117
|
+
raise "The children were not loaded."
|
118
|
+
end
|
119
|
+
@folders
|
120
|
+
end
|
121
|
+
|
122
|
+
# Total number of files outside of paging, this can be used to determine
|
123
|
+
# when you need to page.
|
124
|
+
def total_file_count
|
125
|
+
@total_file_count
|
126
|
+
end
|
127
|
+
|
128
|
+
# Total number of folders outside of paging, this can be used to determine
|
129
|
+
# when you need to page.
|
130
|
+
def total_folder_count
|
131
|
+
@total_folder_count
|
132
|
+
end
|
133
|
+
|
134
|
+
# The current paged folders count.
|
135
|
+
def page_folder_count
|
136
|
+
@page_folder_count
|
137
|
+
end
|
138
|
+
|
139
|
+
# The current paged folders count.
|
140
|
+
def page_file_count
|
141
|
+
@page_file_count
|
142
|
+
end
|
143
|
+
|
144
|
+
# Loads children NVXFile and Folder objects including any metadata.
|
145
|
+
def LoadChildren(page_number, page_size, folder_sort_code = nil, should_sort_descending = nil)
|
146
|
+
#empty the file and folder arrays.
|
147
|
+
@files.clear
|
148
|
+
@folders.clear
|
149
|
+
|
150
|
+
params = [APIParam.new("pageNumber", page_number),
|
151
|
+
APIParam.new("pageSize", page_size),
|
152
|
+
APIParam.new("folderPath", @path)]
|
153
|
+
|
154
|
+
params << APIParam.new("folderSortCode", folder_sort_code) if !folder_sort_code.nil?
|
155
|
+
params << APIParam.new("shouldSortDescending", should_sort_descending) if !should_sort_descending.nil?
|
156
|
+
|
157
|
+
#retrieve the folder information for the current path
|
158
|
+
result = Transport.execute_command_post(APICommand.ListFolder, params, @account_login)
|
159
|
+
|
160
|
+
#Load the folderlist from the xml
|
161
|
+
@fs_folder_list = FSFolderList.new(result.to_s)
|
162
|
+
|
163
|
+
#load the folders array from the attributes
|
164
|
+
@fs_folder_list.folder_attributes.each do |folderattrib|
|
165
|
+
@folders << Folder.new(@account_login, nil, folderattrib)
|
166
|
+
end
|
167
|
+
|
168
|
+
#load the files array from the attributes
|
169
|
+
@fs_folder_list.file_attributes.each do |fileattrib|
|
170
|
+
@files << NVXFile.new(@account_login, fileattrib)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
#Creates the folder path in the current folder
|
175
|
+
def CreateFolders(folders_to_create)
|
176
|
+
params = Array.new
|
177
|
+
folders_to_create.each do |folder|
|
178
|
+
params << APIParam.new("folderPath", folder)
|
179
|
+
end
|
180
|
+
Transport.execute_command_post(APICommand.CreateFolders, params, @account_login)
|
181
|
+
end
|
182
|
+
|
183
|
+
#Copies an array of folders to the current folder
|
184
|
+
def CopyFolders(folders_to_copy)
|
185
|
+
params = [APIParam.new("destFolderPath", @path)]
|
186
|
+
folders_to_copy.each do |folder|
|
187
|
+
params << APIParam.new("srcFilePath", folder)
|
188
|
+
end
|
189
|
+
Transport.execute_command_post(APICommand.CopyFolders, params, @account_login)
|
190
|
+
end
|
191
|
+
|
192
|
+
#Moves an array of folders to the current folder
|
193
|
+
def MoveFolders(folders_to_move)
|
194
|
+
params = [APIParam.new("destFolderPath", @path)]
|
195
|
+
folders_to_move.each do |folder|
|
196
|
+
params << APIParam.new("srcFilePath", folder)
|
197
|
+
end
|
198
|
+
Transport.execute_command_post(APICommand.MoveFolders, params, @account_login)
|
199
|
+
end
|
200
|
+
|
201
|
+
#Copies an array of files to the current folder
|
202
|
+
def CopyFiles(files_to_copy)
|
203
|
+
params = [APIParam.new("destFolderPath", @path)]
|
204
|
+
files_to_copy.each do |file|
|
205
|
+
params << APIParam.new("srcFilePath", file)
|
206
|
+
end
|
207
|
+
Transport.execute_command_post(APICommand.CopyFiles, params, @account_login)
|
208
|
+
end
|
209
|
+
|
210
|
+
#Moves an array of files to the current folder
|
211
|
+
def MoveFiles(files_to_move)
|
212
|
+
params = [APIParam.new("destFolderPath", @path)]
|
213
|
+
files_to_move.each do |file|
|
214
|
+
params << APIParam.new("srcFilePath", file)
|
215
|
+
end
|
216
|
+
Transport.execute_command_post(APICommand.MoveFiles, params, @account_login)
|
217
|
+
end
|
218
|
+
|
219
|
+
#Renames the current folder to the new name
|
220
|
+
def Rename(new_name)
|
221
|
+
if @path.to_s == @account_login.root_path.to_s then
|
222
|
+
raise("You cannot rename the root folder")
|
223
|
+
end
|
224
|
+
|
225
|
+
Transport.execute_command_post(APICommand.RenameFolder,
|
226
|
+
[APIParam.new("folderPath", @path),
|
227
|
+
APIParam.new("newFolderName", new_name)], @account_login)
|
228
|
+
|
229
|
+
splitpath = @path.to_s.split("/")
|
230
|
+
splitpath.delete(splitpath.last)
|
231
|
+
splitpath << new_name
|
232
|
+
@path = splitpath.join("/")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# = Overview
|
2
|
+
# When accessing a file or folder you can share that item publicly. When listing a hosted
|
3
|
+
# item this object is returned to represent a file or folder. You can do that by calling
|
4
|
+
# session.ListHostedItems.
|
5
|
+
#
|
6
|
+
# = Usage
|
7
|
+
# This quick example shows how to create
|
8
|
+
# session = Session.new("APP-KEY", "USERNAME", "APP Name", "123123")
|
9
|
+
# root_folder = session.GetRootFolder(1, 500, 0, true)
|
10
|
+
# root_folder.CreateFolders(["testhostfolder"])
|
11
|
+
# root_folder.LoadChildren(1, 500, 0, true)
|
12
|
+
#
|
13
|
+
# host_folder = ""
|
14
|
+
# root_folder.folders.each do |folder|
|
15
|
+
# if folder.name == "testhostfolder"
|
16
|
+
# host_folder = folder
|
17
|
+
# break
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# host_folder.HostItem
|
22
|
+
# hosted_items = session.ListHostedItems
|
23
|
+
# assert hosted_items.length == 2
|
24
|
+
#
|
25
|
+
# host_folder.RemoveHostedItem
|
26
|
+
# session.DeleteFolders([host_folder.path])
|
27
|
+
module NVX
|
28
|
+
module SDS
|
29
|
+
|
30
|
+
$:.unshift File.dirname(__FILE__)
|
31
|
+
require 'transport'
|
32
|
+
require 'apicommand'
|
33
|
+
require 'apiparam'
|
34
|
+
|
35
|
+
# = Overview
|
36
|
+
# When accessing a file or folder you can share that item publicly. When listing a hosted
|
37
|
+
# item this object is returned to represent a file or folder. You can do that by calling
|
38
|
+
# session.ListHostedItems.
|
39
|
+
#
|
40
|
+
# = Usage
|
41
|
+
# This quick example shows how to create
|
42
|
+
# session = Session.new("APP-KEY", "USERNAME", "APP Name", "123123")
|
43
|
+
# root_folder = session.GetRootFolder(1, 500, 0, true)
|
44
|
+
# root_folder.CreateFolders(["testhostfolder"])
|
45
|
+
# root_folder.LoadChildren(1, 500, 0, true)
|
46
|
+
#
|
47
|
+
# host_folder = ""
|
48
|
+
# root_folder.folders.each do |folder|
|
49
|
+
# if folder.name == "testhostfolder"
|
50
|
+
# host_folder = folder
|
51
|
+
# break
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# host_folder.HostItem
|
56
|
+
# hosted_items = session.ListHostedItems
|
57
|
+
# assert hosted_items.length == 2
|
58
|
+
#
|
59
|
+
# host_folder.RemoveHostedItem
|
60
|
+
# session.DeleteFolders([host_folder.path])
|
61
|
+
class HostedItem
|
62
|
+
|
63
|
+
private
|
64
|
+
# Private method to instantiate the object based on the xml returned.
|
65
|
+
def initialize(account_login, element)
|
66
|
+
@is_file = (text = element.elements["IsFile"].get_text and text.value).downcase == "true" ? true : false
|
67
|
+
@share_path = (text = element.elements["SharePath"].get_text and text.value)
|
68
|
+
@account_login = account_login
|
69
|
+
end
|
70
|
+
|
71
|
+
public
|
72
|
+
# Returns if the hosted item is a file or not.
|
73
|
+
def is_file?
|
74
|
+
@is_file
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns the full shared path to the file.
|
78
|
+
def share_path
|
79
|
+
@share_path
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the URL for a file that can be used to download the file publicly.
|
83
|
+
def GetFileUrl
|
84
|
+
if @is_file
|
85
|
+
raise("Cannot get a download link for a folder.")
|
86
|
+
end
|
87
|
+
|
88
|
+
Utilities.GetDownloadUrl(@account_login, @share_path, false)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns the list of currently hosted items based on page number and page size.
|
92
|
+
def HostedItem.ListHostedItems(account_login, page_number, page_size)
|
93
|
+
params = [APIParam.new("pageNumber", page_number),
|
94
|
+
APIParam.new("pageSize", page_size)]
|
95
|
+
|
96
|
+
doc = Transport.execute_command_post(APICommand.ListHostedItems, params, account_login);
|
97
|
+
|
98
|
+
hosted_items = Array.new
|
99
|
+
|
100
|
+
#if there is any metadata loop through
|
101
|
+
if doc.root.elements["//Response/HostedItem"]
|
102
|
+
doc.root.elements.each("//Response/HostedItem") do |hosted_item|
|
103
|
+
hosted_items << HostedItem.new(account_login, hosted_item)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
return hosted_items
|
107
|
+
end
|
108
|
+
|
109
|
+
# Returns a nicely fomatted string based on the share path and if its a file or folder.
|
110
|
+
def to_s
|
111
|
+
(@is_file ? "File : " : "Folder : ") + @share_path;
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# = Overview
|
2
|
+
# Base object for both files and folders. This object stores both the base attributes and allows
|
3
|
+
# setting if the item is hosted or not.
|
4
|
+
module NVX
|
5
|
+
module SDS
|
6
|
+
|
7
|
+
$:.unshift File.dirname(__FILE__)
|
8
|
+
|
9
|
+
require 'transport'
|
10
|
+
require 'apicommand'
|
11
|
+
require 'apiparam'
|
12
|
+
require 'apiclasses/fsfolderattributes'
|
13
|
+
|
14
|
+
# = Overview
|
15
|
+
# Base object for both files and folders. This object stores both the base attributes and allows
|
16
|
+
# setting if the item is hosted or not.
|
17
|
+
class ItemBase
|
18
|
+
|
19
|
+
# Creates the object based on the file/folder attributes object.
|
20
|
+
def initialize(account_login, fs_item_attributes)
|
21
|
+
if !fs_item_attributes.nil?
|
22
|
+
@account_login, @created_date = account_login, fs_item_attributes.created_date
|
23
|
+
@name, @path = fs_item_attributes.name, fs_item_attributes.path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# The date the file was created on the Nirvanix system.
|
28
|
+
def created_date
|
29
|
+
@created_date
|
30
|
+
end
|
31
|
+
|
32
|
+
# The name of the file/folder.
|
33
|
+
def name
|
34
|
+
@name
|
35
|
+
end
|
36
|
+
|
37
|
+
# The relative path to the file/folder.
|
38
|
+
def path
|
39
|
+
@path
|
40
|
+
end
|
41
|
+
|
42
|
+
# A method that hosts this file / folder making it available publicly.
|
43
|
+
def HostItem
|
44
|
+
Transport.execute_command_post(APICommand.CreateHostedItem, [APIParam.new("sharePath", @path)], @account_login)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Removes the file / folder from the list of hosted items (Does not destroy the file.)
|
48
|
+
def RemoveHostedItem
|
49
|
+
Transport.execute_command_post(APICommand.RemoveHostedItem, [APIParam.new("sharePath", @path)], @account_login)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# = Overview
|
2
|
+
#
|
3
|
+
# The Master account lets you create children, modify children, Get and Set limits, adjust account notes and
|
4
|
+
# impersonate child accounts. Impersonation is available as a simple way to log into a child account if you
|
5
|
+
# do not know the child accounts password but you are the master account. This simplifies the administration
|
6
|
+
# of child accounts.
|
7
|
+
module NVX
|
8
|
+
module SDS
|
9
|
+
# = Overview
|
10
|
+
#
|
11
|
+
# The Master account lets you create children, modify children, Get and Set limits, adjust account notes and
|
12
|
+
# impersonate child accounts. Impersonation is available as a simple way to log into a child account if you
|
13
|
+
# do not know the child accounts password but you are the master account. This simplifies the administration
|
14
|
+
# of child accounts.
|
15
|
+
class MasterAccount
|
16
|
+
|
17
|
+
# Sets the current session and account login objects.
|
18
|
+
def initialize(session, account_login)
|
19
|
+
@account_login = account_login
|
20
|
+
@session = session
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates a new child account. The username and password are required fields.
|
24
|
+
# By default there are no limits on a child account.
|
25
|
+
def CreateChildAccount(username, password, first_name = nil, last_name = nil,
|
26
|
+
middle_initial = nil, phone_number = nil, email_address = nil, email_format = nil,
|
27
|
+
address_line1 = nil, address_line2 = nil, city = nil, state = nil, country = nil, postal_code = nil)
|
28
|
+
|
29
|
+
params = [APIParam.new("username", username), APIParam.new("password", password)]
|
30
|
+
params << APIParam.new("firstName", first_name) if !first_name.nil?
|
31
|
+
params << APIParam.new("lastName", last_name) if !last_name.nil?
|
32
|
+
params << APIParam.new("middleInitial", middle_initial) if !middle_initial.nil?
|
33
|
+
params << APIParam.new("phoneNumber", phone_number) if !phone_number.nil?
|
34
|
+
params << APIParam.new("emailAddress", email_address) if !email_address.nil?
|
35
|
+
params << APIParam.new("emailFormat", email_format) if !email_format.nil?
|
36
|
+
params << APIParam.new("addressLine1", address_line1) if !address_line1.nil?
|
37
|
+
params << APIParam.new("addressLine2", address_line2) if !address_line2.nil?
|
38
|
+
params << APIParam.new("city", city) if !city.nil?
|
39
|
+
params << APIParam.new("state", state) if !state.nil?
|
40
|
+
params << APIParam.new("countryID", country) if !country.nil?
|
41
|
+
params << APIParam.new("postalCode", postal_code) if !postal_code.nil?
|
42
|
+
|
43
|
+
Transport.execute_command_post(APICommand.CreateChildAccount, params, @account_login)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Removes a child account. <i>**This will also remove ALL files/notes/account info the child previously
|
47
|
+
# had in their account.</i>
|
48
|
+
def DeleteChildAccount(username)
|
49
|
+
Transport.execute_command_post(APICommand.DeleteChildAccount, [APIParam.new("username", username)], @account_login)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Gets the account notes in xml.
|
53
|
+
def GetAccountNotes(username)
|
54
|
+
doc = Transport.execute_command_post(APICommand.GetAccountNotes, [APIParam.new("username", username)], @account_login)
|
55
|
+
|
56
|
+
return (text = doc.root.elements["//Response/GetAccountNotes"].get_text and text.value)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set the account notes. This method expects properly formated xml. Be sure to escape any invalid characters.
|
60
|
+
def SetAccountNotes(username, xml_notes)
|
61
|
+
params = [APIParam.new("username", username),
|
62
|
+
APIParam.new("xmlNotes", xml_notes)]
|
63
|
+
Transport.execute_command_post(APICommand.SetAccountNotes, params, @account_login)
|
64
|
+
end
|
65
|
+
|
66
|
+
# This lets the master account get a session for a child account that they have previously created without
|
67
|
+
# knowing the password for that child account.
|
68
|
+
def ImpersonateChildAccount(username)
|
69
|
+
@session = Session.new(@account_login.app_key, username, @account_login.app_name, nil, @account_login.session_token)
|
70
|
+
return @session
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# = Overview
|
2
|
+
# The File object is used for all file operations. The object is initially retrieved
|
3
|
+
# by calling Session.GetRootFolder and retrieving the .Files array. This is loaded with
|
4
|
+
# loadchildren.
|
5
|
+
#
|
6
|
+
# = Usage
|
7
|
+
# session = Session.new("APP-KEY", "USERNAME", "APP NAME", "PASSWORD")
|
8
|
+
# root_folder = session.GetRootFolder(1, 500, 0, true)
|
9
|
+
#
|
10
|
+
# root_folder.files.each do |file|
|
11
|
+
# print file.name
|
12
|
+
# end
|
13
|
+
module NVX
|
14
|
+
module SDS
|
15
|
+
|
16
|
+
$:.unshift File.dirname(__FILE__)
|
17
|
+
require 'itembase'
|
18
|
+
|
19
|
+
# = Overview
|
20
|
+
# The File object is used for all file operations. The object is initially retrieved
|
21
|
+
# by calling Session.GetRootFolder and retrieving the .Files array. This is loaded with
|
22
|
+
# loadchildren.
|
23
|
+
#
|
24
|
+
# = Usage
|
25
|
+
# session = Session.new("APP-KEY", "USERNAME", "APP NAME", "PASSWORD")
|
26
|
+
# root_folder = session.GetRootFolder(1, 500, 0, true)
|
27
|
+
#
|
28
|
+
# root_folder.files.each do |file|
|
29
|
+
# print file.name
|
30
|
+
# end
|
31
|
+
class NVXFile < ItemBase
|
32
|
+
|
33
|
+
# initialize the file using the default file attributes from the listFolder
|
34
|
+
# method.
|
35
|
+
def initialize(account_login, fs_file_attributes)
|
36
|
+
super(account_login, fs_file_attributes)
|
37
|
+
@account_login = account_login
|
38
|
+
@fs_file_attributes = fs_file_attributes
|
39
|
+
@size_bytes = fs_file_attributes.size_bytes
|
40
|
+
end
|
41
|
+
|
42
|
+
# The file size in bytes.
|
43
|
+
def size_bytes
|
44
|
+
@size_bytes
|
45
|
+
end
|
46
|
+
|
47
|
+
# Pass the new filename to change the path.
|
48
|
+
def Rename(new_name)
|
49
|
+
params = [APIParam.new("filePath", @path), APIParam.new("newFileName", new_name)]
|
50
|
+
|
51
|
+
Transport.execute_command_post(APICommand.RenameFile, params, @account_login)
|
52
|
+
|
53
|
+
splitpath = @path.to_s.split("/")
|
54
|
+
splitpath.delete(splitpath.last)
|
55
|
+
splitpath << new_name
|
56
|
+
@path = splitpath.join("/")
|
57
|
+
@name = new_name
|
58
|
+
end
|
59
|
+
|
60
|
+
# Deletes all metadata including those created on the initial upload processing.
|
61
|
+
def DeleteAllMetadata
|
62
|
+
Transport.execute_command_post(APICommand.DeleteAllMetadata, [APIParam.new("path", @path)], @account_login)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Deletes all tags.
|
66
|
+
def DeleteAllTags
|
67
|
+
Transport.execute_command_post(APICommand.DeleteAllTags, [APIParam.new("path", @path)], @account_login)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Deletes one or more metadata entries based on the name of the metadata.
|
71
|
+
def DeleteMetadata(metadata_to_delete)
|
72
|
+
params = [APIParam.new("path", @path)]
|
73
|
+
metadata_to_delete.each do |metadata|
|
74
|
+
params << APIParam.new("metadata", metadata)
|
75
|
+
end
|
76
|
+
|
77
|
+
Transport.execute_command_post(APICommand.DeleteMetadata, params, @account_login)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Retrieve all of the metadata for the current path
|
81
|
+
def GetMetadata
|
82
|
+
params = [APIParam.new("path", @path)]
|
83
|
+
|
84
|
+
#get the metadata for the current path.
|
85
|
+
doc = Transport.execute_command_post(APICommand.GetMetadata, params, @account_login)
|
86
|
+
|
87
|
+
#if there is any metadata loop through
|
88
|
+
metadata = Array.new
|
89
|
+
if doc.root.elements["//Response/Metadata"]
|
90
|
+
doc.root.elements.each("//Response/Metadata") do |metadataxml|
|
91
|
+
#add to the array the type and value of each in the xml.
|
92
|
+
metadata << MetadataInfo.new(metadataxml.elements["Type"][0], metadataxml.elements["Value"][0])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
return metadata
|
97
|
+
end
|
98
|
+
|
99
|
+
# Retrieve all of the metadata for the current path
|
100
|
+
def GetTags
|
101
|
+
params = [APIParam.new("path", @path)]
|
102
|
+
|
103
|
+
#get the metadata for the current path.
|
104
|
+
doc = Transport.execute_command_post(APICommand.GetTags, params, @account_login)
|
105
|
+
|
106
|
+
#empty the existing metadata array
|
107
|
+
tags = Array.new
|
108
|
+
|
109
|
+
if doc.root.elements["//Tag"]
|
110
|
+
doc.root.elements.each("//Tag") do |tag|
|
111
|
+
#add to the array the type and value of each in the xml.
|
112
|
+
tags << tag.get_text.value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
return tags
|
117
|
+
end
|
118
|
+
|
119
|
+
# Sets one or more metadata items, pass the parameter as an array of Metadata objects.
|
120
|
+
def SetMetadata(metadata_info_items)
|
121
|
+
params = [APIParam.new("path", @path)]
|
122
|
+
|
123
|
+
metadata_info_items.each do |item|
|
124
|
+
params << APIParam.new("metadata", item.type + ":" + item.value)
|
125
|
+
end
|
126
|
+
|
127
|
+
Transport.execute_command_post(APICommand.SetMetadata, params, @account_login)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Sets one or more tags on a file.
|
131
|
+
def SetTags(tags)
|
132
|
+
params = [APIParam.new("path", @path)]
|
133
|
+
|
134
|
+
tags.each do |tag|
|
135
|
+
params << APIParam.new("tag", tag)
|
136
|
+
end
|
137
|
+
|
138
|
+
Transport.execute_command_post(APICommand.SetTags, params, @account_login)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Resizes an image to the specified height and width. If a filename or destination folder is specified a
|
142
|
+
# new file will be created. If a callbackURL is defined when the resize process is complete
|
143
|
+
# the URL will be called.
|
144
|
+
def ImageResize(width, height, new_filename = nil, destination_folder = nil, callback_url = nil)
|
145
|
+
path = @path
|
146
|
+
if !destination_folder.nil?
|
147
|
+
new_path = destination_folder
|
148
|
+
end
|
149
|
+
if !new_filename.nil?
|
150
|
+
new_path += new_filename
|
151
|
+
end
|
152
|
+
|
153
|
+
params = [APIParam.new("srcFilePath", @path),
|
154
|
+
APIParam.new("destFilePath", new_path),
|
155
|
+
APIParam.new("width", width.to_s),
|
156
|
+
APIParam.new("height", height.to_s)]
|
157
|
+
params << APIParam.new("callbackURL", callback_url) if !callback_url.nil?
|
158
|
+
|
159
|
+
Transport.execute_command(APICommands.ImageResize, params, @account_login)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Retrieves a Url to the current file.
|
163
|
+
def GetDownloadUrl
|
164
|
+
Utilities.GetDownloadUrl(@account_login, @path, true)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Downloads the current file to a local path.
|
168
|
+
def DownloadToLocalFile(local_path)
|
169
|
+
Transport.DownloadFile(@path, local_path, @account_login)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|