-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
68 lines (59 loc) · 2.22 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package foxyproxy
// Account represents a customer who can be assigned to one or more nodes (vpn/proxy servers).
// See https://reseller.api.foxyproxy.com/#_accounts.
type Account struct {
Active bool `json:"active"`
Node *Node `json:"node,omitempty"`
UID string `json:"uid"`
Username string `json:"username"`
client *Client
}
// NewAccount generates a new account object.
func NewAccount(c *Client) *Account {
return &Account{
client: c,
}
}
// GetNodeNames returns a slice of length 1 containing the account's node name.
// Returns an empty slice if node is nil.
func (a *Account) GetNodeNames() []string {
nodeNames := []string{}
if a.Node != nil {
nodeNames = append(nodeNames, a.Node.Name)
}
return nodeNames
}
// Deactivate deactivates the account on it's node and returns a count of affected accounts.
// See https://reseller.api.foxyproxy.com/#_deactivate_accounts.
func (a *Account) Deactivate() (int, error) {
return a.client.deactivateAccount(a.Username, &CommonProperties{
NodeNames: a.GetNodeNames(),
})
}
// Activate activates the account on it's node and returns a count of affected accounts.
// See https://reseller.api.foxyproxy.com/#_activate_accounts.
func (a *Account) Activate() (int, error) {
return a.client.activateAccount(a.Username, &CommonProperties{
NodeNames: a.GetNodeNames(),
})
}
// UpdatePassword updates the password on it's node and returns a count of affected accounts.
// See https://reseller.api.foxyproxy.com/#_update_passwords.
func (a *Account) UpdatePassword(password string) (int, error) {
return a.client.updatePassword(a.Username, password, &CommonProperties{
NodeNames: a.GetNodeNames(),
})
}
// DeleteAccountsParams is an object of optional account deletion parameters.
type DeleteAccountsParams struct {
IncludeHistory bool `json:"includeHistory"`
CommonProperties
}
// Delete deletes the account on it's node. If includeHistory is set to true, account history is
// also deleted on it's node. Returns a count of affected accounts.
// See https://reseller.api.foxyproxy.com/#_delete_accounts.
func (a *Account) Delete(includeHistory bool) (int, error) {
return a.client.deleteAccounts(a.Username, includeHistory, &CommonProperties{
NodeNames: a.GetNodeNames(),
})
}