Class: NVX::SDS::Utilities

Inherits:
Object
  • Object
show all
Defined in:
lib/nvx/sds/APIClasses/utilities.rb

Overview

The utilites class has several static methods for formatting and other routine operations such as getting download URLs and Getting and settign generic information that requires special formatting.

Class Method Summary collapse

Class Method Details

.GetAccountInfo(account_login, username) ⇒ Object

Returns the account information in an accountInfo object.



33
34
35
36
# File 'lib/nvx/sds/APIClasses/utilities.rb', line 33

def Utilities.GetAccountInfo(, username)
    doc = Transport.execute_command_post(APICommand.GetAccountInfo, [APIParam.new("username", username)], )
    return AccountInfo.new(doc)
end

.GetAccountLimits(account_login, username) ⇒ Object

Gets account limits extracting each limit and creating a new AccountLimit object to contain each.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nvx/sds/APIClasses/utilities.rb', line 39

def Utilities.GetAccountLimits(, username)
    doc = Transport.execute_command_post(APICommand.GetAccountLimits, [APIParam.new("username", username)], )
    
    accountlimits = Array.new

    #if there is any metadata loop through
    if doc.root.elements["//Response/Limits"]
        doc.root.elements.each("//Response/Limits") do |limit|
            #add to the array the type and value of each in the xml.
            accountlimits << AccountLimit.new(limit.elements["Type"][0].to_s, limit.elements["Value"][0].to_s)
        end
    end
    return accountlimits
end

.GetAccountUsage(account_login, username) ⇒ Object

Gets account usage extracting each usage type and creating a new AccountFeatureUsage object to contain each.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/nvx/sds/APIClasses/utilities.rb', line 55

def Utilities.GetAccountUsage(, username)
    doc = Transport.execute_command_post(APICommand.GetAccountUsage, [APIParam.new("username", username)], )
    
    features = Array.new

    #if there is any metadata loop through
    if doc.root.elements["//Response/GetUsage"]
        doc.root.elements.each("//Response/GetUsage") do |feature|
            features << AccountFeatureUsage.new(feature)
        end
    end

    return features
end

.GetDownloadUrl(account_login, path, include_session = true) ⇒ Object

Gets a download url for either hosted or session based downloads. This will output a url in the format of downloadnode.nirvanix.com/sessiontoken/appname/username/path/file.txt or downloadnode.nirvanix.com/appname/username/path/file.txt



22
23
24
25
26
27
28
29
30
# File 'lib/nvx/sds/APIClasses/utilities.rb', line 22

def Utilities.GetDownloadUrl(, path, include_session = true)
    doc = Transport.execute_command_post(APICommand.GetDownloadNodes, [APIParam.new("filePath", path)], )
    
    url = "http://" + doc.root.elements["//Response/DownloadNode"].get_text.value + "/"
    url += .session_token + "/" if include_session
    url += .app_name + "/" + .username + "/"
    url += path.to_s.split("/").last
    return url
end

.SetAccountInfo(account_login, username, first_name, last_name, middle_initial, phone_number, email_address, email_format, address_line1, address_line2, city, state, country, postal_code) ⇒ Object

Sets the account info for a child or parent.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/nvx/sds/APIClasses/utilities.rb', line 71

def Utilities.SetAccountInfo(, username, first_name, last_name, 
        middle_initial, phone_number, email_address, email_format, address_line1, address_line2, 
        city, state, country, postal_code)

    email_format = email_format.nil? ? "TEXT" : email_format
    country = country.nil? ? "1" : country
    
    params = Array.new
    params << APIParam.new("username", username)
    params << APIParam.new("emailFormat", email_format)
    params << APIParam.new("firstName", first_name) if !first_name.nil?
    params << APIParam.new("lastName", last_name) if !last_name.nil?
    params << APIParam.new("middleInitial", middle_initial) if !middle_initial.nil?
    params << APIParam.new("phoneNumber", phone_number) if !phone_number.nil?
    params << APIParam.new("emailAddress", email_address) if !email_address.nil?
    params << APIParam.new("addressLine1", address_line1) if !address_line1.nil?
    params << APIParam.new("addressLine2", address_line2) if !address_line2.nil?
    params << APIParam.new("city", city) if !city.nil?
    params << APIParam.new("state", state) if !state.nil?
    params << APIParam.new("country", country) if !country.nil?
    params << APIParam.new("postalCode", postal_code) if !postal_code.nil?
        
    Transport.execute_command_post(APICommand.SetAccountInfo, params, )
end