chore: migrate to nrdcg. (#779)

This commit is contained in:
Ludovic Fernandez 2019-02-04 22:43:10 +01:00 committed by GitHub
parent c4730a6ec3
commit 3019d10801
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 534 additions and 523 deletions

View file

@ -81,7 +81,7 @@ git push -u origin my-feature
|---------------------------|----------------|--------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------| |---------------------------|----------------|--------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| Acme DNS | `acmedns` | [documentation](https://github.com/joohoi/acme-dns#api) | [Go client](https://github.com/cpu/goacmedns) | | Acme DNS | `acmedns` | [documentation](https://github.com/joohoi/acme-dns#api) | [Go client](https://github.com/cpu/goacmedns) |
| Alibaba Cloud | `alidns` | [documentation](https://www.alibabacloud.com/help/doc-detail/42875.htm) | [Go client](https://github.com/aliyun/alibaba-cloud-sdk-go) | | Alibaba Cloud | `alidns` | [documentation](https://www.alibabacloud.com/help/doc-detail/42875.htm) | [Go client](https://github.com/aliyun/alibaba-cloud-sdk-go) |
| Aurora DNS | `auroradns` | [documentation](https://libcloud.readthedocs.io/en/latest/dns/drivers/auroradns.html#api-docs) | [Go client](https://github.com/edeckers/auroradnsclient) | | Aurora DNS | `auroradns` | [documentation](https://libcloud.readthedocs.io/en/latest/dns/drivers/auroradns.html#api-docs) | [Go client](https://github.com/nrdcg/auroradns) |
| Azure | `azure` | [documentation](https://docs.microsoft.com/en-us/go/azure/) | [Go client](https://github.com/Azure/azure-sdk-for-go) | | Azure | `azure` | [documentation](https://docs.microsoft.com/en-us/go/azure/) | [Go client](https://github.com/Azure/azure-sdk-for-go) |
| Bluecat | `bluecat` | ? | - | | Bluecat | `bluecat` | ? | - |
| Cloudflare | `cloudflare` | [documentation](https://api.cloudflare.com/) | [Go client](https://github.com/cloudflare/cloudflare-go) | | Cloudflare | `cloudflare` | [documentation](https://api.cloudflare.com/) | [Go client](https://github.com/cloudflare/cloudflare-go) |
@ -104,7 +104,7 @@ git push -u origin my-feature
| Go Daddy | `godaddy` | [documentation](https://developer.godaddy.com/doc/endpoint/domains) | - | | Go Daddy | `godaddy` | [documentation](https://developer.godaddy.com/doc/endpoint/domains) | - |
| hosting.de | `hostingde` | [documentation](https://www.hosting.de/api/#dns) | - | | hosting.de | `hostingde` | [documentation](https://www.hosting.de/api/#dns) | - |
| Internet Initiative Japan | `iij` | [documentation](http://manual.iij.jp/p2/pubapi/) | [Go client](https://github.com/iij/doapi) | | Internet Initiative Japan | `iij` | [documentation](http://manual.iij.jp/p2/pubapi/) | [Go client](https://github.com/iij/doapi) |
| INWX | `inwx` | [documentation](https://www.inwx.de/en/help/apidoc) | [Go client](https://github.com/smueller18/goinwx) | | INWX | `inwx` | [documentation](https://www.inwx.de/en/help/apidoc) | [Go client](https://github.com/nrdcg/goinwx) |
| Lightsail | `lightsail` | ? | [Go client](https://github.com/aws/aws-sdk-go/aws) | | Lightsail | `lightsail` | ? | [Go client](https://github.com/aws/aws-sdk-go/aws) |
| Linode (deprecated) | `linode` | [documentation](https://www.linode.com/api/dns) | [Go client](https://github.com/timewasted/linode) | | Linode (deprecated) | `linode` | [documentation](https://www.linode.com/api/dns) | [Go client](https://github.com/timewasted/linode) |
| Linodev4 | `linodev4` | [documentation](https://developers.linode.com/api/v4) | [Go client](https://github.com/linode/linodego) | | Linodev4 | `linodev4` | [documentation](https://developers.linode.com/api/v4) | [Go client](https://github.com/linode/linodego) |

36
Gopkg.lock generated
View file

@ -281,14 +281,6 @@
pruneopts = "NUT" pruneopts = "NUT"
revision = "16bdd962781df9696f40cc2bab924f1a855a7f89" revision = "16bdd962781df9696f40cc2bab924f1a855a7f89"
[[projects]]
digest = "1:417193ba917954c4837c6fc48c6ac241b3fefd13fc0889367b4a7e43b69d582c"
name = "github.com/ldez/go-auroradns"
packages = ["."]
pruneopts = "NUT"
revision = "b40dfcae7c417f8129579362695dc1f3cfe5928d"
version = "v2.0.0"
[[projects]] [[projects]]
digest = "1:111ff5a09a32895248270bfaef9b8b6ac163a8cde9cdd603fed64b3e4b59e8ab" digest = "1:111ff5a09a32895248270bfaef9b8b6ac163a8cde9cdd603fed64b3e4b59e8ab"
name = "github.com/linode/linodego" name = "github.com/linode/linodego"
@ -345,6 +337,22 @@
pruneopts = "NUT" pruneopts = "NUT"
revision = "08470befbe04613bd4b44cb6978b05d50294c4d4" revision = "08470befbe04613bd4b44cb6978b05d50294c4d4"
[[projects]]
digest = "1:417193ba917954c4837c6fc48c6ac241b3fefd13fc0889367b4a7e43b69d582c"
name = "github.com/nrdcg/auroradns"
packages = ["."]
pruneopts = "NUT"
revision = "750ca8603f9f2cca2457acb22ea6e44d3f05358c"
version = "v1.0.0"
[[projects]]
digest = "1:78bc7967454f8c2a1257b3fe4ed1d57227fb1dff46fd74d38b91bd0d0cc2620a"
name = "github.com/nrdcg/goinwx"
packages = ["."]
pruneopts = "NUT"
revision = "d8152159450570012552f924a0ae6ab3d8c617e0"
version = "v0.6.0"
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:02584222c11b07d1d61cd76cc73e78cbc72810384a7ea69c543246d60d3335f7" digest = "1:02584222c11b07d1d61cd76cc73e78cbc72810384a7ea69c543246d60d3335f7"
@ -406,14 +414,6 @@
revision = "3e01752db0189b9157070a0e1668a620f9a85da2" revision = "3e01752db0189b9157070a0e1668a620f9a85da2"
version = "v1.0.6" version = "v1.0.6"
[[projects]]
branch = "master"
digest = "1:94fcec8ba983a96bb3f123ab9690955baf44d6d32de342f95f5a2f665c70457a"
name = "github.com/smueller18/goinwx"
packages = ["."]
pruneopts = "NUT"
revision = "5d138389109eca96463f44f692408f0d1c731278"
[[projects]] [[projects]]
digest = "1:60a46e2410edbf02b419f833372dd1d24d7aa1b916a990a7370e792fada1eadd" digest = "1:60a46e2410edbf02b419f833372dd1d24d7aa1b916a990a7370e792fada1eadd"
name = "github.com/stretchr/objx" name = "github.com/stretchr/objx"
@ -656,15 +656,15 @@
"github.com/exoscale/egoscale", "github.com/exoscale/egoscale",
"github.com/iij/doapi", "github.com/iij/doapi",
"github.com/iij/doapi/protocol", "github.com/iij/doapi/protocol",
"github.com/ldez/go-auroradns",
"github.com/linode/linodego", "github.com/linode/linodego",
"github.com/miekg/dns", "github.com/miekg/dns",
"github.com/namedotcom/go/namecom", "github.com/namedotcom/go/namecom",
"github.com/nrdcg/auroradns",
"github.com/nrdcg/goinwx",
"github.com/ovh/go-ovh/ovh", "github.com/ovh/go-ovh/ovh",
"github.com/rainycape/memcache", "github.com/rainycape/memcache",
"github.com/sacloud/libsacloud/api", "github.com/sacloud/libsacloud/api",
"github.com/sacloud/libsacloud/sacloud", "github.com/sacloud/libsacloud/sacloud",
"github.com/smueller18/goinwx",
"github.com/stretchr/testify/assert", "github.com/stretchr/testify/assert",
"github.com/stretchr/testify/mock", "github.com/stretchr/testify/mock",
"github.com/stretchr/testify/require", "github.com/stretchr/testify/require",

View file

@ -54,8 +54,8 @@
name = "github.com/timewasted/linode" name = "github.com/timewasted/linode"
[[constraint]] [[constraint]]
branch = "master" version = "0.6.0"
name = "github.com/smueller18/goinwx" name = "github.com/nrdcg/goinwx"
[[constraint]] [[constraint]]
version = "0.5.1" version = "0.5.1"

View file

@ -7,7 +7,7 @@ import (
"sync" "sync"
"time" "time"
auroradns "github.com/ldez/go-auroradns" "github.com/nrdcg/auroradns"
"github.com/xenolf/lego/challenge/dns01" "github.com/xenolf/lego/challenge/dns01"
"github.com/xenolf/lego/platform/config/env" "github.com/xenolf/lego/platform/config/env"
) )

View file

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/smueller18/goinwx" "github.com/nrdcg/goinwx"
"github.com/xenolf/lego/challenge/dns01" "github.com/xenolf/lego/challenge/dns01"
"github.com/xenolf/lego/log" "github.com/xenolf/lego/log"
"github.com/xenolf/lego/platform/config/env" "github.com/xenolf/lego/platform/config/env"
@ -99,7 +99,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
Name: dns01.UnFqdn(fqdn), Name: dns01.UnFqdn(fqdn),
Type: "TXT", Type: "TXT",
Content: value, Content: value,
Ttl: d.config.TTL, TTL: d.config.TTL,
} }
_, err = d.client.Nameservers.CreateRecord(request) _, err = d.client.Nameservers.CreateRecord(request)
@ -150,7 +150,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
var lastErr error var lastErr error
for _, record := range response.Records { for _, record := range response.Records {
err = d.client.Nameservers.DeleteRecord(record.Id) err = d.client.Nameservers.DeleteRecord(record.ID)
if err != nil { if err != nil {
lastErr = fmt.Errorf("inwx: %v", err) lastErr = fmt.Errorf("inwx: %v", err)
} }

View file

@ -7,44 +7,38 @@ const (
methodAccountUnlock = "account.unlock" methodAccountUnlock = "account.unlock"
) )
type AccountService interface { // AccountService API access to Account.
Login() error type AccountService service
Logout() error
Lock() error
Unlock(tan string) error
}
type AccountServiceOp struct { // Login Account login.
client *Client func (s *AccountService) Login() error {
}
var _ AccountService = &AccountServiceOp{}
func (s *AccountServiceOp) Login() error {
req := s.client.NewRequest(methodAccountLogin, map[string]interface{}{ req := s.client.NewRequest(methodAccountLogin, map[string]interface{}{
"user": s.client.Username, "user": s.client.username,
"pass": s.client.Password, "pass": s.client.password,
}) })
_, err := s.client.Do(*req) _, err := s.client.Do(*req)
return err return err
} }
func (s *AccountServiceOp) Logout() error { // Logout Account logout.
func (s *AccountService) Logout() error {
req := s.client.NewRequest(methodAccountLogout, nil) req := s.client.NewRequest(methodAccountLogout, nil)
_, err := s.client.Do(*req) _, err := s.client.Do(*req)
return err return err
} }
func (s *AccountServiceOp) Lock() error { // Lock Account lock.
func (s *AccountService) Lock() error {
req := s.client.NewRequest(methodAccountLock, nil) req := s.client.NewRequest(methodAccountLock, nil)
_, err := s.client.Do(*req) _, err := s.client.Do(*req)
return err return err
} }
func (s *AccountServiceOp) Unlock(tan string) error { // Unlock Account unlock.
func (s *AccountService) Unlock(tan string) error {
req := s.client.NewRequest(methodAccountUnlock, map[string]interface{}{ req := s.client.NewRequest(methodAccountUnlock, map[string]interface{}{
"tan": tan, "tan": tan,
}) })

View file

@ -13,64 +13,11 @@ const (
methodContactUpdate = "contact.update" methodContactUpdate = "contact.update"
) )
type ContactService interface { // ContactService API access to Contact.
Create(*ContactCreateRequest) (int, error) type ContactService service
Update(*ContactUpdateRequest) error
Delete(int) error
Info(int) (*ContactInfoResponse, error)
List(string) (*ContactListResponse, error)
}
type ContactServiceOp struct { // Create Creates a contact.
client *Client func (s *ContactService) Create(request *ContactCreateRequest) (int, error) {
}
var _ ContactService = &ContactServiceOp{}
type ContactCreateRequest struct {
Type string `structs:"type"`
Name string `structs:"name"`
Org string `structs:"org,omitempty"`
Street string `structs:"street"`
City string `structs:"city"`
PostalCode string `structs:"pc"`
StateProvince string `structs:"sp,omitempty"`
CountryCode string `structs:"cc"`
Voice string `structs:"voice"`
Fax string `structs:"fax,omitempty"`
Email string `structs:"email"`
Remarks string `structs:"remarks,omitempty"`
Protection bool `structs:"protection,omitempty"`
Testing bool `structs:"testing,omitempty"`
}
type ContactUpdateRequest struct {
Id int `structs:"id"`
Name string `structs:"name,omitempty"`
Org string `structs:"org,omitempty"`
Street string `structs:"street,omitempty"`
City string `structs:"city,omitempty"`
PostalCode string `structs:"pc,omitempty"`
StateProvince string `structs:"sp,omitempty"`
CountryCode string `structs:"cc,omitempty"`
Voice string `structs:"voice,omitempty"`
Fax string `structs:"fax,omitempty"`
Email string `structs:"email,omitempty"`
Remarks string `structs:"remarks,omitempty"`
Protection bool `structs:"protection,omitempty"`
Testing bool `structs:"testing,omitempty"`
}
type ContactInfoResponse struct {
Contact Contact `mapstructure:"contact"`
}
type ContactListResponse struct {
Count int
Contacts []Contact `mapstructure:"contact"`
}
func (s *ContactServiceOp) Create(request *ContactCreateRequest) (int, error) {
req := s.client.NewRequest(methodContactCreate, structs.Map(request)) req := s.client.NewRequest(methodContactCreate, structs.Map(request))
resp, err := s.client.Do(*req) resp, err := s.client.Do(*req)
@ -87,28 +34,31 @@ func (s *ContactServiceOp) Create(request *ContactCreateRequest) (int, error) {
return result["id"], nil return result["id"], nil
} }
func (s *ContactServiceOp) Delete(roId int) error { // Delete Deletes a contact.
func (s *ContactService) Delete(roID int) error {
req := s.client.NewRequest(methodContactDelete, map[string]interface{}{ req := s.client.NewRequest(methodContactDelete, map[string]interface{}{
"id": roId, "id": roID,
}) })
_, err := s.client.Do(*req) _, err := s.client.Do(*req)
return err return err
} }
func (s *ContactServiceOp) Update(request *ContactUpdateRequest) error { // Update Updates a contact.
func (s *ContactService) Update(request *ContactUpdateRequest) error {
req := s.client.NewRequest(methodContactUpdate, structs.Map(request)) req := s.client.NewRequest(methodContactUpdate, structs.Map(request))
_, err := s.client.Do(*req) _, err := s.client.Do(*req)
return err return err
} }
func (s *ContactServiceOp) Info(contactId int) (*ContactInfoResponse, error) { // Info Get information about a contact.
func (s *ContactService) Info(contactID int) (*ContactInfoResponse, error) {
var requestMap = make(map[string]interface{}) var requestMap = make(map[string]interface{})
requestMap["wide"] = 1 requestMap["wide"] = 1
if contactId != 0 { if contactID != 0 {
requestMap["id"] = contactId requestMap["id"] = contactID
} }
req := s.client.NewRequest(methodContactInfo, requestMap) req := s.client.NewRequest(methodContactInfo, requestMap)
@ -127,7 +77,8 @@ func (s *ContactServiceOp) Info(contactId int) (*ContactInfoResponse, error) {
return &result, nil return &result, nil
} }
func (s *ContactServiceOp) List(search string) (*ContactListResponse, error) { // List Search contacts.
func (s *ContactService) List(search string) (*ContactListResponse, error) {
var requestMap = make(map[string]interface{}) var requestMap = make(map[string]interface{})
if search != "" { if search != "" {
@ -148,3 +99,50 @@ func (s *ContactServiceOp) List(search string) (*ContactListResponse, error) {
return &result, nil return &result, nil
} }
// ContactCreateRequest API model.
type ContactCreateRequest struct {
Type string `structs:"type"`
Name string `structs:"name"`
Org string `structs:"org,omitempty"`
Street string `structs:"street"`
City string `structs:"city"`
PostalCode string `structs:"pc"`
StateProvince string `structs:"sp,omitempty"`
CountryCode string `structs:"cc"`
Voice string `structs:"voice"`
Fax string `structs:"fax,omitempty"`
Email string `structs:"email"`
Remarks string `structs:"remarks,omitempty"`
Protection bool `structs:"protection,omitempty"`
Testing bool `structs:"testing,omitempty"`
}
// ContactUpdateRequest API model.
type ContactUpdateRequest struct {
ID int `structs:"id"`
Name string `structs:"name,omitempty"`
Org string `structs:"org,omitempty"`
Street string `structs:"street,omitempty"`
City string `structs:"city,omitempty"`
PostalCode string `structs:"pc,omitempty"`
StateProvince string `structs:"sp,omitempty"`
CountryCode string `structs:"cc,omitempty"`
Voice string `structs:"voice,omitempty"`
Fax string `structs:"fax,omitempty"`
Email string `structs:"email,omitempty"`
Remarks string `structs:"remarks,omitempty"`
Protection bool `structs:"protection,omitempty"`
Testing bool `structs:"testing,omitempty"`
}
// ContactInfoResponse API model.
type ContactInfoResponse struct {
Contact Contact `mapstructure:"contact"`
}
// ContactListResponse API model.
type ContactListResponse struct {
Count int
Contacts []Contact `mapstructure:"contact"`
}

View file

@ -29,25 +29,154 @@ const (
methodDomainWhois = "domain.whois" methodDomainWhois = "domain.whois"
) )
type DomainService interface { // DomainService API access to Domain.
Check(domains []string) ([]DomainCheckResponse, error) type DomainService service
Register(request *DomainRegisterRequest) (*DomainRegisterResponse, error)
Delete(domain string, scheduledDate time.Time) error // Check Checks domains.
Info(domain string, roId int) (*DomainInfoResponse, error) func (s *DomainService) Check(domains []string) ([]DomainCheckResponse, error) {
GetPrices(tlds []string) ([]DomainPriceResponse, error) req := s.client.NewRequest(methodDomainCheck, map[string]interface{}{
List(*DomainListRequest) (*DomainList, error) "domain": domains,
Whois(domain string) (string, error) "wide": "2",
})
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
} }
type DomainServiceOp struct { root := new(domainCheckResponseRoot)
client *Client err = mapstructure.Decode(*resp, &root)
if err != nil {
return nil, err
} }
var _ DomainService = &DomainServiceOp{} return root.Domains, nil
}
// GetPrices Gets TLDS prices.
func (s *DomainService) GetPrices(tlds []string) ([]DomainPriceResponse, error) {
req := s.client.NewRequest(methodDomainGetPrices, map[string]interface{}{
"tld": tlds,
"vat": false,
})
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
root := new(domainPriceResponseRoot)
err = mapstructure.Decode(*resp, &root)
if err != nil {
return nil, err
}
return root.Prices, nil
}
// Register Register a domain.
func (s *DomainService) Register(request *DomainRegisterRequest) (*DomainRegisterResponse, error) {
req := s.client.NewRequest(methodDomainCreate, structs.Map(request))
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
var result DomainRegisterResponse
err = mapstructure.Decode(*resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// Delete Deletes a domain.
func (s *DomainService) Delete(domain string, scheduledDate time.Time) error {
req := s.client.NewRequest(methodDomainDelete, map[string]interface{}{
"domain": domain,
"scDate": scheduledDate.Format(time.RFC3339),
})
_, err := s.client.Do(*req)
return err
}
// Info Gets information about a domain.
func (s *DomainService) Info(domain string, roID int) (*DomainInfoResponse, error) {
req := s.client.NewRequest(methodDomainInfo, map[string]interface{}{
"domain": domain,
"wide": "2",
})
if roID != 0 {
req.Args["roId"] = roID
}
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
var result DomainInfoResponse
err = mapstructure.Decode(*resp, &result)
if err != nil {
return nil, err
}
fmt.Println("Response", result)
return &result, nil
}
// List List domains.
func (s *DomainService) List(request *DomainListRequest) (*DomainList, error) {
if request == nil {
return nil, errors.New("request can't be nil")
}
requestMap := structs.Map(request)
requestMap["wide"] = "2"
req := s.client.NewRequest(methodDomainList, requestMap)
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
var result DomainList
err = mapstructure.Decode(*resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// Whois Whois about a domains.
func (s *DomainService) Whois(domain string) (string, error) {
req := s.client.NewRequest(methodDomainWhois, map[string]interface{}{
"domain": domain,
})
resp, err := s.client.Do(*req)
if err != nil {
return "", err
}
var result map[string]string
err = mapstructure.Decode(*resp, &result)
if err != nil {
return "", err
}
return result["whois"], nil
}
type domainCheckResponseRoot struct { type domainCheckResponseRoot struct {
Domains []DomainCheckResponse `mapstructure:"domain"` Domains []DomainCheckResponse `mapstructure:"domain"`
} }
// DomainCheckResponse API model.
type DomainCheckResponse struct { type DomainCheckResponse struct {
Available int `mapstructure:"avail"` Available int `mapstructure:"avail"`
Status string `mapstructure:"status"` Status string `mapstructure:"status"`
@ -62,6 +191,8 @@ type DomainCheckResponse struct {
type domainPriceResponseRoot struct { type domainPriceResponseRoot struct {
Prices []DomainPriceResponse `mapstructure:"price"` Prices []DomainPriceResponse `mapstructure:"price"`
} }
// DomainPriceResponse API model.
type DomainPriceResponse struct { type DomainPriceResponse struct {
Tld string `mapstructure:"tld"` Tld string `mapstructure:"tld"`
Currency string `mapstructure:"currency"` Currency string `mapstructure:"currency"`
@ -80,6 +211,7 @@ type DomainPriceResponse struct {
TradePeriod int `mapstructure:"tradePeriod"` TradePeriod int `mapstructure:"tradePeriod"`
} }
// DomainRegisterRequest API model.
type DomainRegisterRequest struct { type DomainRegisterRequest struct {
Domain string `structs:"domain"` Domain string `structs:"domain"`
Period string `structs:"period,omitempty"` Period string `structs:"period,omitempty"`
@ -91,7 +223,7 @@ type DomainRegisterRequest struct {
TransferLock string `structs:"transferLock,omitempty"` TransferLock string `structs:"transferLock,omitempty"`
RenewalMode string `structs:"renewalMode,omitempty"` RenewalMode string `structs:"renewalMode,omitempty"`
WhoisProvider string `structs:"whoisProvider,omitempty"` WhoisProvider string `structs:"whoisProvider,omitempty"`
WhoisUrl string `structs:"whoisUrl,omitempty"` WhoisURL string `structs:"whoisUrl,omitempty"`
ScDate string `structs:"scDate,omitempty"` ScDate string `structs:"scDate,omitempty"`
ExtDate string `structs:"extDate,omitempty"` ExtDate string `structs:"extDate,omitempty"`
Asynchron string `structs:"asynchron,omitempty"` Asynchron string `structs:"asynchron,omitempty"`
@ -99,14 +231,16 @@ type DomainRegisterRequest struct {
Testing string `structs:"testing,omitempty"` Testing string `structs:"testing,omitempty"`
} }
// DomainRegisterResponse API model.
type DomainRegisterResponse struct { type DomainRegisterResponse struct {
RoId int RoID int `mapstructure:"roId"`
Price float32 Price float32 `mapstructure:"price"`
Currency string Currency string `mapstructure:"currency"`
} }
// DomainInfoResponse API model.
type DomainInfoResponse struct { type DomainInfoResponse struct {
RoId int `mapstructure:"roId"` RoID int `mapstructure:"roId"`
Domain string `mapstructure:"domain"` Domain string `mapstructure:"domain"`
DomainAce string `mapstructure:"domainAce"` DomainAce string `mapstructure:"domainAce"`
Period string `mapstructure:"period"` Period string `mapstructure:"period"`
@ -129,27 +263,29 @@ type DomainInfoResponse struct {
Contacts map[string]Contact `mapstructure:"contact"` Contacts map[string]Contact `mapstructure:"contact"`
} }
// Contact API model.
type Contact struct { type Contact struct {
RoId int RoID int `mapstructure:"roId"`
Id string ID string `mapstructure:"id"`
Type string Type string `mapstructure:"type"`
Name string Name string `mapstructure:"name"`
Org string Org string `mapstructure:"org"`
Street string Street string `mapstructure:"street"`
City string City string `mapstructure:"city"`
PostalCode string `mapstructure:"pc"` PostalCode string `mapstructure:"pc"`
StateProvince string `mapstructure:"sp"` StateProvince string `mapstructure:"sp"`
Country string `mapstructure:"cc"` Country string `mapstructure:"cc"`
Phone string `mapstructure:"voice"` Phone string `mapstructure:"voice"`
Fax string Fax string `mapstructure:"fax"`
Email string Email string `mapstructure:"email"`
Remarks string Remarks string `mapstructure:"remarks"`
Protection string Protection string `mapstructure:"protection"`
} }
// DomainListRequest API model.
type DomainListRequest struct { type DomainListRequest struct {
Domain string `structs:"domain,omitempty"` Domain string `structs:"domain,omitempty"`
RoId int `structs:"roId,omitempty"` RoID int `structs:"roId,omitempty"`
Status int `structs:"status,omitempty"` Status int `structs:"status,omitempty"`
Registrant int `structs:"registrant,omitempty"` Registrant int `structs:"registrant,omitempty"`
Admin int `structs:"admin,omitempty"` Admin int `structs:"admin,omitempty"`
@ -161,143 +297,11 @@ type DomainListRequest struct {
Tag int `structs:"tag,omitempty"` Tag int `structs:"tag,omitempty"`
Order int `structs:"order,omitempty"` Order int `structs:"order,omitempty"`
Page int `structs:"page,omitempty"` Page int `structs:"page,omitempty"`
Pagelimit int `structs:"pagelimit,omitempty"` PageLimit int `structs:"pagelimit,omitempty"`
} }
// DomainList API model.
type DomainList struct { type DomainList struct {
Count int Count int
Domains []DomainInfoResponse `mapstructure:"domain"` Domains []DomainInfoResponse `mapstructure:"domain"`
} }
func (s *DomainServiceOp) Check(domains []string) ([]DomainCheckResponse, error) {
req := s.client.NewRequest(methodDomainCheck, map[string]interface{}{
"domain": domains,
"wide": "2",
})
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
root := new(domainCheckResponseRoot)
err = mapstructure.Decode(*resp, &root)
if err != nil {
return nil, err
}
return root.Domains, nil
}
func (s *DomainServiceOp) GetPrices(tlds []string) ([]DomainPriceResponse, error) {
req := s.client.NewRequest(methodDomainGetPrices, map[string]interface{}{
"tld": tlds,
"vat": false,
})
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
root := new(domainPriceResponseRoot)
err = mapstructure.Decode(*resp, &root)
if err != nil {
return nil, err
}
return root.Prices, nil
}
func (s *DomainServiceOp) Register(request *DomainRegisterRequest) (*DomainRegisterResponse, error) {
req := s.client.NewRequest(methodDomainCreate, structs.Map(request))
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
var result DomainRegisterResponse
err = mapstructure.Decode(*resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
func (s *DomainServiceOp) Delete(domain string, scheduledDate time.Time) error {
req := s.client.NewRequest(methodDomainDelete, map[string]interface{}{
"domain": domain,
"scDate": scheduledDate.Format(time.RFC3339),
})
_, err := s.client.Do(*req)
return err
}
func (s *DomainServiceOp) Info(domain string, roId int) (*DomainInfoResponse, error) {
req := s.client.NewRequest(methodDomainInfo, map[string]interface{}{
"domain": domain,
"wide": "2",
})
if roId != 0 {
req.Args["roId"] = roId
}
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
var result DomainInfoResponse
err = mapstructure.Decode(*resp, &result)
if err != nil {
return nil, err
}
fmt.Println("Response", result)
return &result, nil
}
func (s *DomainServiceOp) List(request *DomainListRequest) (*DomainList, error) {
if request == nil {
return nil, errors.New("Request can't be nil")
}
requestMap := structs.Map(request)
requestMap["wide"] = "2"
req := s.client.NewRequest(methodDomainList, requestMap)
resp, err := s.client.Do(*req)
if err != nil {
return nil, err
}
var result DomainList
err = mapstructure.Decode(*resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
func (s *DomainServiceOp) Whois(domain string) (string, error) {
req := s.client.NewRequest(methodDomainWhois, map[string]interface{}{
"domain": domain,
})
resp, err := s.client.Do(*req)
if err != nil {
return "", err
}
var result map[string]string
err = mapstructure.Decode(*resp, &result)
if err != nil {
return "", err
}
return result["whois"], nil
}

112
vendor/github.com/nrdcg/goinwx/goinwx.go generated vendored Normal file
View file

@ -0,0 +1,112 @@
package goinwx
import (
"net/url"
"github.com/kolo/xmlrpc"
)
// API information.
const (
APIBaseURL = "https://api.domrobot.com/xmlrpc/"
APISandboxBaseURL = "https://api.ote.domrobot.com/xmlrpc/"
APILanguage = "eng"
)
// Client manages communication with INWX API.
type Client struct {
// HTTP client used to communicate with the INWX API.
RPCClient *xmlrpc.Client
// Base URL for API requests.
BaseURL *url.URL
// API username and password
username string
password string
common service // Reuse a single struct instead of allocating one for each service on the heap.
// Services used for communicating with the API
Account *AccountService
Domains *DomainService
Nameservers *NameserverService
Contacts *ContactService
}
type service struct {
client *Client
}
// ClientOptions Options of the API client.
type ClientOptions struct {
Sandbox bool
}
// Request The representation of an API request.
type Request struct {
ServiceMethod string
Args map[string]interface{}
}
// NewClient returns a new INWX API client.
func NewClient(username, password string, opts *ClientOptions) *Client {
var useSandbox bool
if opts != nil {
useSandbox = opts.Sandbox
}
var baseURL *url.URL
if useSandbox {
baseURL, _ = url.Parse(APISandboxBaseURL)
} else {
baseURL, _ = url.Parse(APIBaseURL)
}
rpcClient, _ := xmlrpc.NewClient(baseURL.String(), nil)
client := &Client{
RPCClient: rpcClient,
BaseURL: baseURL,
username: username,
password: password,
}
client.common.client = client
client.Account = (*AccountService)(&client.common)
client.Domains = (*DomainService)(&client.common)
client.Nameservers = (*NameserverService)(&client.common)
client.Contacts = (*ContactService)(&client.common)
return client
}
// NewRequest creates an API request.
func (c *Client) NewRequest(serviceMethod string, args map[string]interface{}) *Request {
if args != nil {
args["lang"] = APILanguage
}
return &Request{ServiceMethod: serviceMethod, Args: args}
}
// Do sends an API request and returns the API response.
func (c *Client) Do(req Request) (*map[string]interface{}, error) {
var resp Response
err := c.RPCClient.Call(req.ServiceMethod, req.Args, &resp)
if err != nil {
return nil, err
}
return &resp.ResponseData, checkResponse(&resp)
}
// checkResponse checks the API response for errors, and returns them if present.
func checkResponse(r *Response) error {
if c := r.Code; c >= 1000 && c <= 1500 {
return nil
}
return &ErrorResponse{Code: r.Code, Message: r.Message, Reason: r.Reason, ReasonCode: r.ReasonCode}
}

View file

@ -21,114 +21,11 @@ const (
methodNameserverUpdateRecord = "nameserver.updateRecord" methodNameserverUpdateRecord = "nameserver.updateRecord"
) )
type NameserverService interface { // NameserverService API access to Nameservers.
Check(domain string, nameservers []string) (*NameserverCheckResponse, error) type NameserverService service
Create(*NameserverCreateRequest) (int, error)
Info(*NameserverInfoRequest) (*NamserverInfoResponse, error)
List(domain string) (*NamserverListResponse, error)
CreateRecord(*NameserverRecordRequest) (int, error)
UpdateRecord(recId int, request *NameserverRecordRequest) error
DeleteRecord(recId int) error
FindRecordById(recId int) (*NameserverRecord, *NameserverDomain, error)
}
type NameserverServiceOp struct { // Check Checks a domain on nameservers.
client *Client func (s *NameserverService) Check(domain string, nameservers []string) (*NameserverCheckResponse, error) {
}
var _ NameserverService = &NameserverServiceOp{}
type NameserverCheckResponse struct {
Details []string
Status string
}
type NameserverRecordRequest struct {
RoId int `structs:"roId,omitempty"`
Domain string `structs:"domain,omitempty"`
Type string `structs:"type"`
Content string `structs:"content"`
Name string `structs:"name,omitempty"`
Ttl int `structs:"ttl,omitempty"`
Priority int `structs:"prio,omitempty"`
UrlRedirectType string `structs:"urlRedirectType,omitempty"`
UrlRedirectTitle string `structs:"urlRedirectTitle,omitempty"`
UrlRedirectDescription string `structs:"urlRedirectDescription,omitempty"`
UrlRedirectFavIcon string `structs:"urlRedirectFavIcon,omitempty"`
UrlRedirectKeywords string `structs:"urlRedirectKeywords,omitempty"`
}
type NameserverCreateRequest struct {
Domain string `structs:"domain"`
Type string `structs:"type"`
Nameservers []string `structs:"ns,omitempty"`
MasterIp string `structs:"masterIp,omitempty"`
Web string `structs:"web,omitempty"`
Mail string `structs:"mail,omitempty"`
SoaEmail string `structs:"soaEmail,omitempty"`
UrlRedirectType string `structs:"urlRedirectType,omitempty"`
UrlRedirectTitle string `structs:"urlRedirectTitle,omitempty"`
UrlRedirectDescription string `structs:"urlRedirectDescription,omitempty"`
UrlRedirectFavIcon string `structs:"urlRedirectFavIcon,omitempty"`
UrlRedirectKeywords string `structs:"urlRedirectKeywords,omitempty"`
Testing bool `structs:"testing,omitempty"`
}
type NameserverInfoRequest struct {
Domain string `structs:"domain,omitempty"`
RoId int `structs:"roId,omitempty"`
RecordId int `structs:"recordId,omitempty"`
Type string `structs:"type,omitempty"`
Name string `structs:"name,omitempty"`
Content string `structs:"content,omitempty"`
Ttl int `structs:"ttl,omitempty"`
Prio int `structs:"prio,omitempty"`
}
type NamserverInfoResponse struct {
RoId int
Domain string
Type string
MasterIp string
LastZoneCheck time.Time
SlaveDns interface{}
SOAserial string
Count int
Records []NameserverRecord `mapstructure:"record"`
}
type NameserverRecord struct {
Id int
Name string
Type string
Content string
Ttl int
Prio int
UrlRedirectType string
UrlRedirectTitle string
UrlRedirectDescription string
UrlRedirectKeywords string
UrlRedirectFavIcon string
}
type NamserverListResponse struct {
Count int
Domains []NameserverDomain `mapstructure:"domains"`
}
type NameserverDomain struct {
RoId int `mapstructure:"roId"`
Domain string `mapstructure:"domain"`
Type string `mapstructure:"type"`
MasterIp string `mapstructure:"masterIp"`
Mail string `mapstructure:"mail"`
Web string `mapstructure:"web"`
Url string `mapstructure:"url"`
Ipv4 string `mapstructure:"ipv4"`
Ipv6 string `mapstructure:"ipv6"`
}
func (s *NameserverServiceOp) Check(domain string, nameservers []string) (*NameserverCheckResponse, error) {
req := s.client.NewRequest(methodNameserverCheck, map[string]interface{}{ req := s.client.NewRequest(methodNameserverCheck, map[string]interface{}{
"domain": domain, "domain": domain,
"ns": nameservers, "ns": nameservers,
@ -148,7 +45,8 @@ func (s *NameserverServiceOp) Check(domain string, nameservers []string) (*Names
return &result, nil return &result, nil
} }
func (s *NameserverServiceOp) Info(request *NameserverInfoRequest) (*NamserverInfoResponse, error) { // Info Gets informations.
func (s *NameserverService) Info(request *NameserverInfoRequest) (*NamserverInfoResponse, error) {
req := s.client.NewRequest(methodNameserverInfo, structs.Map(request)) req := s.client.NewRequest(methodNameserverInfo, structs.Map(request))
resp, err := s.client.Do(*req) resp, err := s.client.Do(*req)
@ -164,7 +62,8 @@ func (s *NameserverServiceOp) Info(request *NameserverInfoRequest) (*NamserverIn
return &result, nil return &result, nil
} }
func (s *NameserverServiceOp) List(domain string) (*NamserverListResponse, error) { // List List nameservers for a domain.
func (s *NameserverService) List(domain string) (*NamserverListResponse, error) {
requestMap := map[string]interface{}{ requestMap := map[string]interface{}{
"domain": "*", "domain": "*",
"wide": 2, "wide": 2,
@ -187,7 +86,8 @@ func (s *NameserverServiceOp) List(domain string) (*NamserverListResponse, error
return &result, nil return &result, nil
} }
func (s *NameserverServiceOp) Create(request *NameserverCreateRequest) (int, error) { // Create Creates a namesever.
func (s *NameserverService) Create(request *NameserverCreateRequest) (int, error) {
req := s.client.NewRequest(methodNameserverCreate, structs.Map(request)) req := s.client.NewRequest(methodNameserverCreate, structs.Map(request))
resp, err := s.client.Do(*req) resp, err := s.client.Do(*req)
@ -204,7 +104,8 @@ func (s *NameserverServiceOp) Create(request *NameserverCreateRequest) (int, err
return result["roId"], nil return result["roId"], nil
} }
func (s *NameserverServiceOp) CreateRecord(request *NameserverRecordRequest) (int, error) { // CreateRecord Creates a DNS record.
func (s *NameserverService) CreateRecord(request *NameserverRecordRequest) (int, error) {
req := s.client.NewRequest(methodNameserverCreateRecord, structs.Map(request)) req := s.client.NewRequest(methodNameserverCreateRecord, structs.Map(request))
resp, err := s.client.Do(*req) resp, err := s.client.Do(*req)
@ -221,12 +122,13 @@ func (s *NameserverServiceOp) CreateRecord(request *NameserverRecordRequest) (in
return result["id"], nil return result["id"], nil
} }
func (s *NameserverServiceOp) UpdateRecord(recId int, request *NameserverRecordRequest) error { // UpdateRecord Updates a DNS record.
func (s *NameserverService) UpdateRecord(recID int, request *NameserverRecordRequest) error {
if request == nil { if request == nil {
return errors.New("Request can't be nil") return errors.New("request can't be nil")
} }
requestMap := structs.Map(request) requestMap := structs.Map(request)
requestMap["id"] = recId requestMap["id"] = recID
req := s.client.NewRequest(methodNameserverUpdateRecord, requestMap) req := s.client.NewRequest(methodNameserverUpdateRecord, requestMap)
@ -238,9 +140,10 @@ func (s *NameserverServiceOp) UpdateRecord(recId int, request *NameserverRecordR
return nil return nil
} }
func (s *NameserverServiceOp) DeleteRecord(recId int) error { // DeleteRecord Deletes a DNS record.
func (s *NameserverService) DeleteRecord(recID int) error {
req := s.client.NewRequest(methodNameserverDeleteRecord, map[string]interface{}{ req := s.client.NewRequest(methodNameserverDeleteRecord, map[string]interface{}{
"id": recId, "id": recID,
}) })
_, err := s.client.Do(*req) _, err := s.client.Do(*req)
@ -251,25 +154,130 @@ func (s *NameserverServiceOp) DeleteRecord(recId int) error {
return nil return nil
} }
func (s *NameserverServiceOp) FindRecordById(recId int) (*NameserverRecord, *NameserverDomain, error) { // FindRecordByID Search a DNS record by ID.
func (s *NameserverService) FindRecordByID(recID int) (*NameserverRecord, *NameserverDomain, error) {
listResp, err := s.client.Nameservers.List("") listResp, err := s.client.Nameservers.List("")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
for _, domainItem := range listResp.Domains { for _, domainItem := range listResp.Domains {
resp, err := s.client.Nameservers.Info(&NameserverInfoRequest{RoId: domainItem.RoId}) resp, err := s.client.Nameservers.Info(&NameserverInfoRequest{RoID: domainItem.RoID})
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
for _, record := range resp.Records { for _, record := range resp.Records {
if record.Id == recId { if record.ID == recID {
return &record, &domainItem, nil return &record, &domainItem, nil
} }
} }
} }
return nil, nil, fmt.Errorf("couldn't find INWX Record for id %d", recId) return nil, nil, fmt.Errorf("couldn't find INWX Record for id %d", recID)
} }
// NameserverCheckResponse API model.
type NameserverCheckResponse struct {
Details []string
Status string
}
// NameserverRecordRequest API model.
type NameserverRecordRequest struct {
RoID int `structs:"roId,omitempty"`
Domain string `structs:"domain,omitempty"`
Type string `structs:"type"`
Content string `structs:"content"`
Name string `structs:"name,omitempty"`
TTL int `structs:"ttl,omitempty"`
Priority int `structs:"prio,omitempty"`
URLRedirectType string `structs:"urlRedirectType,omitempty"`
URLRedirectTitle string `structs:"urlRedirectTitle,omitempty"`
URLRedirectDescription string `structs:"urlRedirectDescription,omitempty"`
URLRedirectFavIcon string `structs:"urlRedirectFavIcon,omitempty"`
URLRedirectKeywords string `structs:"urlRedirectKeywords,omitempty"`
}
// NameserverCreateRequest API model.
type NameserverCreateRequest struct {
Domain string `structs:"domain"`
Type string `structs:"type"`
Nameservers []string `structs:"ns,omitempty"`
MasterIP string `structs:"masterIp,omitempty"`
Web string `structs:"web,omitempty"`
Mail string `structs:"mail,omitempty"`
SoaEmail string `structs:"soaEmail,omitempty"`
URLRedirectType string `structs:"urlRedirectType,omitempty"`
URLRedirectTitle string `structs:"urlRedirectTitle,omitempty"`
URLRedirectDescription string `structs:"urlRedirectDescription,omitempty"`
URLRedirectFavIcon string `structs:"urlRedirectFavIcon,omitempty"`
URLRedirectKeywords string `structs:"urlRedirectKeywords,omitempty"`
Testing bool `structs:"testing,omitempty"`
}
// NameserverInfoRequest API model.
type NameserverInfoRequest struct {
Domain string `structs:"domain,omitempty"`
RoID int `structs:"roId,omitempty"`
RecordID int `structs:"recordId,omitempty"`
Type string `structs:"type,omitempty"`
Name string `structs:"name,omitempty"`
Content string `structs:"content,omitempty"`
TTL int `structs:"ttl,omitempty"`
Priority int `structs:"prio,omitempty"`
}
// NamserverInfoResponse API model.
type NamserverInfoResponse struct {
RoID int `mapstructure:"roId"`
Domain string `mapstructure:"domain"`
Type string `mapstructure:"type"`
MasterIP string `mapstructure:"masterIp"`
LastZoneCheck time.Time `mapstructure:"lastZoneCheck"`
SlaveDNS []SlaveInfo `mapstructure:"slaveDns"`
SOASerial string `mapstructure:"SOAserial"`
Count int `mapstructure:"count"`
Records []NameserverRecord `mapstructure:"record"`
}
// SlaveInfo API model.
type SlaveInfo struct {
Name string `mapstructure:"name"`
IP string `mapstructure:"ip"`
}
// NameserverRecord API model.
type NameserverRecord struct {
ID int `mapstructure:"id"`
Name string `mapstructure:"name"`
Type string `mapstructure:"type"`
Content string `mapstructure:"content"`
TTL int `mapstructure:"TTL"`
Priority int `mapstructure:"prio"`
URLRedirectType string `mapstructure:"urlRedirectType"`
URLRedirectTitle string `mapstructure:"urlRedirectTitle"`
URLRedirectDescription string `mapstructure:"urlRedirectDescription"`
URLRedirectKeywords string `mapstructure:"urlRedirectKeywords"`
URLRedirectFavIcon string `mapstructure:"urlRedirectFavIcon"`
}
// NamserverListResponse API model.
type NamserverListResponse struct {
Count int
Domains []NameserverDomain `mapstructure:"domains"`
}
// NameserverDomain API model.
type NameserverDomain struct {
RoID int `mapstructure:"roId"`
Domain string `mapstructure:"domain"`
Type string `mapstructure:"type"`
MasterIP string `mapstructure:"masterIp"`
Mail string `mapstructure:"mail"`
Web string `mapstructure:"web"`
URL string `mapstructure:"url"`
Ipv4 string `mapstructure:"ipv4"`
Ipv6 string `mapstructure:"ipv6"`
}

28
vendor/github.com/nrdcg/goinwx/response.go generated vendored Normal file
View file

@ -0,0 +1,28 @@
package goinwx
import "fmt"
// Response is a INWX API response. This wraps the standard http.Response returned from INWX.
type Response struct {
Code int `xmlrpc:"code"`
Message string `xmlrpc:"msg"`
ReasonCode string `xmlrpc:"reasonCode"`
Reason string `xmlrpc:"reason"`
ResponseData map[string]interface{} `xmlrpc:"resData"`
}
// An ErrorResponse reports the error caused by an API request
type ErrorResponse struct {
Code int `xmlrpc:"code"`
Message string `xmlrpc:"msg"`
ReasonCode string `xmlrpc:"reasonCode"`
Reason string `xmlrpc:"reason"`
}
func (r *ErrorResponse) Error() string {
if r.Reason != "" {
return fmt.Sprintf("(%d) %s. Reason: (%s) %s",
r.Code, r.Message, r.ReasonCode, r.Reason)
}
return fmt.Sprintf("(%d) %s", r.Code, r.Message)
}

View file

@ -1,133 +0,0 @@
package goinwx
import (
"fmt"
"net/url"
"github.com/kolo/xmlrpc"
)
const (
libraryVersion = "0.4.0"
APIBaseUrl = "https://api.domrobot.com/xmlrpc/"
APISandboxBaseUrl = "https://api.ote.domrobot.com/xmlrpc/"
APILanguage = "eng"
)
// Client manages communication with INWX API.
type Client struct {
// HTTP client used to communicate with the INWX API.
RPCClient *xmlrpc.Client
// Base URL for API requests.
BaseURL *url.URL
// API username
Username string
// API password
Password string
// User agent for client
APILanguage string
// Services used for communicating with the API
Account AccountService
Domains DomainService
Nameservers NameserverService
Contacts ContactService
}
type ClientOptions struct {
Sandbox bool
}
type Request struct {
ServiceMethod string
Args map[string]interface{}
}
// Response is a INWX API response. This wraps the standard http.Response returned from INWX.
type Response struct {
Code int `xmlrpc:"code"`
Message string `xmlrpc:"msg"`
ReasonCode string `xmlrpc:"reasonCode"`
Reason string `xmlrpc:"reason"`
ResponseData map[string]interface{} `xmlrpc:"resData"`
}
// An ErrorResponse reports the error caused by an API request
type ErrorResponse struct {
Code int `xmlrpc:"code"`
Message string `xmlrpc:"msg"`
ReasonCode string `xmlrpc:"reasonCode"`
Reason string `xmlrpc:"reason"`
}
// NewClient returns a new INWX API client.
func NewClient(username, password string, opts *ClientOptions) *Client {
var useSandbox bool
if opts != nil {
useSandbox = opts.Sandbox
}
var baseURL *url.URL
if useSandbox {
baseURL, _ = url.Parse(APISandboxBaseUrl)
} else {
baseURL, _ = url.Parse(APIBaseUrl)
}
rpcClient, _ := xmlrpc.NewClient(baseURL.String(), nil)
client := &Client{RPCClient: rpcClient,
BaseURL: baseURL,
Username: username,
Password: password,
}
client.Account = &AccountServiceOp{client: client}
client.Domains = &DomainServiceOp{client: client}
client.Nameservers = &NameserverServiceOp{client: client}
client.Contacts = &ContactServiceOp{client: client}
return client
}
// NewRequest creates an API request.
func (c *Client) NewRequest(serviceMethod string, args map[string]interface{}) *Request {
if args != nil {
args["lang"] = APILanguage
}
return &Request{ServiceMethod: serviceMethod, Args: args}
}
// Do sends an API request and returns the API response.
func (c *Client) Do(req Request) (*map[string]interface{}, error) {
var resp Response
err := c.RPCClient.Call(req.ServiceMethod, req.Args, &resp)
if err != nil {
return nil, err
}
return &resp.ResponseData, CheckResponse(&resp)
}
func (r *ErrorResponse) Error() string {
if r.Reason != "" {
return fmt.Sprintf("(%d) %s. Reason: (%s) %s",
r.Code, r.Message, r.ReasonCode, r.Reason)
}
return fmt.Sprintf("(%d) %s", r.Code, r.Message)
}
// CheckResponse checks the API response for errors, and returns them if present.
func CheckResponse(r *Response) error {
if c := r.Code; c >= 1000 && c <= 1500 {
return nil
}
return &ErrorResponse{Code: r.Code, Message: r.Message, Reason: r.Reason, ReasonCode: r.ReasonCode}
}