Skip to content
28 changes: 25 additions & 3 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

const (
domainsDNSGetHosts = "namecheap.domains.dns.getHosts"
domainsDNSSetHosts = "namecheap.domains.dns.setHosts"
domainsDNSSetCustom = "namecheap.domains.dns.setCustom"
domainsDNSGetHosts = "namecheap.domains.dns.getHosts"
domainsDNSSetHosts = "namecheap.domains.dns.setHosts"
domainsDNSSetCustom = "namecheap.domains.dns.setCustom"
domainsDNSSetDefault = "namecheap.domains.dns.setDefault"
)

type DomainDNSGetHostsResult struct {
Expand Down Expand Up @@ -99,3 +100,24 @@ func (client *Client) DomainDNSSetCustom(sld, tld, nameservers string) (*DomainD
}
return resp.DomainDNSSetCustom, nil
}

type DomainDNSSetDefaultResult struct {
Domain string `xml:"Domain,attr"`
Update bool `xml:"Updated,attr"`
}

func (client *Client) DomainDNSSetDefault(sld, tld string) (*DomainDNSSetDefaultResult, error) {
requestInfo := &ApiRequest{
command: domainsDNSSetDefault,
method: "POST",
params: url.Values{},
}
requestInfo.params.Set("SLD", sld)
requestInfo.params.Set("TLD", tld)

resp, err := client.do(requestInfo)
if err != nil {
return nil, err
}
return resp.DomainDNSSetDefault, nil
}
42 changes: 42 additions & 0 deletions dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,45 @@ func TestDomainsDNSSetCustom(t *testing.T) {
t.Errorf("DomainsDNSSetCustom returned %+v, want %+v", result, want)
}
}

func TestDomainsDNSSetDefault(t *testing.T) {
setup()
defer teardown()

respXML := `
<?xml version="1.0" encoding="UTF-8"?>
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors />
<RequestedCommand>namecheap.domains.dns.setDefault</RequestedCommand>
<CommandResponse Type="namecheap.domains.dns.setDefault">
<DomainDNSSetDefaultResult Domain="domain.com" Updated="true" />
</CommandResponse>
<Server>SERVER-NAME</Server>
<GMTTimeDifference>+5</GMTTimeDifference>
<ExecutionTime>32.76</ExecutionTime>
</ApiResponse>`

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
correctParams := fillDefaultParams(url.Values{})
correctParams.Set("Command", "namecheap.domains.dns.setDefault")
correctParams.Set("SLD", "domain")
correctParams.Set("TLD", "com")
testBody(t, r, correctParams)
testMethod(t, r, "POST")
fmt.Fprint(w, respXML)
})

result, err := client.DomainDNSSetDefault("domain", "com")
if err != nil {
t.Errorf("DomainDNSSetDefault returned error: %v", err)
}

want := &DomainDNSSetDefaultResult{
Domain: "domain.com",
Update: true,
}

if !reflect.DeepEqual(result, want) {
t.Errorf("DomainsDNSSetDefault returned %+v, want %+v", result, want)
}
}
114 changes: 105 additions & 9 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import (
)

const (
domainsGetList = "namecheap.domains.getList"
domainsGetInfo = "namecheap.domains.getInfo"
domainsCheck = "namecheap.domains.check"
domainsCreate = "namecheap.domains.create"
domainsTLDList = "namecheap.domains.getTldList"
domainsRenew = "namecheap.domains.renew"
domainsGetList = "namecheap.domains.getList"
domainsGetInfo = "namecheap.domains.getInfo"
domainsCheck = "namecheap.domains.check"
domainsCreate = "namecheap.domains.create"
domainsTLDList = "namecheap.domains.getTldList"
domainsRenew = "namecheap.domains.renew"
domainsReactivate = "namecheap.domains.reactivate"
domainsSetContacts = "namecheap.domains.setContacts"
domainsGetContacts = "namecheap.domains.getContacts"
)

// DomainGetListResult represents the data returned by 'domains.getList'
Expand Down Expand Up @@ -50,9 +53,10 @@ type DNSDetails struct {
}

type Whoisguard struct {
Enabled bool `xml:"Enabled,attr"`
ID int64 `xml:"ID"`
ExpiredDate string `xml:"ExpiredDate"`
EnabledString string `xml:"Enabled,attr"`
Enabled bool
ID int64 `xml:"ID"`
ExpiredDate string `xml:"ExpiredDate"`
}

type DomainCheckResult struct {
Expand Down Expand Up @@ -91,6 +95,40 @@ type DomainRenewResult struct {
ExpireDate string `xml:"DomainDetails>ExpiredDate"`
}

type DomainReactivateResult struct {
Name string `xml:"Domain,attr"`
Reactivated bool `xml:"IsSuccess,attr"`
ChargedAmount float64 `xml:"ChargedAmount,attr"`
OrderID int `xml:"OrderID,attr"`
TransactionID int `xml:"TransactionID,attr"`
}

type DomainSetContactsResult struct {
Name string `xml:"Domain,attr"`
ContactsChanged bool `xml:"IsSuccess,attr"`
}

type DomainGetContactsResult struct {
Domain string `xml:"Domain,attr"`
Registrant DomainContactDetail `xml:"Registrant"`
Tech DomainContactDetail `xml:"Tech"`
Admin DomainContactDetail `xml:"Admin"`
AuxBilling DomainContactDetail `xml:"AuxBilling"`
}

type DomainContactDetail struct {
FirstName string `xml:"FirstName"`
LastName string `xml:"LastName"`
Address1 string `xml:"Address1"`
Address2 string `xml:"Address2"`
City string `xml:"City"`
StateProvince string `xml:"StateProvince"`
PostalCode string `xml:"PostalCode"`
Country string `xml:"Country"`
Phone string `xml:"Phone"`
EmailAddress string `xml:"EmailAddress"`
}

type DomainCreateOption struct {
AddFreeWhoisguard bool
WGEnabled bool
Expand Down Expand Up @@ -126,6 +164,11 @@ func (client *Client) DomainGetInfo(domainName string) (*DomainInfo, error) {
return nil, err
}

switch strings.ToLower(resp.DomainInfo.Whoisguard.EnabledString) {
case "1", "true":
resp.DomainInfo.Whoisguard.Enabled = true
}

return resp.DomainInfo, nil
}

Expand Down Expand Up @@ -212,3 +255,56 @@ func (client *Client) DomainRenew(domainName string, years int) (*DomainRenewRes

return resp.DomainRenew, nil
}

func (client *Client) DomainReactivate(domainName string, years int) (*DomainReactivateResult, error) {
requestInfo := &ApiRequest{
command: domainsReactivate,
method: "POST",
params: url.Values{},
}
requestInfo.params.Set("DomainName", domainName)
requestInfo.params.Set("Years", strconv.Itoa(years))

resp, err := client.do(requestInfo)
if err != nil {
return nil, err
}

return resp.DomainReactivate, nil
}

func (client *Client) DomainSetContacts(domainName string, registrant *Registrant) (*DomainSetContactsResult, error) {
requestInfo := &ApiRequest{
command: domainsSetContacts,
method: "POST",
params: url.Values{},
}
requestInfo.params.Set("DomainName", domainName)

if err := registrant.addValues(requestInfo.params); err != nil {
return nil, err
}

resp, err := client.do(requestInfo)
if err != nil {
return nil, err
}

return resp.DomainSetContacts, nil
}

func (client *Client) DomainGetContacts(domainName string) (*DomainGetContactsResult, error) {
requestInfo := &ApiRequest{
command: domainsGetContacts,
method: "POST",
params: url.Values{},
}
requestInfo.params.Set("DomainName", domainName)

resp, err := client.do(requestInfo)
if err != nil {
return nil, err
}

return resp.DomainGetContacts, nil
}
Loading