forked from billputer/go-namecheap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whoisguard.go
105 lines (87 loc) · 2.53 KB
/
whoisguard.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package namecheap
import (
"errors"
"net/url"
"strconv"
)
const (
whoisguardGetList = "namecheap.whoisguard.getList"
whoisguardEnable = "namecheap.whoisguard.enable"
whoisguardDisable = "namecheap.whoisguard.disable"
whoisguardRenew = "namecheap.whoisguard.renew"
)
type WhoisguardGetListResult struct {
ID int64 `xml:"ID,attr"`
DomainName string `xml:"DomainName,attr"`
Created string `xml:"Created,attr"`
Expires string `xml:"Expires,attr"`
Status string `xml:"Status,attr"`
}
type whoisguardEnableResult struct {
Domain string `xml:"Domain,attr"`
IsSuccess bool `xml:"IsSuccess,attr"`
}
type whoisguardDisableResult struct {
Domain string `xml:"Domain,attr"`
IsSuccess bool `xml:"IsSuccess,attr"`
}
type WhoisguardRenewResult struct {
WhoisguardID int64 `xml:"WhoisguardId,attr"`
Renewed bool `xml:"Renew,attr"`
ChargedAmount float64 `xml:"ChargedAmount,attr"`
OrderID int `xml:"OrderId,attr"`
TransactionID int `xml:"TransactionId,attr"`
}
func (client *Client) WhoisguardGetList() ([]WhoisguardGetListResult, error) {
requestInfo := &ApiRequest{
command: whoisguardGetList,
method: "POST",
params: url.Values{},
}
resp, err := client.do(requestInfo)
if err != nil {
return nil, err
}
return resp.WhoisguardList, nil
}
func (client *Client) WhoisguardEnable(id int64, email string) error {
requestInfo := &ApiRequest{
command: whoisguardEnable,
method: "POST",
params: url.Values{},
}
requestInfo.params.Set("WhoisguardID", strconv.FormatInt(id, 10))
requestInfo.params.Set("ForwardedToEmail", email)
resp, err := client.do(requestInfo)
if err == nil && !resp.WhoisguardEnable.IsSuccess {
err = errors.New("IsSuccess was false")
}
return err
}
func (client *Client) WhoisguardDisable(id int64) error {
requestInfo := &ApiRequest{
command: whoisguardDisable,
method: "POST",
params: url.Values{},
}
requestInfo.params.Set("WhoisguardID", strconv.FormatInt(id, 10))
resp, err := client.do(requestInfo)
if err == nil && !resp.WhoisguardDisable.IsSuccess {
err = errors.New("IsSuccess was false")
}
return err
}
func (client *Client) WhoisguardRenew(id int64, years int) (*WhoisguardRenewResult, error) {
requestInfo := &ApiRequest{
command: whoisguardRenew,
method: "POST",
params: url.Values{},
}
requestInfo.params.Set("WhoisguardID", strconv.FormatInt(id, 10))
requestInfo.params.Set("Years", strconv.Itoa(years))
resp, err := client.do(requestInfo)
if err != nil {
return nil, err
}
return resp.WhoisguardRenew, nil
}