Class: NVX::SDS::NVXFile

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

Overview

Overview

The File object is used for all file operations. The object is initially retrieved by calling Session.GetRootFolder and retrieving the .Files array. This is loaded with loadchildren.

Usage

session = Session.new("APP-KEY", "USERNAME", "APP NAME", "PASSWORD")
root_folder = session.GetRootFolder(1, 500, 0, true)

root_folder.files.each do |file|
    print file.name
end

Instance Method Summary collapse

Methods inherited from ItemBase

#HostItem, #RemoveHostedItem, #created_date, #name, #path

Constructor Details

#initialize(account_login, fs_file_attributes) ⇒ NVXFile

initialize the file using the default file attributes from the listFolder method.



35
36
37
38
39
40
# File 'lib/nvx/sds/nvxfile.rb', line 35

def initialize(, fs_file_attributes)
    super(, fs_file_attributes)
    @account_login = 
    @fs_file_attributes = fs_file_attributes
    @size_bytes = fs_file_attributes.size_bytes
end

Instance Method Details

#DeleteAllMetadataObject

Deletes all metadata including those created on the initial upload processing.



61
62
63
# File 'lib/nvx/sds/nvxfile.rb', line 61

def DeleteAllMetadata
    Transport.execute_command_post(APICommand.DeleteAllMetadata, [APIParam.new("path", @path)], @account_login)
end

#DeleteAllTagsObject

Deletes all tags.



66
67
68
# File 'lib/nvx/sds/nvxfile.rb', line 66

def DeleteAllTags
    Transport.execute_command_post(APICommand.DeleteAllTags, [APIParam.new("path", @path)], @account_login)
end

#DeleteMetadata(metadata_to_delete) ⇒ Object

Deletes one or more metadata entries based on the name of the metadata.



71
72
73
74
75
76
77
78
# File 'lib/nvx/sds/nvxfile.rb', line 71

def DeleteMetadata()
    params = [APIParam.new("path", @path)]
    .each do ||
        params << APIParam.new("metadata", )
    end
    
    Transport.execute_command_post(APICommand.DeleteMetadata, params, @account_login)
end

#DownloadToLocalFile(local_path) ⇒ Object

Downloads the current file to a local path.



214
215
216
# File 'lib/nvx/sds/nvxfile.rb', line 214

def DownloadToLocalFile(local_path)
    Transport.DownloadFile(@path, local_path, @account_login)
end

Gets a public download link that will expire after expiration_seconds



199
200
201
202
203
204
205
206
# File 'lib/nvx/sds/nvxfile.rb', line 199

def GetDownloadLink(expiration_seconds, restricted_ip = nil)
    params = [APIParam.new("filePath", @path),
                APIParam.new("expiration", expiration_seconds.to_s)]
    params << APIParam.new("restricted_ip", restricted_ip) if !restricted_ip.nil?

    doc = Transport.execute_command_post(APICommand.GetDownloadLinks, params, @account_login)
    return doc.root.elements["//Response/Download/DownloadURL"].get_text.value
end

#GetDownloadUrlObject

Retrieves a Url to the current file.



209
210
211
# File 'lib/nvx/sds/nvxfile.rb', line 209

def GetDownloadUrl
    Utilities.GetDownloadUrl(@account_login, @path, true)
end

#GetMetadataObject

Retrieve all of the metadata for the current path



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nvx/sds/nvxfile.rb', line 81

def GetMetadata
    params = [APIParam.new("path", @path)]
    
    #get the metadata for the current path.
    doc = Transport.execute_command_post(APICommand.GetMetadata, params, @account_login)
    
    #if there is any metadata loop through
     = Array.new
    if doc.root.elements["//Response/Metadata"]
        doc.root.elements.each("//Response/Metadata") do |metadataxml|
            #add to the array the type and value of each in the xml.
             << MetadataInfo.new(metadataxml.elements["Type"][0], metadataxml.elements["Value"][0])
        end
    end
    
    return 
end

#GetTagsObject

Retrieve all of the metadata for the current path



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/nvx/sds/nvxfile.rb', line 100

def GetTags
    params = [APIParam.new("path", @path)]
    
    #get the metadata for the current path.
    doc = Transport.execute_command_post(APICommand.GetTags, params, @account_login)
    
    #empty the existing metadata array
    tags = Array.new

    if doc.root.elements["//Tag"]
        doc.root.elements.each("//Tag") do |tag|
            #add to the array the type and value of each in the xml.
            tags << tag.get_text.value
        end
    end

    return tags
end

#ImageResize(width, height, new_filename = nil, destination_folder = nil, callback_url = nil) ⇒ Object

Resizes an image to the specified height and width. If a filename or destination folder is specified a new file will be created. If a callbackURL is defined when the resize process is complete the URL will be called.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/nvx/sds/nvxfile.rb', line 144

def ImageResize(width, height, new_filename = nil, destination_folder = nil, callback_url = nil)
    path = @path
    new_path = ""
    if !destination_folder.nil?
        new_path = destination_folder
    end
    if !new_filename.nil?
        new_path += new_filename
    end
    
    params = [APIParam.new("srcFilePath", @path),
                APIParam.new("destFilePath", new_path),
                APIParam.new("width", width.to_s),
                APIParam.new("height", height.to_s)]
    params << APIParam.new("callbackURL", callback_url) if !callback_url.nil?
    
    Transport.execute_command_post(APICommand.ImageResize, params, @account_login)
end

#ImageRotateFlip(rotate = "RotateNone", flip = "FlipNone", new_filename = nil, destination_folder = nil, callback_url = nil) ⇒ Object

Rotates and/or flips an image file. If a filename or destination folder is specified a new file will be created. If a callbackURL is defined when the operation is complete the URL will be called.

Rotate Values:

  • RotateNone

  • Rotate90

  • Rotate180

  • Rotate270

Flip Values:

  • FlipNone

  • FlipHorizontal

  • FlipVertical

  • FlipHorizontalVertical



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/nvx/sds/nvxfile.rb', line 179

def ImageRotateFlip(rotate = "RotateNone", flip = "FlipNone", new_filename = nil, destination_folder = nil, callback_url = nil)
    path = @path
    new_path = ""
    if !destination_folder.nil?
        new_path = destination_folder
    end
    if !new_filename.nil?
        new_path += new_filename
    end
    
    params = [APIParam.new("srcFilePath", @path),
                APIParam.new("destFilePath", new_path),
                APIParam.new("rotate", rotate.to_s),
                APIParam.new("flip", flip.to_s)]
    params << APIParam.new("callbackURL", callback_url) if !callback_url.nil?
    
    Transport.execute_command_post(APICommand.ImageRotateFlip, params, @account_login)
end

#Rename(new_name) ⇒ Object

Pass the new filename to change the path.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nvx/sds/nvxfile.rb', line 48

def Rename(new_name)
    params = [APIParam.new("filePath", @path), APIParam.new("newFileName", new_name)]
    
    Transport.execute_command_post(APICommand.RenameFile, params, @account_login)
    
    splitpath = @path.to_s.split("/")
    splitpath.delete(splitpath.last)
    splitpath << new_name
    @path = splitpath.join("/")
    @name = new_name                
end

#SetMetadata(metadata_info_items) ⇒ Object

Sets one or more metadata items, pass the parameter as an array of Metadata objects.



120
121
122
123
124
125
126
127
128
# File 'lib/nvx/sds/nvxfile.rb', line 120

def SetMetadata()
    params = [APIParam.new("path", @path)]
    
    .each do |item|
        params << APIParam.new("metadata", item.type + ":" + item.value)
    end
    
    Transport.execute_command_post(APICommand.SetMetadata, params, @account_login)
end

#SetTags(tags) ⇒ Object

Sets one or more tags on a file.



131
132
133
134
135
136
137
138
139
# File 'lib/nvx/sds/nvxfile.rb', line 131

def SetTags(tags)
    params = [APIParam.new("path", @path)]
    
    tags.each do |tag|
        params << APIParam.new("tag", tag)
    end
    
    Transport.execute_command_post(APICommand.SetTags, params, @account_login)
end

#size_bytesObject

The file size in bytes.



43
44
45
# File 'lib/nvx/sds/nvxfile.rb', line 43

def size_bytes
    @size_bytes
end