Class: NVX::SDS::MasterAccount

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

Overview

Overview

The Master account lets you create children, modify children, Get and Set limits, adjust account notes and impersonate child accounts. Impersonation is available as a simple way to log into a child account if you do not know the child accounts password but you are the master account. This simplifies the administration of child accounts.

Instance Method Summary collapse

Constructor Details

#initialize(session, account_login) ⇒ MasterAccount

Sets the current session and account login objects.



18
19
20
21
# File 'lib/nvx/sds/masteraccount.rb', line 18

def initialize(session, )
    @account_login = 
    @session = session
end

Instance Method Details

#CreateChildAccount(username, password, first_name = nil, last_name = nil, middle_initial = nil, phone_number = nil, email_address = nil, email_format = nil, address_line1 = nil, address_line2 = nil, city = nil, state = nil, country = nil, postal_code = nil) ⇒ Object

Creates a new child account. The username and password are required fields. By default there are no limits on a child account.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nvx/sds/masteraccount.rb', line 25

def CreateChildAccount(username, password, first_name = nil, last_name = nil, 
    middle_initial = nil, phone_number = nil, email_address = nil, email_format = nil,
    address_line1 = nil, address_line2 = nil, city = nil, state = nil, country = nil, postal_code = nil)
   
    params = [APIParam.new("username", username), APIParam.new("password", password)]
    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("emailFormat", email_format) if !email_format.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("countryID", country) if !country.nil?
    params << APIParam.new("postalCode", postal_code) if !postal_code.nil?
    
    Transport.execute_command_post(APICommand.CreateChildAccount, params, @account_login)
end

#DeleteChildAccount(username) ⇒ Object

Removes a child account. **This will also remove ALL files/notes/account info the child previously had in their account.



48
49
50
# File 'lib/nvx/sds/masteraccount.rb', line 48

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

#GetAccountNotes(username) ⇒ Object

Gets the account notes in xml.



81
82
83
84
85
# File 'lib/nvx/sds/masteraccount.rb', line 81

def GetAccountNotes(username)
    doc = Transport.execute_command_post(APICommand.GetAccountNotes, [APIParam.new("username", username)], @account_login)
    
    return (text = doc.root.elements["//Response/GetAccountNotes"].get_text and text.value)
end

#ImpersonateChildAccount(username) ⇒ Object

This lets the master account get a session for a child account that they have previously created without knowing the password for that child account.



96
97
98
99
# File 'lib/nvx/sds/masteraccount.rb', line 96

def ImpersonateChildAccount(username)
    @session = Session.new(@account_login.app_key, username, @account_login.app_name, nil, @account_login.session_token)
    return @session
end

#ListChildAccounts(page_number = 1, page_size = 500) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/nvx/sds/masteraccount.rb', line 64

def ListChildAccounts(page_number = 1, page_size = 500)
    params = [APIParam.new("pageNumber", page_number),
                APIParam.new("pageSize", page_size)]
    doc = Transport.execute_command_post(APICommand.ListChildAccounts, params, @account_login)  

    child_accounts = Array.new

    #if there is any metadata loop through
    if doc.root.elements["//Response/Account"]
        doc.root.elements.each("//Response/Account") do ||
            child_accounts << .get_text.value
        end
    end
    return child_accounts                
end

#SetAccountNotes(username, xml_notes) ⇒ Object

Set the account notes. This method expects properly formated xml. Be sure to escape any invalid characters.



88
89
90
91
92
# File 'lib/nvx/sds/masteraccount.rb', line 88

def SetAccountNotes(username, xml_notes)
    params = [APIParam.new("username", username),
                APIParam.new("xmlNotes", xml_notes)]
    Transport.execute_command_post(APICommand.SetAccountNotes, params, @account_login)
end

#SetChildAccountPassword(master_password, child_username, new_password) ⇒ Object

Changes the child password. The master account needs to reauthenticate with the system to change a childs password.



54
55
56
57
58
59
60
61
62
# File 'lib/nvx/sds/masteraccount.rb', line 54

def SetChildAccountPassword(master_password, child_username, new_password)
    # The master account needs to reauthenticate with the system to change a childs password.
    params = [APIParam.new("username", @account_login.username), 
                APIParam.new("password", master_password),
                APIParam.new("appKey", @account_login.app_key),
                APIParam.new("childAccountUsername", child_username),
                APIParam.new("childAccountPassword", new_password)]
    Transport.execute_command_post(APICommand.SetChildAccountPassword, params, @account_login)
end