1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Update DNSimple Provider to api client 0.62 (#739)

* Update DNSimple-go to 0.61

This adds support for contexts, exports all return values, Adds ZoneRecordAttributes to fix support for blank record names.

* Add UserAgent to client

* Update Integration test for DNSimple

We now support Empty TXT, however we do not support Null MX yet.

* Bump to dnsimple-go 0.62 & use dnsimple.String()
This commit is contained in:
Amelia Aronsohn
2020-05-13 13:37:49 -07:00
committed by GitHub
parent d8a153c01f
commit b2b0ed4154
33 changed files with 777 additions and 629 deletions

2
go.mod
View File

@ -17,7 +17,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/dgrijalva/jwt-go v3.2.1-0.20190620180102-5e25c22bd5d6+incompatible // indirect github.com/dgrijalva/jwt-go v3.2.1-0.20190620180102-5e25c22bd5d6+incompatible // indirect
github.com/digitalocean/godo v1.35.1 github.com/digitalocean/godo v1.35.1
github.com/dnsimple/dnsimple-go v0.31.0 github.com/dnsimple/dnsimple-go v0.62.0
github.com/exoscale/egoscale v0.23.0 github.com/exoscale/egoscale v0.23.0
github.com/go-acme/lego v2.7.2+incompatible github.com/go-acme/lego v2.7.2+incompatible
github.com/gobwas/glob v0.2.4-0.20181002190808-e7a84e9525fe github.com/gobwas/glob v0.2.4-0.20181002190808-e7a84e9525fe

6
go.sum
View File

@ -3,8 +3,6 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.41.1-0.20190703172311-335e9e09b93e h1:E4NknbTPW+1SVNhlxaJolqh+W5FM4q7KsiR2zv8tVNg= cloud.google.com/go v0.41.1-0.20190703172311-335e9e09b93e h1:E4NknbTPW+1SVNhlxaJolqh+W5FM4q7KsiR2zv8tVNg=
cloud.google.com/go v0.41.1-0.20190703172311-335e9e09b93e/go.mod h1:05T3xsDVUIfRZP+EM2ftPky59P2i67FhEj6hjkpO5GE= cloud.google.com/go v0.41.1-0.20190703172311-335e9e09b93e/go.mod h1:05T3xsDVUIfRZP+EM2ftPky59P2i67FhEj6hjkpO5GE=
github.com/Azure/azure-sdk-for-go v41.3.0+incompatible h1:W5px0x53aa47nmIAuF1XWR1ZzFuUnkJBGUuzHnNp+Nk=
github.com/Azure/azure-sdk-for-go v41.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go v42.0.0+incompatible h1:yz6sFf5bHZ+gEOQVuK5JhPqTTAmv+OvSLSaqgzqaCwY= github.com/Azure/azure-sdk-for-go v42.0.0+incompatible h1:yz6sFf5bHZ+gEOQVuK5JhPqTTAmv+OvSLSaqgzqaCwY=
github.com/Azure/azure-sdk-for-go v42.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go v42.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
@ -69,8 +67,8 @@ github.com/digitalocean/godo v1.35.1 h1:3P5timR4LTqcCafzrCgV2j83ck4aWb937ybFC7YQ
github.com/digitalocean/godo v1.35.1/go.mod h1:p7dOjjtSBqCTUksqtA5Fd3uaKs9kyTq2xcz76ulEJRU= github.com/digitalocean/godo v1.35.1/go.mod h1:p7dOjjtSBqCTUksqtA5Fd3uaKs9kyTq2xcz76ulEJRU=
github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4= github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4=
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
github.com/dnsimple/dnsimple-go v0.31.0 h1:I1T+AxBQfhovyyfGSJ4CSUeH0iQejLArsUlhSQKw8WI= github.com/dnsimple/dnsimple-go v0.62.0 h1:Lr4U8F08FBL90rMEtQMR547RebifgwTPGCRC/+6ZW4g=
github.com/dnsimple/dnsimple-go v0.31.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/dnsimple/dnsimple-go v0.62.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/exoscale/egoscale v0.23.0 h1:hoUDzrO8yNoobNdnrRvlRFjfg3Ng0vQTrv6bXRJu6z0= github.com/exoscale/egoscale v0.23.0 h1:hoUDzrO8yNoobNdnrRvlRFjfg3Ng0vQTrv6bXRJu6z0=

View File

@ -614,7 +614,7 @@ func makeTests(t *testing.T) []*TestGroup {
), ),
testgroup("Null MX", testgroup("Null MX",
not("AZURE_DNS", "GANDI_V5", "NAMEDOTCOM", "DIGITALOCEAN", "NETCUP"), // These providers don't support RFC 7505 not("AZURE_DNS", "GANDI_V5", "NAMEDOTCOM", "DIGITALOCEAN", "NETCUP", "DNSIMPLE"), // These providers don't support RFC 7505
tc("Null MX", mx("@", 0, ".")), tc("Null MX", mx("@", 0, ".")),
), ),
@ -654,7 +654,7 @@ func makeTests(t *testing.T) []*TestGroup {
), ),
testgroup("empty TXT", testgroup("empty TXT",
not("DNSIMPLE", "CLOUDFLAREAPI", "NETCUP"), not("CLOUDFLAREAPI", "NETCUP"),
tc("TXT with empty str", txt("foo1", "")), tc("TXT with empty str", txt("foo1", "")),
// https://github.com/StackExchange/dnscontrol/issues/598 // https://github.com/StackExchange/dnscontrol/issues/598
// We decided that permitting the TXT target to be an empty // We decided that permitting the TXT target to be an empty

View File

@ -91,7 +91,9 @@ func (client *DnsimpleApi) GetZoneRecords(domain string) (models.Records, error)
continue continue
case "ALIAS", "URL": case "ALIAS", "URL":
rec.Type = r.Type rec.Type = r.Type
rec.SetTarget(r.Content) if err := rec.SetTarget(r.Content); err != nil {
panic(fmt.Errorf("unparsable record received from dnsimple: %w", err))
}
case "MX": case "MX":
if err := rec.SetTargetMX(uint16(r.Priority), r.Content); err != nil { if err := rec.SetTargetMX(uint16(r.Priority), r.Content); err != nil {
panic(fmt.Errorf("unparsable record received from dnsimple: %w", err)) panic(fmt.Errorf("unparsable record received from dnsimple: %w", err))
@ -247,6 +249,7 @@ func (c *DnsimpleApi) getClient() *dnsimpleapi.Client {
// new client // new client
client := dnsimpleapi.NewClient(tc) client := dnsimpleapi.NewClient(tc)
client.SetUserAgent("DNSControl")
if c.BaseURL != "" { if c.BaseURL != "" {
client.BaseURL = c.BaseURL client.BaseURL = c.BaseURL
@ -257,7 +260,7 @@ func (c *DnsimpleApi) getClient() *dnsimpleapi.Client {
func (c *DnsimpleApi) getAccountID() (string, error) { func (c *DnsimpleApi) getAccountID() (string, error) {
if c.accountID == "" { if c.accountID == "" {
client := c.getClient() client := c.getClient()
whoamiResponse, err := client.Identity.Whoami() whoamiResponse, err := client.Identity.Whoami(context.Background())
if err != nil { if err != nil {
return "", err return "", err
} }
@ -279,9 +282,10 @@ func (c *DnsimpleApi) getRecords(domainName string) ([]dnsimpleapi.ZoneRecord, e
opts := &dnsimpleapi.ZoneRecordListOptions{} opts := &dnsimpleapi.ZoneRecordListOptions{}
recs := []dnsimpleapi.ZoneRecord{} recs := []dnsimpleapi.ZoneRecord{}
opts.Page = 1 page := 1
for { for {
recordsResponse, err := client.Zones.ListRecords(accountID, domainName, opts) opts.Page = &page
recordsResponse, err := client.Zones.ListRecords(context.Background(), accountID, domainName, opts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -290,7 +294,7 @@ func (c *DnsimpleApi) getRecords(domainName string) ([]dnsimpleapi.ZoneRecord, e
if pg.CurrentPage == pg.TotalPages { if pg.CurrentPage == pg.TotalPages {
break break
} }
opts.Page++ page++
} }
return recs, nil return recs, nil
@ -307,7 +311,7 @@ func (c *DnsimpleApi) getDnssec(domainName string) (bool, error) {
return false, err return false, err
} }
dnssecResponse, err := client.Domains.GetDnssec(accountID, domainName) dnssecResponse, err := client.Domains.GetDnssec(context.Background(), accountID, domainName)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -328,7 +332,7 @@ func (c *DnsimpleApi) enableDnssec(domainName string) (bool, error) {
return false, err return false, err
} }
dnssecResponse, err := client.Domains.EnableDnssec(accountID, domainName) dnssecResponse, err := client.Domains.EnableDnssec(context.Background(), accountID, domainName)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -349,7 +353,7 @@ func (c *DnsimpleApi) disableDnssec(domainName string) (bool, error) {
return false, err return false, err
} }
dnssecResponse, err := client.Domains.DisableDnssec(accountID, domainName) dnssecResponse, err := client.Domains.DisableDnssec(context.Background(), accountID, domainName)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -370,14 +374,14 @@ func (c *DnsimpleApi) getNameservers(domainName string) ([]string, error) {
return nil, err return nil, err
} }
domainResponse, err := client.Domains.GetDomain(accountID, domainName) domainResponse, err := client.Domains.GetDomain(context.Background(), accountID, domainName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if domainResponse.Data.State == stateRegistered { if domainResponse.Data.State == stateRegistered {
delegationResponse, err := client.Registrar.GetDomainDelegation(accountID, domainName) delegationResponse, err := client.Registrar.GetDomainDelegation(context.Background(), accountID, domainName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -399,7 +403,7 @@ func (c *DnsimpleApi) updateNameserversFunc(nameServerNames []string, domainName
nameServers := dnsimpleapi.Delegation(nameServerNames) nameServers := dnsimpleapi.Delegation(nameServerNames)
_, err = client.Registrar.ChangeDomainDelegation(accountID, domainName, &nameServers) _, err = client.Registrar.ChangeDomainDelegation(context.Background(), accountID, domainName, &nameServers)
if err != nil { if err != nil {
return err return err
} }
@ -417,14 +421,14 @@ func (c *DnsimpleApi) createRecordFunc(rc *models.RecordConfig, domainName strin
if err != nil { if err != nil {
return err return err
} }
record := dnsimpleapi.ZoneRecord{ record := dnsimpleapi.ZoneRecordAttributes{
Name: rc.GetLabel(), Name: dnsimpleapi.String(rc.GetLabel()),
Type: rc.Type, Type: rc.Type,
Content: getTargetRecordContent(rc), Content: getTargetRecordContent(rc),
TTL: int(rc.TTL), TTL: int(rc.TTL),
Priority: getTargetRecordPriority(rc), Priority: getTargetRecordPriority(rc),
} }
_, err = client.Zones.CreateRecord(accountID, domainName, record) _, err = client.Zones.CreateRecord(context.Background(), accountID, domainName, record)
if err != nil { if err != nil {
return err return err
} }
@ -443,7 +447,7 @@ func (c *DnsimpleApi) deleteRecordFunc(recordID int64, domainName string) func()
return err return err
} }
_, err = client.Zones.DeleteRecord(accountID, domainName, recordID) _, err = client.Zones.DeleteRecord(context.Background(), accountID, domainName, recordID)
if err != nil { if err != nil {
return err return err
} }
@ -463,15 +467,15 @@ func (c *DnsimpleApi) updateRecordFunc(old *dnsimpleapi.ZoneRecord, rc *models.R
return err return err
} }
record := dnsimpleapi.ZoneRecord{ record := dnsimpleapi.ZoneRecordAttributes{
Name: rc.GetLabel(), Name: dnsimpleapi.String(rc.GetLabel()),
Type: rc.Type, Type: rc.Type,
Content: getTargetRecordContent(rc), Content: getTargetRecordContent(rc),
TTL: int(rc.TTL), TTL: int(rc.TTL),
Priority: getTargetRecordPriority(rc), Priority: getTargetRecordPriority(rc),
} }
_, err = client.Zones.UpdateRecord(accountID, domainName, old.ID, record) _, err = client.Zones.UpdateRecord(context.Background(), accountID, domainName, old.ID, record)
if err != nil { if err != nil {
return err return err
} }
@ -490,9 +494,10 @@ func (c *DnsimpleApi) ListZones() ([]string, error) {
var zones []string var zones []string
opts := &dnsimpleapi.ZoneListOptions{} opts := &dnsimpleapi.ZoneListOptions{}
opts.Page = 1 page := 1
for { for {
zonesResponse, err := client.Zones.ListZones(accountID, opts) opts.Page = &page
zonesResponse, err := client.Zones.ListZones(context.Background(), accountID, opts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -503,7 +508,7 @@ func (c *DnsimpleApi) ListZones() ([]string, error) {
if pg.CurrentPage == pg.TotalPages { if pg.CurrentPage == pg.TotalPages {
break break
} }
opts.Page++ page++
} }
return zones, nil return zones, nil
} }

View File

@ -1,5 +1,13 @@
package dnsimple package dnsimple
import (
"context"
)
// AccountsService handles communication with the account related
// methods of the DNSimple API.
//
// See https://developer.dnsimple.com/v2/accounts/
type AccountsService struct { type AccountsService struct {
client *Client client *Client
} }
@ -13,8 +21,8 @@ type Account struct {
UpdatedAt string `json:"updated_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"`
} }
// accountsResponse represents a response from an API method that returns a collection of Account struct. // AccountsResponse represents a response from an API method that returns a collection of Account struct.
type accountsResponse struct { type AccountsResponse struct {
Response Response
Data []Account `json:"data"` Data []Account `json:"data"`
} }
@ -22,20 +30,20 @@ type accountsResponse struct {
// ListAccounts list the accounts for an user. // ListAccounts list the accounts for an user.
// //
// See https://developer.dnsimple.com/v2/accounts/#list // See https://developer.dnsimple.com/v2/accounts/#list
func (s *AccountsService) ListAccounts(options *ListOptions) (*accountsResponse, error) { func (s *AccountsService) ListAccounts(ctx context.Context, options *ListOptions) (*AccountsResponse, error) {
path := versioned("/accounts") path := versioned("/accounts")
accountsResponse := &accountsResponse{} accountsResponse := &AccountsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, accountsResponse) resp, err := s.client.get(ctx, path, accountsResponse)
if err != nil { if err != nil {
return accountsResponse, err return accountsResponse, err
} }
accountsResponse.HttpResponse = resp accountsResponse.HTTPResponse = resp
return accountsResponse, nil return accountsResponse, nil
} }

View File

@ -1,9 +1,24 @@
package dnsimple package dnsimple
import ( import (
"context"
"net/http" "net/http"
"golang.org/x/oauth2"
) )
// BasicAuthHTTPClient returns a client that authenticates via HTTP Basic Auth with given username and password.
func BasicAuthHTTPClient(_ context.Context, username, password string) *http.Client {
tp := BasicAuthTransport{Username: username, Password: password}
return tp.Client()
}
// StaticTokenHTTPClient returns a client that authenticates with a static OAuth token.
func StaticTokenHTTPClient(ctx context.Context, token string) *http.Client {
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
return oauth2.NewClient(ctx, ts)
}
// BasicAuthTransport is an http.RoundTripper that authenticates all requests // BasicAuthTransport is an http.RoundTripper that authenticates all requests
// using HTTP Basic Authentication with the provided username and password. // using HTTP Basic Authentication with the provided username and password.
type BasicAuthTransport struct { type BasicAuthTransport struct {

View File

@ -1,13 +1,14 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
// CertificatesService handles communication with the certificate related // CertificatesService handles communication with the certificate related
// methods of the DNSimple API. // methods of the DNSimple API.
// //
// See https://developer.dnsimple.com/v2/certificates // See https://developer.dnsimple.com/v2/certificates/
type CertificatesService struct { type CertificatesService struct {
client *Client client *Client
} }
@ -84,32 +85,32 @@ func letsencryptCertificatePath(accountID, domainIdentifier string, certificateI
return return
} }
// certificateResponse represents a response from an API method that returns a Certificate struct. // CertificateResponse represents a response from an API method that returns a Certificate struct.
type certificateResponse struct { type CertificateResponse struct {
Response Response
Data *Certificate `json:"data"` Data *Certificate `json:"data"`
} }
// certificateBundleResponse represents a response from an API method that returns a CertificatBundle struct. // CertificateBundleResponse represents a response from an API method that returns a CertificatBundle struct.
type certificateBundleResponse struct { type CertificateBundleResponse struct {
Response Response
Data *CertificateBundle `json:"data"` Data *CertificateBundle `json:"data"`
} }
// certificatesResponse represents a response from an API method that returns a collection of Certificate struct. // CertificatesResponse represents a response from an API method that returns a collection of Certificate struct.
type certificatesResponse struct { type CertificatesResponse struct {
Response Response
Data []Certificate `json:"data"` Data []Certificate `json:"data"`
} }
// certificatePurchaseResponse represents a response from an API method that returns a CertificatePurchase struct. // CertificatePurchaseResponse represents a response from an API method that returns a CertificatePurchase struct.
type certificatePurchaseResponse struct { type CertificatePurchaseResponse struct {
Response Response
Data *CertificatePurchase `json:"data"` Data *CertificatePurchase `json:"data"`
} }
// certificateRenewalResponse represents a response from an API method that returns a CertificateRenewal struct. // CertificateRenewalResponse represents a response from an API method that returns a CertificateRenewal struct.
type certificateRenewalResponse struct { type CertificateRenewalResponse struct {
Response Response
Data *CertificateRenewal `json:"data"` Data *CertificateRenewal `json:"data"`
} }
@ -117,37 +118,37 @@ type certificateRenewalResponse struct {
// ListCertificates lists the certificates for a domain in the account. // ListCertificates lists the certificates for a domain in the account.
// //
// See https://developer.dnsimple.com/v2/certificates#listCertificates // See https://developer.dnsimple.com/v2/certificates#listCertificates
func (s *CertificatesService) ListCertificates(accountID, domainIdentifier string, options *ListOptions) (*certificatesResponse, error) { func (s *CertificatesService) ListCertificates(ctx context.Context, accountID, domainIdentifier string, options *ListOptions) (*CertificatesResponse, error) {
path := versioned(certificatePath(accountID, domainIdentifier, 0)) path := versioned(certificatePath(accountID, domainIdentifier, 0))
certificatesResponse := &certificatesResponse{} certificatesResponse := &CertificatesResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, certificatesResponse) resp, err := s.client.get(ctx, path, certificatesResponse)
if err != nil { if err != nil {
return certificatesResponse, err return certificatesResponse, err
} }
certificatesResponse.HttpResponse = resp certificatesResponse.HTTPResponse = resp
return certificatesResponse, nil return certificatesResponse, nil
} }
// GetCertificate gets the details of a certificate. // GetCertificate gets the details of a certificate.
// //
// See https://developer.dnsimple.com/v2/certificates#getCertificate // See https://developer.dnsimple.com/v2/certificates#getCertificate
func (s *CertificatesService) GetCertificate(accountID, domainIdentifier string, certificateID int64) (*certificateResponse, error) { func (s *CertificatesService) GetCertificate(ctx context.Context, accountID, domainIdentifier string, certificateID int64) (*CertificateResponse, error) {
path := versioned(certificatePath(accountID, domainIdentifier, certificateID)) path := versioned(certificatePath(accountID, domainIdentifier, certificateID))
certificateResponse := &certificateResponse{} certificateResponse := &CertificateResponse{}
resp, err := s.client.get(path, certificateResponse) resp, err := s.client.get(ctx, path, certificateResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
certificateResponse.HttpResponse = resp certificateResponse.HTTPResponse = resp
return certificateResponse, nil return certificateResponse, nil
} }
@ -155,95 +156,95 @@ func (s *CertificatesService) GetCertificate(accountID, domainIdentifier string,
// along with the root certificate and intermediate chain. // along with the root certificate and intermediate chain.
// //
// See https://developer.dnsimple.com/v2/certificates#downloadCertificate // See https://developer.dnsimple.com/v2/certificates#downloadCertificate
func (s *CertificatesService) DownloadCertificate(accountID, domainIdentifier string, certificateID int64) (*certificateBundleResponse, error) { func (s *CertificatesService) DownloadCertificate(ctx context.Context, accountID, domainIdentifier string, certificateID int64) (*CertificateBundleResponse, error) {
path := versioned(certificatePath(accountID, domainIdentifier, certificateID) + "/download") path := versioned(certificatePath(accountID, domainIdentifier, certificateID) + "/download")
certificateBundleResponse := &certificateBundleResponse{} certificateBundleResponse := &CertificateBundleResponse{}
resp, err := s.client.get(path, certificateBundleResponse) resp, err := s.client.get(ctx, path, certificateBundleResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
certificateBundleResponse.HttpResponse = resp certificateBundleResponse.HTTPResponse = resp
return certificateBundleResponse, nil return certificateBundleResponse, nil
} }
// GetCertificatePrivateKey gets the PEM-encoded certificate private key. // GetCertificatePrivateKey gets the PEM-encoded certificate private key.
// //
// See https://developer.dnsimple.com/v2/certificates#getCertificatePrivateKey // See https://developer.dnsimple.com/v2/certificates#getCertificatePrivateKey
func (s *CertificatesService) GetCertificatePrivateKey(accountID, domainIdentifier string, certificateID int64) (*certificateBundleResponse, error) { func (s *CertificatesService) GetCertificatePrivateKey(ctx context.Context, accountID, domainIdentifier string, certificateID int64) (*CertificateBundleResponse, error) {
path := versioned(certificatePath(accountID, domainIdentifier, certificateID) + "/private_key") path := versioned(certificatePath(accountID, domainIdentifier, certificateID) + "/private_key")
certificateBundleResponse := &certificateBundleResponse{} certificateBundleResponse := &CertificateBundleResponse{}
resp, err := s.client.get(path, certificateBundleResponse) resp, err := s.client.get(ctx, path, certificateBundleResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
certificateBundleResponse.HttpResponse = resp certificateBundleResponse.HTTPResponse = resp
return certificateBundleResponse, nil return certificateBundleResponse, nil
} }
// PurchaseLetsencryptCertificate purchases a Let's Encrypt certificate. // PurchaseLetsencryptCertificate purchases a Let's Encrypt certificate.
// //
// See https://developer.dnsimple.com/v2/certificates/#purchaseLetsencryptCertificate // See https://developer.dnsimple.com/v2/certificates/#purchaseLetsencryptCertificate
func (s *CertificatesService) PurchaseLetsencryptCertificate(accountID, domainIdentifier string, certificateAttributes LetsencryptCertificateAttributes) (*certificatePurchaseResponse, error) { func (s *CertificatesService) PurchaseLetsencryptCertificate(ctx context.Context, accountID, domainIdentifier string, certificateAttributes LetsencryptCertificateAttributes) (*CertificatePurchaseResponse, error) {
path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, 0)) path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, 0))
certificatePurchaseResponse := &certificatePurchaseResponse{} certificatePurchaseResponse := &CertificatePurchaseResponse{}
resp, err := s.client.post(path, certificateAttributes, certificatePurchaseResponse) resp, err := s.client.post(ctx, path, certificateAttributes, certificatePurchaseResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
certificatePurchaseResponse.HttpResponse = resp certificatePurchaseResponse.HTTPResponse = resp
return certificatePurchaseResponse, nil return certificatePurchaseResponse, nil
} }
// IssueLetsencryptCertificate issues a pending Let's Encrypt certificate purchase order. // IssueLetsencryptCertificate issues a pending Let's Encrypt certificate purchase order.
// //
// See https://developer.dnsimple.com/v2/certificates/#issueLetsencryptCertificate // See https://developer.dnsimple.com/v2/certificates/#issueLetsencryptCertificate
func (s *CertificatesService) IssueLetsencryptCertificate(accountID, domainIdentifier string, certificateID int64) (*certificateResponse, error) { func (s *CertificatesService) IssueLetsencryptCertificate(ctx context.Context, accountID, domainIdentifier string, certificateID int64) (*CertificateResponse, error) {
path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, certificateID) + "/issue") path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, certificateID) + "/issue")
certificateResponse := &certificateResponse{} certificateResponse := &CertificateResponse{}
resp, err := s.client.post(path, nil, certificateResponse) resp, err := s.client.post(ctx, path, nil, certificateResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
certificateResponse.HttpResponse = resp certificateResponse.HTTPResponse = resp
return certificateResponse, nil return certificateResponse, nil
} }
// PurchaseLetsencryptCertificateRenewal purchases a Let's Encrypt certificate renewal. // PurchaseLetsencryptCertificateRenewal purchases a Let's Encrypt certificate renewal.
// //
// See https://developer.dnsimple.com/v2/certificates/#purchaseRenewalLetsencryptCertificate // See https://developer.dnsimple.com/v2/certificates/#purchaseRenewalLetsencryptCertificate
func (s *CertificatesService) PurchaseLetsencryptCertificateRenewal(accountID, domainIdentifier string, certificateID int64, certificateAttributes LetsencryptCertificateAttributes) (*certificateRenewalResponse, error) { func (s *CertificatesService) PurchaseLetsencryptCertificateRenewal(ctx context.Context, accountID, domainIdentifier string, certificateID int64, certificateAttributes LetsencryptCertificateAttributes) (*CertificateRenewalResponse, error) {
path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, certificateID) + "/renewals") path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, certificateID) + "/renewals")
certificateRenewalResponse := &certificateRenewalResponse{} certificateRenewalResponse := &CertificateRenewalResponse{}
resp, err := s.client.post(path, certificateAttributes, certificateRenewalResponse) resp, err := s.client.post(ctx, path, certificateAttributes, certificateRenewalResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
certificateRenewalResponse.HttpResponse = resp certificateRenewalResponse.HTTPResponse = resp
return certificateRenewalResponse, nil return certificateRenewalResponse, nil
} }
// IssueLetsencryptCertificateRenewal issues a pending Let's Encrypt certificate renewal order. // IssueLetsencryptCertificateRenewal issues a pending Let's Encrypt certificate renewal order.
// //
// See https://developer.dnsimple.com/v2/certificates/#issueRenewalLetsencryptCertificate // See https://developer.dnsimple.com/v2/certificates/#issueRenewalLetsencryptCertificate
func (s *CertificatesService) IssueLetsencryptCertificateRenewal(accountID, domainIdentifier string, certificateID, certificateRenewalID int64) (*certificateResponse, error) { func (s *CertificatesService) IssueLetsencryptCertificateRenewal(ctx context.Context, accountID, domainIdentifier string, certificateID, certificateRenewalID int64) (*CertificateResponse, error) {
path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, certificateID) + fmt.Sprintf("/renewals/%d/issue", certificateRenewalID)) path := versioned(letsencryptCertificatePath(accountID, domainIdentifier, certificateID) + fmt.Sprintf("/renewals/%d/issue", certificateRenewalID))
certificateResponse := &certificateResponse{} certificateResponse := &CertificateResponse{}
resp, err := s.client.post(path, nil, certificateResponse) resp, err := s.client.post(ctx, path, nil, certificateResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
certificateResponse.HttpResponse = resp certificateResponse.HTTPResponse = resp
return certificateResponse, nil return certificateResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -42,14 +43,14 @@ func contactPath(accountID string, contactID int64) (path string) {
return return
} }
// contactResponse represents a response from an API method that returns a Contact struct. // ContactResponse represents a response from an API method that returns a Contact struct.
type contactResponse struct { type ContactResponse struct {
Response Response
Data *Contact `json:"data"` Data *Contact `json:"data"`
} }
// contactsResponse represents a response from an API method that returns a collection of Contact struct. // ContactsResponse represents a response from an API method that returns a collection of Contact struct.
type contactsResponse struct { type ContactsResponse struct {
Response Response
Data []Contact `json:"data"` Data []Contact `json:"data"`
} }
@ -57,84 +58,84 @@ type contactsResponse struct {
// ListContacts list the contacts for an account. // ListContacts list the contacts for an account.
// //
// See https://developer.dnsimple.com/v2/contacts/#list // See https://developer.dnsimple.com/v2/contacts/#list
func (s *ContactsService) ListContacts(accountID string, options *ListOptions) (*contactsResponse, error) { func (s *ContactsService) ListContacts(ctx context.Context, accountID string, options *ListOptions) (*ContactsResponse, error) {
path := versioned(contactPath(accountID, 0)) path := versioned(contactPath(accountID, 0))
contactsResponse := &contactsResponse{} contactsResponse := &ContactsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, contactsResponse) resp, err := s.client.get(ctx, path, contactsResponse)
if err != nil { if err != nil {
return contactsResponse, err return contactsResponse, err
} }
contactsResponse.HttpResponse = resp contactsResponse.HTTPResponse = resp
return contactsResponse, nil return contactsResponse, nil
} }
// CreateContact creates a new contact. // CreateContact creates a new contact.
// //
// See https://developer.dnsimple.com/v2/contacts/#create // See https://developer.dnsimple.com/v2/contacts/#create
func (s *ContactsService) CreateContact(accountID string, contactAttributes Contact) (*contactResponse, error) { func (s *ContactsService) CreateContact(ctx context.Context, accountID string, contactAttributes Contact) (*ContactResponse, error) {
path := versioned(contactPath(accountID, 0)) path := versioned(contactPath(accountID, 0))
contactResponse := &contactResponse{} contactResponse := &ContactResponse{}
resp, err := s.client.post(path, contactAttributes, contactResponse) resp, err := s.client.post(ctx, path, contactAttributes, contactResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
contactResponse.HttpResponse = resp contactResponse.HTTPResponse = resp
return contactResponse, nil return contactResponse, nil
} }
// GetContact fetches a contact. // GetContact fetches a contact.
// //
// See https://developer.dnsimple.com/v2/contacts/#get // See https://developer.dnsimple.com/v2/contacts/#get
func (s *ContactsService) GetContact(accountID string, contactID int64) (*contactResponse, error) { func (s *ContactsService) GetContact(ctx context.Context, accountID string, contactID int64) (*ContactResponse, error) {
path := versioned(contactPath(accountID, contactID)) path := versioned(contactPath(accountID, contactID))
contactResponse := &contactResponse{} contactResponse := &ContactResponse{}
resp, err := s.client.get(path, contactResponse) resp, err := s.client.get(ctx, path, contactResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
contactResponse.HttpResponse = resp contactResponse.HTTPResponse = resp
return contactResponse, nil return contactResponse, nil
} }
// UpdateContact updates a contact. // UpdateContact updates a contact.
// //
// See https://developer.dnsimple.com/v2/contacts/#update // See https://developer.dnsimple.com/v2/contacts/#update
func (s *ContactsService) UpdateContact(accountID string, contactID int64, contactAttributes Contact) (*contactResponse, error) { func (s *ContactsService) UpdateContact(ctx context.Context, accountID string, contactID int64, contactAttributes Contact) (*ContactResponse, error) {
path := versioned(contactPath(accountID, contactID)) path := versioned(contactPath(accountID, contactID))
contactResponse := &contactResponse{} contactResponse := &ContactResponse{}
resp, err := s.client.patch(path, contactAttributes, contactResponse) resp, err := s.client.patch(ctx, path, contactAttributes, contactResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
contactResponse.HttpResponse = resp contactResponse.HTTPResponse = resp
return contactResponse, nil return contactResponse, nil
} }
// DeleteContact PERMANENTLY deletes a contact from the account. // DeleteContact PERMANENTLY deletes a contact from the account.
// //
// See https://developer.dnsimple.com/v2/contacts/#delete // See https://developer.dnsimple.com/v2/contacts/#delete
func (s *ContactsService) DeleteContact(accountID string, contactID int64) (*contactResponse, error) { func (s *ContactsService) DeleteContact(ctx context.Context, accountID string, contactID int64) (*ContactResponse, error) {
path := versioned(contactPath(accountID, contactID)) path := versioned(contactPath(accountID, contactID))
contactResponse := &contactResponse{} contactResponse := &ContactResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
contactResponse.HttpResponse = resp contactResponse.HTTPResponse = resp
return contactResponse, nil return contactResponse, nil
} }

View File

@ -4,7 +4,9 @@ package dnsimple
import ( import (
"bytes" "bytes"
"context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -23,7 +25,7 @@ const (
// This is a pro-forma convention given that Go dependencies // This is a pro-forma convention given that Go dependencies
// tends to be fetched directly from the repo. // tends to be fetched directly from the repo.
// It is also used in the user-agent identify the client. // It is also used in the user-agent identify the client.
Version = "0.31.0" Version = "0.62.0"
// defaultBaseURL to the DNSimple production API. // defaultBaseURL to the DNSimple production API.
defaultBaseURL = "https://api.dnsimple.com" defaultBaseURL = "https://api.dnsimple.com"
@ -68,18 +70,18 @@ type Client struct {
} }
// ListOptions contains the common options you can pass to a List method // ListOptions contains the common options you can pass to a List method
// in order to control parameters such as paginations and page number. // in order to control parameters such as pagination and page number.
type ListOptions struct { type ListOptions struct {
// The page to return // The page to return
Page int `url:"page,omitempty"` Page *int `url:"page,omitempty"`
// The number of entries to return per page // The number of entries to return per page
PerPage int `url:"per_page,omitempty"` PerPage *int `url:"per_page,omitempty"`
// The order criteria to sort the results. // The order criteria to sort the results.
// The value is a comma-separated list of field[:direction], // The value is a comma-separated list of field[:direction],
// eg. name | name:desc | name:desc,expiration:desc // eg. name | name:desc | name:desc,expiration:desc
Sort string `url:"sort,omitempty"` Sort *string `url:"sort,omitempty"`
} }
// NewClient returns a new DNSimple API client. // NewClient returns a new DNSimple API client.
@ -104,10 +106,101 @@ func NewClient(httpClient *http.Client) *Client {
return c return c
} }
// NewRequest creates an API request. // SetUserAgent overrides the default UserAgent.
// The path is expected to be a relative path and will be resolved //
// according to the BaseURL of the Client. Paths should always be specified without a preceding slash. // When a custom user agent is provided, the final user agent is the combination of the custom user agent
func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Request, error) { // prepended by the default user agent.
//
// customAgentFlag dnsimple-go/1.0
//
func (c *Client) SetUserAgent(ua string) {
c.UserAgent = ua
}
// formatUserAgent builds the final user agent to use for HTTP requests.
//
// If no custom user agent is provided, the default user agent is used.
//
// dnsimple-go/1.0
//
// If a custom user agent is provided, the final user agent is the combination of the custom user agent
// prepended by the default user agent.
//
// customAgentFlag dnsimple-go/1.0
//
func formatUserAgent(customUserAgent string) string {
if customUserAgent == "" {
return defaultUserAgent
}
return fmt.Sprintf("%s %s", customUserAgent, defaultUserAgent)
}
func versioned(path string) string {
return fmt.Sprintf("/%s/%s", apiVersion, strings.Trim(path, "/"))
}
func (c *Client) get(ctx context.Context, path string, obj interface{}) (*http.Response, error) {
return c.makeRequest(ctx, http.MethodGet, path, nil, obj, nil)
}
func (c *Client) post(ctx context.Context, path string, payload, obj interface{}) (*http.Response, error) {
return c.makeRequest(ctx, http.MethodPost, path, payload, obj, nil)
}
func (c *Client) put(ctx context.Context, path string, payload, obj interface{}) (*http.Response, error) {
return c.makeRequest(ctx, http.MethodPut, path, payload, obj, nil)
}
func (c *Client) patch(ctx context.Context, path string, payload, obj interface{}) (*http.Response, error) {
return c.makeRequest(ctx, http.MethodPatch, path, payload, obj, nil)
}
func (c *Client) delete(ctx context.Context, path string, payload, obj interface{}) (*http.Response, error) {
return c.makeRequest(ctx, http.MethodDelete, path, payload, obj, nil)
}
// Request executes an API request with the current client scope, and returns the response.
func (c *Client) Request(ctx context.Context, method, path string, payload, obj interface{}, headers http.Header) (*http.Response, error) {
return c.makeRequest(ctx, method, path, payload, obj, headers)
}
// makeRequest executes an API request and returns the HTTP response.
//
// The content pointed by payload is serialized and used as body of the request.
// The HTTP response is JSON decoded and stored in the value pointed by obj.
func (c *Client) makeRequest(ctx context.Context, method, path string, payload, obj interface{}, headers http.Header) (*http.Response, error) {
req, err := c.newRequestWithHeaders(method, path, payload, headers)
if err != nil {
return nil, err
}
if c.Debug {
log.Printf("Request (%v): %#v", req.URL, req)
}
resp, err := c.request(ctx, req, obj)
if err != nil {
return nil, err
}
if c.Debug {
log.Printf("Response: %#v", resp)
}
return resp, nil
}
// newRequest creates an API request.
//
// The path is expected to be a relative path and will be resolved according to the BaseURL of the Client.
// Paths should always be specified without a preceding slash.
func (c *Client) newRequest(method, path string, payload interface{}) (*http.Request, error) {
return c.newRequestWithHeaders(method, path, payload, nil)
}
// newRequestWithHeaders creates an API request, with custom headers.
func (c *Client) newRequestWithHeaders(method, path string, payload interface{}, headers http.Header) (*http.Request, error) {
url := c.BaseURL + path url := c.BaseURL + path
body := new(bytes.Buffer) body := new(bytes.Buffer)
@ -123,91 +216,36 @@ func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Req
return nil, err return nil, err
} }
combinedHeaders := make(http.Header)
copyHeader(combinedHeaders, headers)
req.Header = combinedHeaders
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Add("Accept", "application/json") req.Header.Add("Accept", "application/json")
req.Header.Add("User-Agent", formatUserAgent(c.UserAgent)) req.Header.Add("User-Agent", formatUserAgent(c.UserAgent))
return req, nil return req, err
} }
// formatUserAgent builds the final user agent to use for HTTP requests. // copyHeader copies all headers for `source` and sets them on `target`.
// based on https://godoc.org/github.com/golang/gddo/httputil/header#Copy
func copyHeader(target, source http.Header) {
for k, vs := range source {
target[k] = vs
}
}
// request sends the HTTP request and returns the HTTP response.
// //
// If no custom user agent is provided, the default user agent is used. // The HTTP response is JSON decoded and stored in the value pointed by obj,
//
// dnsimple-go/1.0
//
// If a custom user agent is provided, the final user agent is the combination of the custom user agent
// prepended by the default user agent.
//
// dnsimple-go/1.0 customAgentFlag
//
func formatUserAgent(customUserAgent string) string {
if customUserAgent == "" {
return defaultUserAgent
}
return fmt.Sprintf("%s %s", customUserAgent, defaultUserAgent)
}
func versioned(path string) string {
return fmt.Sprintf("/%s/%s", apiVersion, strings.Trim(path, "/"))
}
func (c *Client) get(path string, obj interface{}) (*http.Response, error) {
req, err := c.NewRequest("GET", path, nil)
if err != nil {
return nil, err
}
return c.Do(req, obj)
}
func (c *Client) post(path string, payload, obj interface{}) (*http.Response, error) {
req, err := c.NewRequest("POST", path, payload)
if err != nil {
return nil, err
}
return c.Do(req, obj)
}
func (c *Client) put(path string, payload, obj interface{}) (*http.Response, error) {
req, err := c.NewRequest("PUT", path, payload)
if err != nil {
return nil, err
}
return c.Do(req, obj)
}
func (c *Client) patch(path string, payload, obj interface{}) (*http.Response, error) {
req, err := c.NewRequest("PATCH", path, payload)
if err != nil {
return nil, err
}
return c.Do(req, obj)
}
func (c *Client) delete(path string, payload interface{}, obj interface{}) (*http.Response, error) {
req, err := c.NewRequest("DELETE", path, payload)
if err != nil {
return nil, err
}
return c.Do(req, obj)
}
// Do sends an API request and returns the API response.
//
// The API response is JSON decoded and stored in the value pointed by obj,
// or returned as an error if an API error has occurred. // or returned as an error if an API error has occurred.
// If obj implements the io.Writer interface, the raw response body will be written to obj, // If obj implements the io.Writer interface, the raw response body will be written to obj,
// without attempting to decode it. // without attempting to decode it.
func (c *Client) Do(req *http.Request, obj interface{}) (*http.Response, error) { func (c *Client) request(ctx context.Context, req *http.Request, obj interface{}) (*http.Response, error) {
if c.Debug { if ctx == nil {
log.Printf("Executing request (%v): %#v", req.URL, req) return nil, errors.New("context must be non-nil")
} }
req = req.WithContext(ctx)
resp, err := c.httpClient.Do(req) resp, err := c.httpClient.Do(req)
if err != nil { if err != nil {
@ -215,10 +253,6 @@ func (c *Client) Do(req *http.Request, obj interface{}) (*http.Response, error)
} }
defer resp.Body.Close() defer resp.Body.Close()
if c.Debug {
log.Printf("Response received: %#v", resp)
}
err = CheckResponse(resp) err = CheckResponse(resp)
if err != nil { if err != nil {
return resp, err return resp, err
@ -240,7 +274,7 @@ func (c *Client) Do(req *http.Request, obj interface{}) (*http.Response, error)
// A Response represents an API response. // A Response represents an API response.
type Response struct { type Response struct {
// HTTP response // HTTP response
HttpResponse *http.Response HTTPResponse *http.Response
// If the response is paginated, the Pagination will store them. // If the response is paginated, the Pagination will store them.
Pagination *Pagination `json:"pagination"` Pagination *Pagination `json:"pagination"`
@ -248,23 +282,23 @@ type Response struct {
// RateLimit returns the maximum amount of requests this account can send in an hour. // RateLimit returns the maximum amount of requests this account can send in an hour.
func (r *Response) RateLimit() int { func (r *Response) RateLimit() int {
value, _ := strconv.Atoi(r.HttpResponse.Header.Get("X-RateLimit-Limit")) value, _ := strconv.Atoi(r.HTTPResponse.Header.Get("X-RateLimit-Limit"))
return value return value
} }
// RateLimitRemaining returns the remaining amount of requests this account can send within this hour window. // RateLimitRemaining returns the remaining amount of requests this account can send within this hour window.
func (r *Response) RateLimitRemaining() int { func (r *Response) RateLimitRemaining() int {
value, _ := strconv.Atoi(r.HttpResponse.Header.Get("X-RateLimit-Remaining")) value, _ := strconv.Atoi(r.HTTPResponse.Header.Get("X-RateLimit-Remaining"))
return value return value
} }
// RateLimitReset returns when the throttling window will be reset for this account. // RateLimitReset returns when the throttling window will be reset for this account.
func (r *Response) RateLimitReset() time.Time { func (r *Response) RateLimitReset() time.Time {
value, _ := strconv.ParseInt(r.HttpResponse.Header.Get("X-RateLimit-Reset"), 10, 64) value, _ := strconv.ParseInt(r.HTTPResponse.Header.Get("X-RateLimit-Reset"), 10, 64)
return time.Unix(value, 0) return time.Unix(value, 0)
} }
// If the response is paginated, Pagination represents the pagination information. // Pagination represents the pagination information, if the response is paginated.
type Pagination struct { type Pagination struct {
CurrentPage int `json:"current_page"` CurrentPage int `json:"current_page"`
PerPage int `json:"per_page"` PerPage int `json:"per_page"`
@ -283,8 +317,8 @@ type ErrorResponse struct {
// Error implements the error interface. // Error implements the error interface.
func (r *ErrorResponse) Error() string { func (r *ErrorResponse) Error() string {
return fmt.Sprintf("%v %v: %v %v", return fmt.Sprintf("%v %v: %v %v",
r.HttpResponse.Request.Method, r.HttpResponse.Request.URL, r.HTTPResponse.Request.Method, r.HTTPResponse.Request.URL,
r.HttpResponse.StatusCode, r.Message) r.HTTPResponse.StatusCode, r.Message)
} }
// CheckResponse checks the API response for errors, and returns them if present. // CheckResponse checks the API response for errors, and returns them if present.
@ -296,7 +330,7 @@ func CheckResponse(resp *http.Response) error {
} }
errorResponse := &ErrorResponse{} errorResponse := &ErrorResponse{}
errorResponse.HttpResponse = resp errorResponse.HTTPResponse = resp
err := json.NewDecoder(resp.Body).Decode(errorResponse) err := json.NewDecoder(resp.Body).Decode(errorResponse)
if err != nil { if err != nil {
@ -329,10 +363,22 @@ func addURLQueryOptions(path string, options interface{}) (string, error) {
} }
uqs := u.Query() uqs := u.Query()
for k, _ := range qs { for k := range qs {
uqs.Set(k, qs.Get(k)) uqs.Set(k, qs.Get(k))
} }
u.RawQuery = uqs.Encode() u.RawQuery = uqs.Encode()
return u.String(), nil return u.String(), nil
} }
// Int is a helper routine that allocates a new int value
// to store v and returns a pointer to it.
func Int(v int) *int { return &v }
// Int64 is a helper routine that allocates a new int64 value
// to store v and returns a pointer to it.
func Int64(v int64) *int64 { return &v }
// String is a helper routine that allocates a new string value
// to store v and returns a pointer to it.
func String(v string) *string { return &v }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -36,14 +37,14 @@ func domainPath(accountID string, domainIdentifier string) (path string) {
return return
} }
// domainResponse represents a response from an API method that returns a Domain struct. // DomainResponse represents a response from an API method that returns a Domain struct.
type domainResponse struct { type DomainResponse struct {
Response Response
Data *Domain `json:"data"` Data *Domain `json:"data"`
} }
// domainsResponse represents a response from an API method that returns a collection of Domain struct. // DomainsResponse represents a response from an API method that returns a collection of Domain struct.
type domainsResponse struct { type DomainsResponse struct {
Response Response
Data []Domain `json:"data"` Data []Domain `json:"data"`
} }
@ -52,10 +53,10 @@ type domainsResponse struct {
// to customize the DomainsService.ListDomains method. // to customize the DomainsService.ListDomains method.
type DomainListOptions struct { type DomainListOptions struct {
// Select domains where the name contains given string. // Select domains where the name contains given string.
NameLike string `url:"name_like,omitempty"` NameLike *string `url:"name_like,omitempty"`
// Select domains where the registrant matches given ID. // Select domains where the registrant matches given ID.
RegistrantID int `url:"registrant_id,omitempty"` RegistrantID *int `url:"registrant_id,omitempty"`
ListOptions ListOptions
} }
@ -63,76 +64,68 @@ type DomainListOptions struct {
// ListDomains lists the domains for an account. // ListDomains lists the domains for an account.
// //
// See https://developer.dnsimple.com/v2/domains/#list // See https://developer.dnsimple.com/v2/domains/#list
func (s *DomainsService) ListDomains(accountID string, options *DomainListOptions) (*domainsResponse, error) { func (s *DomainsService) ListDomains(ctx context.Context, accountID string, options *DomainListOptions) (*DomainsResponse, error) {
path := versioned(domainPath(accountID, "")) path := versioned(domainPath(accountID, ""))
domainsResponse := &domainsResponse{} domainsResponse := &DomainsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, domainsResponse) resp, err := s.client.get(ctx, path, domainsResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
domainsResponse.HttpResponse = resp domainsResponse.HTTPResponse = resp
return domainsResponse, nil return domainsResponse, nil
} }
// CreateDomain creates a new domain in the account. // CreateDomain creates a new domain in the account.
// //
// See https://developer.dnsimple.com/v2/domains/#create // See https://developer.dnsimple.com/v2/domains/#create
func (s *DomainsService) CreateDomain(accountID string, domainAttributes Domain) (*domainResponse, error) { func (s *DomainsService) CreateDomain(ctx context.Context, accountID string, domainAttributes Domain) (*DomainResponse, error) {
path := versioned(domainPath(accountID, "")) path := versioned(domainPath(accountID, ""))
domainResponse := &domainResponse{} domainResponse := &DomainResponse{}
resp, err := s.client.post(path, domainAttributes, domainResponse) resp, err := s.client.post(ctx, path, domainAttributes, domainResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
domainResponse.HttpResponse = resp domainResponse.HTTPResponse = resp
return domainResponse, nil return domainResponse, nil
} }
// GetDomain fetches a domain. // GetDomain fetches a domain.
// //
// See https://developer.dnsimple.com/v2/domains/#get // See https://developer.dnsimple.com/v2/domains/#get
func (s *DomainsService) GetDomain(accountID string, domainIdentifier string) (*domainResponse, error) { func (s *DomainsService) GetDomain(ctx context.Context, accountID string, domainIdentifier string) (*DomainResponse, error) {
path := versioned(domainPath(accountID, domainIdentifier)) path := versioned(domainPath(accountID, domainIdentifier))
domainResponse := &domainResponse{} domainResponse := &DomainResponse{}
resp, err := s.client.get(path, domainResponse) resp, err := s.client.get(ctx, path, domainResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
domainResponse.HttpResponse = resp domainResponse.HTTPResponse = resp
return domainResponse, nil return domainResponse, nil
} }
// DeleteDomain PERMANENTLY deletes a domain from the account. // DeleteDomain PERMANENTLY deletes a domain from the account.
// //
// See https://developer.dnsimple.com/v2/domains/#delete // See https://developer.dnsimple.com/v2/domains/#delete
func (s *DomainsService) DeleteDomain(accountID string, domainIdentifier string) (*domainResponse, error) { func (s *DomainsService) DeleteDomain(ctx context.Context, accountID string, domainIdentifier string) (*DomainResponse, error) {
path := versioned(domainPath(accountID, domainIdentifier)) path := versioned(domainPath(accountID, domainIdentifier))
domainResponse := &domainResponse{} domainResponse := &DomainResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
domainResponse.HttpResponse = resp domainResponse.HTTPResponse = resp
return domainResponse, nil return domainResponse, nil
} }
// DEPRECATED
//
// See https://developer.dnsimple.com/v2/domains/#reset-token
func (s *DomainsService) ResetDomainToken(accountID string, domainIdentifier string) (*domainResponse, error) {
// noop
return &domainResponse{}, nil
}

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -30,14 +31,14 @@ type CollaboratorAttributes struct {
Email string `json:"email,omitempty"` Email string `json:"email,omitempty"`
} }
// collaboratorResponse represents a response from an API method that returns a Collaborator struct. // CollaboratorResponse represents a response from an API method that returns a Collaborator struct.
type collaboratorResponse struct { type CollaboratorResponse struct {
Response Response
Data *Collaborator `json:"data"` Data *Collaborator `json:"data"`
} }
// collaboratorsResponse represents a response from an API method that returns a collection of Collaborator struct. // CollaboratorsResponse represents a response from an API method that returns a collection of Collaborator struct.
type collaboratorsResponse struct { type CollaboratorsResponse struct {
Response Response
Data []Collaborator `json:"data"` Data []Collaborator `json:"data"`
} }
@ -45,52 +46,52 @@ type collaboratorsResponse struct {
// ListCollaborators list the collaborators for a domain. // ListCollaborators list the collaborators for a domain.
// //
// See https://developer.dnsimple.com/v2/domains/collaborators#list // See https://developer.dnsimple.com/v2/domains/collaborators#list
func (s *DomainsService) ListCollaborators(accountID, domainIdentifier string, options *ListOptions) (*collaboratorsResponse, error) { func (s *DomainsService) ListCollaborators(ctx context.Context, accountID, domainIdentifier string, options *ListOptions) (*CollaboratorsResponse, error) {
path := versioned(collaboratorPath(accountID, domainIdentifier, 0)) path := versioned(collaboratorPath(accountID, domainIdentifier, 0))
collaboratorsResponse := &collaboratorsResponse{} collaboratorsResponse := &CollaboratorsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, collaboratorsResponse) resp, err := s.client.get(ctx, path, collaboratorsResponse)
if err != nil { if err != nil {
return collaboratorsResponse, err return collaboratorsResponse, err
} }
collaboratorsResponse.HttpResponse = resp collaboratorsResponse.HTTPResponse = resp
return collaboratorsResponse, nil return collaboratorsResponse, nil
} }
// AddCollaborator adds a new collaborator to the domain in the account. // AddCollaborator adds a new collaborator to the domain in the account.
// //
// See https://developer.dnsimple.com/v2/domains/collaborators#add // See https://developer.dnsimple.com/v2/domains/collaborators#add
func (s *DomainsService) AddCollaborator(accountID string, domainIdentifier string, attributes CollaboratorAttributes) (*collaboratorResponse, error) { func (s *DomainsService) AddCollaborator(ctx context.Context, accountID string, domainIdentifier string, attributes CollaboratorAttributes) (*CollaboratorResponse, error) {
path := versioned(collaboratorPath(accountID, domainIdentifier, 0)) path := versioned(collaboratorPath(accountID, domainIdentifier, 0))
collaboratorResponse := &collaboratorResponse{} collaboratorResponse := &CollaboratorResponse{}
resp, err := s.client.post(path, attributes, collaboratorResponse) resp, err := s.client.post(ctx, path, attributes, collaboratorResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
collaboratorResponse.HttpResponse = resp collaboratorResponse.HTTPResponse = resp
return collaboratorResponse, nil return collaboratorResponse, nil
} }
// RemoveCollaborator PERMANENTLY deletes a domain from the account. // RemoveCollaborator PERMANENTLY deletes a domain from the account.
// //
// See https://developer.dnsimple.com/v2/domains/collaborators#remove // See https://developer.dnsimple.com/v2/domains/collaborators#remove
func (s *DomainsService) RemoveCollaborator(accountID string, domainIdentifier string, collaboratorID int64) (*collaboratorResponse, error) { func (s *DomainsService) RemoveCollaborator(ctx context.Context, accountID string, domainIdentifier string, collaboratorID int64) (*CollaboratorResponse, error) {
path := versioned(collaboratorPath(accountID, domainIdentifier, collaboratorID)) path := versioned(collaboratorPath(accountID, domainIdentifier, collaboratorID))
collaboratorResponse := &collaboratorResponse{} collaboratorResponse := &CollaboratorResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
collaboratorResponse.HttpResponse = resp collaboratorResponse.HTTPResponse = resp
return collaboratorResponse, nil return collaboratorResponse, nil
} }

View File

@ -1,6 +1,9 @@
package dnsimple package dnsimple
import "fmt" import (
"context"
"fmt"
)
// DelegationSignerRecord represents a delegation signer record for a domain in DNSimple. // DelegationSignerRecord represents a delegation signer record for a domain in DNSimple.
type DelegationSignerRecord struct { type DelegationSignerRecord struct {
@ -22,14 +25,14 @@ func delegationSignerRecordPath(accountID string, domainIdentifier string, dsRec
return return
} }
// delegationSignerRecordResponse represents a response from an API method that returns a DelegationSignerRecord struct. // DelegationSignerRecordResponse represents a response from an API method that returns a DelegationSignerRecord struct.
type delegationSignerRecordResponse struct { type DelegationSignerRecordResponse struct {
Response Response
Data *DelegationSignerRecord `json:"data"` Data *DelegationSignerRecord `json:"data"`
} }
// delegationSignerRecordResponse represents a response from an API method that returns a DelegationSignerRecord struct. // DelegationSignerRecordsResponse represents a response from an API method that returns a DelegationSignerRecord struct.
type delegationSignerRecordsResponse struct { type DelegationSignerRecordsResponse struct {
Response Response
Data []DelegationSignerRecord `json:"data"` Data []DelegationSignerRecord `json:"data"`
} }
@ -37,53 +40,53 @@ type delegationSignerRecordsResponse struct {
// ListDelegationSignerRecords lists the delegation signer records for a domain. // ListDelegationSignerRecords lists the delegation signer records for a domain.
// //
// See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-list // See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-list
func (s *DomainsService) ListDelegationSignerRecords(accountID string, domainIdentifier string, options *ListOptions) (*delegationSignerRecordsResponse, error) { func (s *DomainsService) ListDelegationSignerRecords(ctx context.Context, accountID string, domainIdentifier string, options *ListOptions) (*DelegationSignerRecordsResponse, error) {
path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, 0)) path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, 0))
dsRecordsResponse := &delegationSignerRecordsResponse{} dsRecordsResponse := &DelegationSignerRecordsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, dsRecordsResponse) resp, err := s.client.get(ctx, path, dsRecordsResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dsRecordsResponse.HttpResponse = resp dsRecordsResponse.HTTPResponse = resp
return dsRecordsResponse, nil return dsRecordsResponse, nil
} }
// CreateDelegationSignerRecord creates a new delegation signer record. // CreateDelegationSignerRecord creates a new delegation signer record.
// //
// See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-create // See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-create
func (s *DomainsService) CreateDelegationSignerRecord(accountID string, domainIdentifier string, dsRecordAttributes DelegationSignerRecord) (*delegationSignerRecordResponse, error) { func (s *DomainsService) CreateDelegationSignerRecord(ctx context.Context, accountID string, domainIdentifier string, dsRecordAttributes DelegationSignerRecord) (*DelegationSignerRecordResponse, error) {
path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, 0)) path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, 0))
dsRecordResponse := &delegationSignerRecordResponse{} dsRecordResponse := &DelegationSignerRecordResponse{}
resp, err := s.client.post(path, dsRecordAttributes, dsRecordResponse) resp, err := s.client.post(ctx, path, dsRecordAttributes, dsRecordResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dsRecordResponse.HttpResponse = resp dsRecordResponse.HTTPResponse = resp
return dsRecordResponse, nil return dsRecordResponse, nil
} }
// GetDelegationSignerRecord fetches a delegation signer record. // GetDelegationSignerRecord fetches a delegation signer record.
// //
// See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-get // See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-get
func (s *DomainsService) GetDelegationSignerRecord(accountID string, domainIdentifier string, dsRecordID int64) (*delegationSignerRecordResponse, error) { func (s *DomainsService) GetDelegationSignerRecord(ctx context.Context, accountID string, domainIdentifier string, dsRecordID int64) (*DelegationSignerRecordResponse, error) {
path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, dsRecordID)) path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, dsRecordID))
dsRecordResponse := &delegationSignerRecordResponse{} dsRecordResponse := &DelegationSignerRecordResponse{}
resp, err := s.client.get(path, dsRecordResponse) resp, err := s.client.get(ctx, path, dsRecordResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dsRecordResponse.HttpResponse = resp dsRecordResponse.HTTPResponse = resp
return dsRecordResponse, nil return dsRecordResponse, nil
} }
@ -91,15 +94,15 @@ func (s *DomainsService) GetDelegationSignerRecord(accountID string, domainIdent
// from the domain. // from the domain.
// //
// See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-delete // See https://developer.dnsimple.com/v2/domains/dnssec/#ds-record-delete
func (s *DomainsService) DeleteDelegationSignerRecord(accountID string, domainIdentifier string, dsRecordID int64) (*delegationSignerRecordResponse, error) { func (s *DomainsService) DeleteDelegationSignerRecord(ctx context.Context, accountID string, domainIdentifier string, dsRecordID int64) (*DelegationSignerRecordResponse, error) {
path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, dsRecordID)) path := versioned(delegationSignerRecordPath(accountID, domainIdentifier, dsRecordID))
dsRecordResponse := &delegationSignerRecordResponse{} dsRecordResponse := &DelegationSignerRecordResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dsRecordResponse.HttpResponse = resp dsRecordResponse.HTTPResponse = resp
return dsRecordResponse, nil return dsRecordResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -14,57 +15,56 @@ func dnssecPath(accountID string, domainIdentifier string) (path string) {
return return
} }
// dnssecResponse represents a response from an API method that returns a Dnssec struct. // DnssecResponse represents a response from an API method that returns a Dnssec struct.
type dnssecResponse struct { type DnssecResponse struct {
Response Response
Data *Dnssec `json:"data"` Data *Dnssec `json:"data"`
} }
// EnableDnssec enables DNSSEC on the domain. // EnableDnssec enables DNSSEC on the domain.
// //
// See https://developer.dnsimple.com/v2/domains/dnssec/#enable // See https://developer.dnsimple.com/v2/domains/dnssec/#enableDomainDnssec
func (s *DomainsService) EnableDnssec(ctx context.Context, accountID string, domainIdentifier string) (*DnssecResponse, error) {
func (s *DomainsService) EnableDnssec(accountID string, domainIdentifier string) (*dnssecResponse, error) {
path := versioned(dnssecPath(accountID, domainIdentifier)) path := versioned(dnssecPath(accountID, domainIdentifier))
dnssecResponse := &dnssecResponse{} dnssecResponse := &DnssecResponse{}
resp, err := s.client.post(path, dnssecResponse, nil) resp, err := s.client.post(ctx, path, dnssecResponse, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dnssecResponse.HttpResponse = resp dnssecResponse.HTTPResponse = resp
return dnssecResponse, nil return dnssecResponse, nil
} }
// DisableDnssec disables DNSSEC on the domain. // DisableDnssec disables DNSSEC on the domain.
// //
// See https://developer.dnsimple.com/v2/domains/dnssec/#disable // See https://developer.dnsimple.com/v2/domains/dnssec/#disableDomainDnssec
func (s *DomainsService) DisableDnssec(accountID string, domainIdentifier string) (*dnssecResponse, error) { func (s *DomainsService) DisableDnssec(ctx context.Context, accountID string, domainIdentifier string) (*DnssecResponse, error) {
path := versioned(dnssecPath(accountID, domainIdentifier)) path := versioned(dnssecPath(accountID, domainIdentifier))
dnssecResponse := &dnssecResponse{} dnssecResponse := &DnssecResponse{}
resp, err := s.client.delete(path, dnssecResponse, nil) resp, err := s.client.delete(ctx, path, dnssecResponse, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dnssecResponse.HttpResponse = resp dnssecResponse.HTTPResponse = resp
return dnssecResponse, nil return dnssecResponse, nil
} }
// GetDnssec retrieves the current status of DNSSEC on the domain. // GetDnssec retrieves the current status of DNSSEC on the domain.
// //
// See https://developer.dnsimple.com/v2/domains/dnssec/#get // See https://developer.dnsimple.com/v2/domains/dnssec/#getDomainDnssec
func (s *DomainsService) GetDnssec(accountID string, domainIdentifier string) (*dnssecResponse, error) { func (s *DomainsService) GetDnssec(ctx context.Context, accountID string, domainIdentifier string) (*DnssecResponse, error) {
path := versioned(dnssecPath(accountID, domainIdentifier)) path := versioned(dnssecPath(accountID, domainIdentifier))
dnssecResponse := &dnssecResponse{} dnssecResponse := &DnssecResponse{}
resp, err := s.client.get(path, dnssecResponse) resp, err := s.client.get(ctx, path, dnssecResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dnssecResponse.HttpResponse = resp dnssecResponse.HTTPResponse = resp
return dnssecResponse, nil return dnssecResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -22,14 +23,14 @@ func emailForwardPath(accountID string, domainIdentifier string, forwardID int64
return return
} }
// emailForwardResponse represents a response from an API method that returns an EmailForward struct. // EmailForwardResponse represents a response from an API method that returns an EmailForward struct.
type emailForwardResponse struct { type EmailForwardResponse struct {
Response Response
Data *EmailForward `json:"data"` Data *EmailForward `json:"data"`
} }
// emailForwardsResponse represents a response from an API method that returns a collection of EmailForward struct. // EmailForwardsResponse represents a response from an API method that returns a collection of EmailForward struct.
type emailForwardsResponse struct { type EmailForwardsResponse struct {
Response Response
Data []EmailForward `json:"data"` Data []EmailForward `json:"data"`
} }
@ -37,68 +38,68 @@ type emailForwardsResponse struct {
// ListEmailForwards lists the email forwards for a domain. // ListEmailForwards lists the email forwards for a domain.
// //
// See https://developer.dnsimple.com/v2/domains/email-forwards/#list // See https://developer.dnsimple.com/v2/domains/email-forwards/#list
func (s *DomainsService) ListEmailForwards(accountID string, domainIdentifier string, options *ListOptions) (*emailForwardsResponse, error) { func (s *DomainsService) ListEmailForwards(ctx context.Context, accountID string, domainIdentifier string, options *ListOptions) (*EmailForwardsResponse, error) {
path := versioned(emailForwardPath(accountID, domainIdentifier, 0)) path := versioned(emailForwardPath(accountID, domainIdentifier, 0))
forwardsResponse := &emailForwardsResponse{} forwardsResponse := &EmailForwardsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, forwardsResponse) resp, err := s.client.get(ctx, path, forwardsResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
forwardsResponse.HttpResponse = resp forwardsResponse.HTTPResponse = resp
return forwardsResponse, nil return forwardsResponse, nil
} }
// CreateEmailForward creates a new email forward. // CreateEmailForward creates a new email forward.
// //
// See https://developer.dnsimple.com/v2/domains/email-forwards/#create // See https://developer.dnsimple.com/v2/domains/email-forwards/#create
func (s *DomainsService) CreateEmailForward(accountID string, domainIdentifier string, forwardAttributes EmailForward) (*emailForwardResponse, error) { func (s *DomainsService) CreateEmailForward(ctx context.Context, accountID string, domainIdentifier string, forwardAttributes EmailForward) (*EmailForwardResponse, error) {
path := versioned(emailForwardPath(accountID, domainIdentifier, 0)) path := versioned(emailForwardPath(accountID, domainIdentifier, 0))
forwardResponse := &emailForwardResponse{} forwardResponse := &EmailForwardResponse{}
resp, err := s.client.post(path, forwardAttributes, forwardResponse) resp, err := s.client.post(ctx, path, forwardAttributes, forwardResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
forwardResponse.HttpResponse = resp forwardResponse.HTTPResponse = resp
return forwardResponse, nil return forwardResponse, nil
} }
// GetEmailForward fetches an email forward. // GetEmailForward fetches an email forward.
// //
// See https://developer.dnsimple.com/v2/domains/email-forwards/#get // See https://developer.dnsimple.com/v2/domains/email-forwards/#get
func (s *DomainsService) GetEmailForward(accountID string, domainIdentifier string, forwardID int64) (*emailForwardResponse, error) { func (s *DomainsService) GetEmailForward(ctx context.Context, accountID string, domainIdentifier string, forwardID int64) (*EmailForwardResponse, error) {
path := versioned(emailForwardPath(accountID, domainIdentifier, forwardID)) path := versioned(emailForwardPath(accountID, domainIdentifier, forwardID))
forwardResponse := &emailForwardResponse{} forwardResponse := &EmailForwardResponse{}
resp, err := s.client.get(path, forwardResponse) resp, err := s.client.get(ctx, path, forwardResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
forwardResponse.HttpResponse = resp forwardResponse.HTTPResponse = resp
return forwardResponse, nil return forwardResponse, nil
} }
// DeleteEmailForward PERMANENTLY deletes an email forward from the domain. // DeleteEmailForward PERMANENTLY deletes an email forward from the domain.
// //
// See https://developer.dnsimple.com/v2/domains/email-forwards/#delete // See https://developer.dnsimple.com/v2/domains/email-forwards/#delete
func (s *DomainsService) DeleteEmailForward(accountID string, domainIdentifier string, forwardID int64) (*emailForwardResponse, error) { func (s *DomainsService) DeleteEmailForward(ctx context.Context, accountID string, domainIdentifier string, forwardID int64) (*EmailForwardResponse, error) {
path := versioned(emailForwardPath(accountID, domainIdentifier, forwardID)) path := versioned(emailForwardPath(accountID, domainIdentifier, forwardID))
forwardResponse := &emailForwardResponse{} forwardResponse := &EmailForwardResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
forwardResponse.HttpResponse = resp forwardResponse.HTTPResponse = resp
return forwardResponse, nil return forwardResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -23,14 +24,14 @@ func domainPushPath(accountID string, pushID int64) (path string) {
return return
} }
// domainPushResponse represents a response from an API method that returns a DomainPush struct. // DomainPushResponse represents a response from an API method that returns a DomainPush struct.
type domainPushResponse struct { type DomainPushResponse struct {
Response Response
Data *DomainPush `json:"data"` Data *DomainPush `json:"data"`
} }
// domainPushesResponse represents a response from an API method that returns a collection of DomainPush struct. // DomainPushesResponse represents a response from an API method that returns a collection of DomainPush struct.
type domainPushesResponse struct { type DomainPushesResponse struct {
Response Response
Data []DomainPush `json:"data"` Data []DomainPush `json:"data"`
} }
@ -43,69 +44,69 @@ type DomainPushAttributes struct {
// InitiatePush initiate a new domain push. // InitiatePush initiate a new domain push.
// //
// See https://developer.dnsimple.com/v2/domains/pushes/#initiate // See https://developer.dnsimple.com/v2/domains/pushes/#initiateDomainPush
func (s *DomainsService) InitiatePush(accountID, domainID string, pushAttributes DomainPushAttributes) (*domainPushResponse, error) { func (s *DomainsService) InitiatePush(ctx context.Context, accountID, domainID string, pushAttributes DomainPushAttributes) (*DomainPushResponse, error) {
path := versioned(fmt.Sprintf("/%v/pushes", domainPath(accountID, domainID))) path := versioned(fmt.Sprintf("/%v/pushes", domainPath(accountID, domainID)))
pushResponse := &domainPushResponse{} pushResponse := &DomainPushResponse{}
resp, err := s.client.post(path, pushAttributes, pushResponse) resp, err := s.client.post(ctx, path, pushAttributes, pushResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pushResponse.HttpResponse = resp pushResponse.HTTPResponse = resp
return pushResponse, nil return pushResponse, nil
} }
// ListPushes lists the pushes for an account. // ListPushes lists the pushes for an account.
// //
// See https://developer.dnsimple.com/v2/domains/pushes/#list // See https://developer.dnsimple.com/v2/domains/pushes/#listPushes
func (s *DomainsService) ListPushes(accountID string, options *ListOptions) (*domainPushesResponse, error) { func (s *DomainsService) ListPushes(ctx context.Context, accountID string, options *ListOptions) (*DomainPushesResponse, error) {
path := versioned(domainPushPath(accountID, 0)) path := versioned(domainPushPath(accountID, 0))
pushesResponse := &domainPushesResponse{} pushesResponse := &DomainPushesResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, pushesResponse) resp, err := s.client.get(ctx, path, pushesResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pushesResponse.HttpResponse = resp pushesResponse.HTTPResponse = resp
return pushesResponse, nil return pushesResponse, nil
} }
// AcceptPush accept a push for a domain. // AcceptPush accept a push for a domain.
// //
// See https://developer.dnsimple.com/v2/domains/pushes/#accept // See https://developer.dnsimple.com/v2/domains/pushes/#acceptPush
func (s *DomainsService) AcceptPush(accountID string, pushID int64, pushAttributes DomainPushAttributes) (*domainPushResponse, error) { func (s *DomainsService) AcceptPush(ctx context.Context, accountID string, pushID int64, pushAttributes DomainPushAttributes) (*DomainPushResponse, error) {
path := versioned(domainPushPath(accountID, pushID)) path := versioned(domainPushPath(accountID, pushID))
pushResponse := &domainPushResponse{} pushResponse := &DomainPushResponse{}
resp, err := s.client.post(path, pushAttributes, nil) resp, err := s.client.post(ctx, path, pushAttributes, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pushResponse.HttpResponse = resp pushResponse.HTTPResponse = resp
return pushResponse, nil return pushResponse, nil
} }
// RejectPush reject a push for a domain. // RejectPush reject a push for a domain.
// //
// See https://developer.dnsimple.com/v2/domains/pushes/#reject // See https://developer.dnsimple.com/v2/domains/pushes/#rejectPush
func (s *DomainsService) RejectPush(accountID string, pushID int64) (*domainPushResponse, error) { func (s *DomainsService) RejectPush(ctx context.Context, accountID string, pushID int64) (*DomainPushResponse, error) {
path := versioned(domainPushPath(accountID, pushID)) path := versioned(domainPushPath(accountID, pushID))
pushResponse := &domainPushResponse{} pushResponse := &DomainPushResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pushResponse.HttpResponse = resp pushResponse.HTTPResponse = resp
return pushResponse, nil return pushResponse, nil
} }

View File

@ -1,5 +1,9 @@
package dnsimple package dnsimple
import (
"context"
)
// IdentityService handles communication with several authentication identity // IdentityService handles communication with several authentication identity
// methods of the DNSimple API. // methods of the DNSimple API.
// //
@ -15,8 +19,8 @@ type WhoamiData struct {
Account *Account `json:"account,omitempty"` Account *Account `json:"account,omitempty"`
} }
// whoamiResponse represents a response from an API method that returns a Whoami struct. // WhoamiResponse represents a response from an API method that returns a Whoami struct.
type whoamiResponse struct { type WhoamiResponse struct {
Response Response
Data *WhoamiData `json:"data"` Data *WhoamiData `json:"data"`
} }
@ -24,23 +28,22 @@ type whoamiResponse struct {
// Whoami gets the current authenticate context. // Whoami gets the current authenticate context.
// //
// See https://developer.dnsimple.com/v2/whoami // See https://developer.dnsimple.com/v2/whoami
func (s *IdentityService) Whoami() (*whoamiResponse, error) { func (s *IdentityService) Whoami(ctx context.Context) (*WhoamiResponse, error) {
path := versioned("/whoami") path := versioned("/whoami")
whoamiResponse := &whoamiResponse{} whoamiResponse := &WhoamiResponse{}
resp, err := s.client.get(path, whoamiResponse) resp, err := s.client.get(ctx, path, whoamiResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
whoamiResponse.HttpResponse = resp whoamiResponse.HTTPResponse = resp
return whoamiResponse, nil return whoamiResponse, nil
} }
// Whoami is a state-less shortcut to client.Whoami() // Whoami is a state-less shortcut to client.Whoami() that returns only the relevant Data.
// that returns only the relevant Data. func Whoami(ctx context.Context, c *Client) (data *WhoamiData, err error) {
func Whoami(c *Client) (data *WhoamiData, err error) { resp, err := c.Identity.Whoami(ctx)
resp, err := c.Identity.Whoami()
if resp != nil { if resp != nil {
data = resp.Data data = resp.Data
} }

View File

@ -49,7 +49,7 @@ type ExchangeAuthorizationRequest struct {
// an authorization code for an access token. // an authorization code for an access token.
type ExchangeAuthorizationError struct { type ExchangeAuthorizationError struct {
// HTTP response // HTTP response
HttpResponse *http.Response HTTPResponse *http.Response
ErrorCode string `json:"error"` ErrorCode string `json:"error"`
ErrorDescription string `json:"error_description"` ErrorDescription string `json:"error_description"`
@ -58,7 +58,7 @@ type ExchangeAuthorizationError struct {
// Error implements the error interface. // Error implements the error interface.
func (r *ExchangeAuthorizationError) Error() string { func (r *ExchangeAuthorizationError) Error() string {
return fmt.Sprintf("%v %v: %v %v", return fmt.Sprintf("%v %v: %v %v",
r.HttpResponse.Request.Method, r.HttpResponse.Request.URL, r.HTTPResponse.Request.Method, r.HTTPResponse.Request.URL,
r.ErrorCode, r.ErrorDescription) r.ErrorCode, r.ErrorDescription)
} }
@ -67,7 +67,7 @@ func (r *ExchangeAuthorizationError) Error() string {
func (s *OauthService) ExchangeAuthorizationForToken(authorization *ExchangeAuthorizationRequest) (*AccessToken, error) { func (s *OauthService) ExchangeAuthorizationForToken(authorization *ExchangeAuthorizationRequest) (*AccessToken, error) {
path := versioned("/oauth/access_token") path := versioned("/oauth/access_token")
req, err := s.client.NewRequest("POST", path, authorization) req, err := s.client.newRequest("POST", path, authorization)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -80,8 +80,11 @@ func (s *OauthService) ExchangeAuthorizationForToken(authorization *ExchangeAuth
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
errorResponse := &ExchangeAuthorizationError{} errorResponse := &ExchangeAuthorizationError{}
errorResponse.HttpResponse = resp err = json.NewDecoder(resp.Body).Decode(errorResponse)
json.NewDecoder(resp.Body).Decode(errorResponse) if err != nil {
return nil, err
}
errorResponse.HTTPResponse = resp
return nil, errorResponse return nil, errorResponse
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -19,8 +20,8 @@ type DomainCheck struct {
Premium bool `json:"premium"` Premium bool `json:"premium"`
} }
// domainCheckResponse represents a response from a domain check request. // DomainCheckResponse represents a response from a domain check request.
type domainCheckResponse struct { type DomainCheckResponse struct {
Response Response
Data *DomainCheck `json:"data"` Data *DomainCheck `json:"data"`
} }
@ -28,16 +29,16 @@ type domainCheckResponse struct {
// CheckDomain checks a domain name. // CheckDomain checks a domain name.
// //
// See https://developer.dnsimple.com/v2/registrar/#check // See https://developer.dnsimple.com/v2/registrar/#check
func (s *RegistrarService) CheckDomain(accountID string, domainName string) (*domainCheckResponse, error) { func (s *RegistrarService) CheckDomain(ctx context.Context, accountID string, domainName string) (*DomainCheckResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/check", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/check", accountID, domainName))
checkResponse := &domainCheckResponse{} checkResponse := &DomainCheckResponse{}
resp, err := s.client.get(path, checkResponse) resp, err := s.client.get(ctx, path, checkResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
checkResponse.HttpResponse = resp checkResponse.HTTPResponse = resp
return checkResponse, nil return checkResponse, nil
} }
@ -50,8 +51,8 @@ type DomainPremiumPrice struct {
Action string `json:"action"` Action string `json:"action"`
} }
// domainPremiumPriceResponse represents a response from a domain premium price request. // DomainPremiumPriceResponse represents a response from a domain premium price request.
type domainPremiumPriceResponse struct { type DomainPremiumPriceResponse struct {
Response Response
Data *DomainPremiumPrice `json:"data"` Data *DomainPremiumPrice `json:"data"`
} }
@ -70,10 +71,10 @@ type DomainPremiumPriceOptions struct {
// - renewal // - renewal
// //
// See https://developer.dnsimple.com/v2/registrar/#premium-price // See https://developer.dnsimple.com/v2/registrar/#premium-price
func (s *RegistrarService) GetDomainPremiumPrice(accountID string, domainName string, options *DomainPremiumPriceOptions) (*domainPremiumPriceResponse, error) { func (s *RegistrarService) GetDomainPremiumPrice(ctx context.Context, accountID string, domainName string, options *DomainPremiumPriceOptions) (*DomainPremiumPriceResponse, error) {
var err error var err error
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/premium_price", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/premium_price", accountID, domainName))
priceResponse := &domainPremiumPriceResponse{} priceResponse := &DomainPremiumPriceResponse{}
if options != nil { if options != nil {
path, err = addURLQueryOptions(path, options) path, err = addURLQueryOptions(path, options)
@ -82,12 +83,12 @@ func (s *RegistrarService) GetDomainPremiumPrice(accountID string, domainName st
} }
} }
resp, err := s.client.get(path, priceResponse) resp, err := s.client.get(ctx, path, priceResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
priceResponse.HttpResponse = resp priceResponse.HTTPResponse = resp
return priceResponse, nil return priceResponse, nil
} }
@ -104,15 +105,15 @@ type DomainRegistration struct {
UpdatedAt string `json:"updated_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"`
} }
// domainRegistrationResponse represents a response from an API method that results in a domain registration. // DomainRegistrationResponse represents a response from an API method that results in a domain registration.
type domainRegistrationResponse struct { type DomainRegistrationResponse struct {
Response Response
Data *DomainRegistration `json:"data"` Data *DomainRegistration `json:"data"`
} }
// DomainRegisterRequest represents the attributes you can pass to a register API request. // RegisterDomainInput represents the attributes you can pass to a register API request.
// Some attributes are mandatory. // Some attributes are mandatory.
type DomainRegisterRequest struct { type RegisterDomainInput struct {
// The ID of the Contact to use as registrant for the domain // The ID of the Contact to use as registrant for the domain
RegistrantID int `json:"registrant_id"` RegistrantID int `json:"registrant_id"`
// Set to true to enable the whois privacy service. An extra cost may apply. // Set to true to enable the whois privacy service. An extra cost may apply.
@ -121,6 +122,8 @@ type DomainRegisterRequest struct {
// Set to true to enable the auto-renewal of the domain. // Set to true to enable the auto-renewal of the domain.
// Default to true. // Default to true.
EnableAutoRenewal bool `json:"auto_renew,omitempty"` EnableAutoRenewal bool `json:"auto_renew,omitempty"`
// Required by some TLDs. Use Tlds.GetTldExtendedAttributes() to get the required entries.
ExtendedAttributes map[string]string `json:"extended_attributes,omitempty"`
// Required as confirmation of the price, only if the domain is premium. // Required as confirmation of the price, only if the domain is premium.
PremiumPrice string `json:"premium_price,omitempty"` PremiumPrice string `json:"premium_price,omitempty"`
} }
@ -128,18 +131,18 @@ type DomainRegisterRequest struct {
// RegisterDomain registers a domain name. // RegisterDomain registers a domain name.
// //
// See https://developer.dnsimple.com/v2/registrar/#register // See https://developer.dnsimple.com/v2/registrar/#register
func (s *RegistrarService) RegisterDomain(accountID string, domainName string, request *DomainRegisterRequest) (*domainRegistrationResponse, error) { func (s *RegistrarService) RegisterDomain(ctx context.Context, accountID string, domainName string, input *RegisterDomainInput) (*DomainRegistrationResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/registrations", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/registrations", accountID, domainName))
registrationResponse := &domainRegistrationResponse{} registrationResponse := &DomainRegistrationResponse{}
// TODO: validate mandatory attributes RegistrantID // TODO: validate mandatory attributes RegistrantID
resp, err := s.client.post(path, request, registrationResponse) resp, err := s.client.post(ctx, path, input, registrationResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
registrationResponse.HttpResponse = resp registrationResponse.HTTPResponse = resp
return registrationResponse, nil return registrationResponse, nil
} }
@ -151,19 +154,20 @@ type DomainTransfer struct {
State string `json:"state"` State string `json:"state"`
AutoRenew bool `json:"auto_renew"` AutoRenew bool `json:"auto_renew"`
WhoisPrivacy bool `json:"whois_privacy"` WhoisPrivacy bool `json:"whois_privacy"`
StatusDescription string `json:"status_description"`
CreatedAt string `json:"created_at,omitempty"` CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"`
} }
// domainTransferResponse represents a response from an API method that results in a domain transfer. // DomainTransferResponse represents a response from an API method that results in a domain transfer.
type domainTransferResponse struct { type DomainTransferResponse struct {
Response Response
Data *DomainTransfer `json:"data"` Data *DomainTransfer `json:"data"`
} }
// DomainTransferRequest represents the attributes you can pass to a transfer API request. // TransferDomainInput represents the attributes you can pass to a transfer API request.
// Some attributes are mandatory. // Some attributes are mandatory.
type DomainTransferRequest struct { type TransferDomainInput struct {
// The ID of the Contact to use as registrant for the domain // The ID of the Contact to use as registrant for the domain
RegistrantID int `json:"registrant_id"` RegistrantID int `json:"registrant_id"`
// The Auth-Code required to transfer the domain. // The Auth-Code required to transfer the domain.
@ -175,47 +179,81 @@ type DomainTransferRequest struct {
// Set to true to enable the auto-renewal of the domain. // Set to true to enable the auto-renewal of the domain.
// Default to true. // Default to true.
EnableAutoRenewal bool `json:"auto_renew,omitempty"` EnableAutoRenewal bool `json:"auto_renew,omitempty"`
// Required by some TLDs. Use Tlds.GetTldExtendedAttributes() to get the required entries.
ExtendedAttributes map[string]string `json:"extended_attributes,omitempty"`
// Required as confirmation of the price, only if the domain is premium. // Required as confirmation of the price, only if the domain is premium.
PremiumPrice string `json:"premium_price,omitempty"` PremiumPrice string `json:"premium_price,omitempty"`
} }
// TransferDomain transfers a domain name. // TransferDomain transfers a domain name.
// //
// See https://developer.dnsimple.com/v2/registrar/#transfer // See https://developer.dnsimple.com/v2/registrar/#transferDomain
func (s *RegistrarService) TransferDomain(accountID string, domainName string, request *DomainTransferRequest) (*domainTransferResponse, error) { func (s *RegistrarService) TransferDomain(ctx context.Context, accountID string, domainName string, input *TransferDomainInput) (*DomainTransferResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/transfers", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/transfers", accountID, domainName))
transferResponse := &domainTransferResponse{} transferResponse := &DomainTransferResponse{}
// TODO: validate mandatory attributes RegistrantID // TODO: validate mandatory attributes RegistrantID
resp, err := s.client.post(path, request, transferResponse) resp, err := s.client.post(ctx, path, input, transferResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
transferResponse.HttpResponse = resp transferResponse.HTTPResponse = resp
return transferResponse, nil return transferResponse, nil
} }
// domainTransferOutResponse represents a response from an API method that results in a domain transfer out. // GetDomainTransfer fetches a domain transfer.
type domainTransferOutResponse struct { //
// See https://developer.dnsimple.com/v2/registrar/#getDomainTransfer
func (s *RegistrarService) GetDomainTransfer(ctx context.Context, accountID string, domainName string, domainTransferID int64) (*DomainTransferResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/transfers/%v", accountID, domainName, domainTransferID))
transferResponse := &DomainTransferResponse{}
resp, err := s.client.get(ctx, path, transferResponse)
if err != nil {
return nil, err
}
transferResponse.HTTPResponse = resp
return transferResponse, nil
}
// CancelDomainTransfer cancels an in progress domain transfer.
//
// See https://developer.dnsimple.com/v2/registrar/#cancelDomainTransfer
func (s *RegistrarService) CancelDomainTransfer(ctx context.Context, accountID string, domainName string, domainTransferID int64) (*DomainTransferResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/transfers/%v", accountID, domainName, domainTransferID))
transferResponse := &DomainTransferResponse{}
resp, err := s.client.delete(ctx, path, nil, transferResponse)
if err != nil {
return nil, err
}
transferResponse.HTTPResponse = resp
return transferResponse, nil
}
// DomainTransferOutResponse represents a response from an API method that results in a domain transfer out.
type DomainTransferOutResponse struct {
Response Response
Data *Domain `json:"data"` Data *Domain `json:"data"`
} }
// Transfer out a domain name. // TransferDomainOut prepares a domain for outbound transfer.
// //
// See https://developer.dnsimple.com/v2/registrar/#transfer-out // See https://developer.dnsimple.com/v2/registrar/#authorizeDomainTransferOut
func (s *RegistrarService) TransferDomainOut(accountID string, domainName string) (*domainTransferOutResponse, error) { func (s *RegistrarService) TransferDomainOut(ctx context.Context, accountID string, domainName string) (*DomainTransferOutResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/authorize_transfer_out", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/authorize_transfer_out", accountID, domainName))
transferResponse := &domainTransferOutResponse{} transferResponse := &DomainTransferOutResponse{}
resp, err := s.client.post(path, nil, nil) resp, err := s.client.post(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
transferResponse.HttpResponse = resp transferResponse.HTTPResponse = resp
return transferResponse, nil return transferResponse, nil
} }
@ -229,15 +267,15 @@ type DomainRenewal struct {
UpdatedAt string `json:"updated_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"`
} }
// domainRenewalResponse represents a response from an API method that returns a domain renewal. // DomainRenewalResponse represents a response from an API method that returns a domain renewal.
type domainRenewalResponse struct { type DomainRenewalResponse struct {
Response Response
Data *DomainRenewal `json:"data"` Data *DomainRenewal `json:"data"`
} }
// DomainRenewRequest represents the attributes you can pass to a renew API request. // RenewDomainInput represents the attributes you can pass to a renew API request.
// Some attributes are mandatory. // Some attributes are mandatory.
type DomainRenewRequest struct { type RenewDomainInput struct {
// The number of years // The number of years
Period int `json:"period"` Period int `json:"period"`
// Required as confirmation of the price, only if the domain is premium. // Required as confirmation of the price, only if the domain is premium.
@ -247,15 +285,15 @@ type DomainRenewRequest struct {
// RenewDomain renews a domain name. // RenewDomain renews a domain name.
// //
// See https://developer.dnsimple.com/v2/registrar/#register // See https://developer.dnsimple.com/v2/registrar/#register
func (s *RegistrarService) RenewDomain(accountID string, domainName string, request *DomainRenewRequest) (*domainRenewalResponse, error) { func (s *RegistrarService) RenewDomain(ctx context.Context, accountID string, domainName string, input *RenewDomainInput) (*DomainRenewalResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/renewals", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/renewals", accountID, domainName))
renewalResponse := &domainRenewalResponse{} renewalResponse := &DomainRenewalResponse{}
resp, err := s.client.post(path, request, renewalResponse) resp, err := s.client.post(ctx, path, input, renewalResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
renewalResponse.HttpResponse = resp renewalResponse.HTTPResponse = resp
return renewalResponse, nil return renewalResponse, nil
} }

View File

@ -1,37 +1,38 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
// EnableDomainAutoRenewal enables auto-renewal for the domain. // EnableDomainAutoRenewal enables auto-renewal for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/auto-renewal/#enable // See https://developer.dnsimple.com/v2/registrar/auto-renewal/#enable
func (s *RegistrarService) EnableDomainAutoRenewal(accountID string, domainName string) (*domainResponse, error) { func (s *RegistrarService) EnableDomainAutoRenewal(ctx context.Context, accountID string, domainName string) (*DomainResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/auto_renewal", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/auto_renewal", accountID, domainName))
domainResponse := &domainResponse{} domainResponse := &DomainResponse{}
resp, err := s.client.put(path, nil, nil) resp, err := s.client.put(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
domainResponse.HttpResponse = resp domainResponse.HTTPResponse = resp
return domainResponse, nil return domainResponse, nil
} }
// DisableDomainAutoRenewal disables auto-renewal for the domain. // DisableDomainAutoRenewal disables auto-renewal for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/auto-renewal/#enable // See https://developer.dnsimple.com/v2/registrar/auto-renewal/#enable
func (s *RegistrarService) DisableDomainAutoRenewal(accountID string, domainName string) (*domainResponse, error) { func (s *RegistrarService) DisableDomainAutoRenewal(ctx context.Context, accountID string, domainName string) (*DomainResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/auto_renewal", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/auto_renewal", accountID, domainName))
domainResponse := &domainResponse{} domainResponse := &DomainResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
domainResponse.HttpResponse = resp domainResponse.HTTPResponse = resp
return domainResponse, nil return domainResponse, nil
} }

View File

@ -1,20 +1,21 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
// Delegation represents a list of name servers that correspond to a domain delegation. // Delegation represents a list of name servers that correspond to a domain delegation.
type Delegation []string type Delegation []string
// delegationResponse represents a response from an API method that returns a delegation struct. // DelegationResponse represents a response from an API method that returns a delegation struct.
type delegationResponse struct { type DelegationResponse struct {
Response Response
Data *Delegation `json:"data"` Data *Delegation `json:"data"`
} }
// vanityDelegationResponse represents a response for vanity name server enable and disable operations. // VanityDelegationResponse represents a response for vanity name server enable and disable operations.
type vanityDelegationResponse struct { type VanityDelegationResponse struct {
Response Response
Data []VanityNameServer `json:"data"` Data []VanityNameServer `json:"data"`
} }
@ -22,63 +23,63 @@ type vanityDelegationResponse struct {
// GetDomainDelegation gets the current delegated name servers for the domain. // GetDomainDelegation gets the current delegated name servers for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/delegation/#get // See https://developer.dnsimple.com/v2/registrar/delegation/#get
func (s *RegistrarService) GetDomainDelegation(accountID string, domainName string) (*delegationResponse, error) { func (s *RegistrarService) GetDomainDelegation(ctx context.Context, accountID string, domainName string) (*DelegationResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName))
delegationResponse := &delegationResponse{} delegationResponse := &DelegationResponse{}
resp, err := s.client.get(path, delegationResponse) resp, err := s.client.get(ctx, path, delegationResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
delegationResponse.HttpResponse = resp delegationResponse.HTTPResponse = resp
return delegationResponse, nil return delegationResponse, nil
} }
// ChangeDomainDelegation updates the delegated name severs for the domain. // ChangeDomainDelegation updates the delegated name severs for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/delegation/#get // See https://developer.dnsimple.com/v2/registrar/delegation/#get
func (s *RegistrarService) ChangeDomainDelegation(accountID string, domainName string, newDelegation *Delegation) (*delegationResponse, error) { func (s *RegistrarService) ChangeDomainDelegation(ctx context.Context, accountID string, domainName string, newDelegation *Delegation) (*DelegationResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName))
delegationResponse := &delegationResponse{} delegationResponse := &DelegationResponse{}
resp, err := s.client.put(path, newDelegation, delegationResponse) resp, err := s.client.put(ctx, path, newDelegation, delegationResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
delegationResponse.HttpResponse = resp delegationResponse.HTTPResponse = resp
return delegationResponse, nil return delegationResponse, nil
} }
// ChangeDomainDelegationToVanity enables vanity name servers for the given domain. // ChangeDomainDelegationToVanity enables vanity name servers for the given domain.
// //
// See https://developer.dnsimple.com/v2/registrar/delegation/#delegateToVanity // See https://developer.dnsimple.com/v2/registrar/delegation/#delegateToVanity
func (s *RegistrarService) ChangeDomainDelegationToVanity(accountID string, domainName string, newDelegation *Delegation) (*vanityDelegationResponse, error) { func (s *RegistrarService) ChangeDomainDelegationToVanity(ctx context.Context, accountID string, domainName string, newDelegation *Delegation) (*VanityDelegationResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName))
delegationResponse := &vanityDelegationResponse{} delegationResponse := &VanityDelegationResponse{}
resp, err := s.client.put(path, newDelegation, delegationResponse) resp, err := s.client.put(ctx, path, newDelegation, delegationResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
delegationResponse.HttpResponse = resp delegationResponse.HTTPResponse = resp
return delegationResponse, nil return delegationResponse, nil
} }
// ChangeDomainDelegationFromVanity disables vanity name servers for the given domain. // ChangeDomainDelegationFromVanity disables vanity name servers for the given domain.
// //
// See https://developer.dnsimple.com/v2/registrar/delegation/#dedelegateFromVanity // See https://developer.dnsimple.com/v2/registrar/delegation/#dedelegateFromVanity
func (s *RegistrarService) ChangeDomainDelegationFromVanity(accountID string, domainName string) (*vanityDelegationResponse, error) { func (s *RegistrarService) ChangeDomainDelegationFromVanity(ctx context.Context, accountID string, domainName string) (*VanityDelegationResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName))
delegationResponse := &vanityDelegationResponse{} delegationResponse := &VanityDelegationResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
delegationResponse.HttpResponse = resp delegationResponse.HTTPResponse = resp
return delegationResponse, nil return delegationResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -26,14 +27,14 @@ type WhoisPrivacyRenewal struct {
UpdatedAt string `json:"updated_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"`
} }
// whoisPrivacyResponse represents a response from an API method that returns a WhoisPrivacy struct. // WhoisPrivacyResponse represents a response from an API method that returns a WhoisPrivacy struct.
type whoisPrivacyResponse struct { type WhoisPrivacyResponse struct {
Response Response
Data *WhoisPrivacy `json:"data"` Data *WhoisPrivacy `json:"data"`
} }
// whoisPrivacyRenewalResponse represents a response from an API method that returns a WhoisPrivacyRenewal struct. // WhoisPrivacyRenewalResponse represents a response from an API method that returns a WhoisPrivacyRenewal struct.
type whoisPrivacyRenewalResponse struct { type WhoisPrivacyRenewalResponse struct {
Response Response
Data *WhoisPrivacyRenewal `json:"data"` Data *WhoisPrivacyRenewal `json:"data"`
} }
@ -41,63 +42,63 @@ type whoisPrivacyRenewalResponse struct {
// GetWhoisPrivacy gets the whois privacy for the domain. // GetWhoisPrivacy gets the whois privacy for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/whois-privacy/#get // See https://developer.dnsimple.com/v2/registrar/whois-privacy/#get
func (s *RegistrarService) GetWhoisPrivacy(accountID string, domainName string) (*whoisPrivacyResponse, error) { func (s *RegistrarService) GetWhoisPrivacy(ctx context.Context, accountID string, domainName string) (*WhoisPrivacyResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName))
privacyResponse := &whoisPrivacyResponse{} privacyResponse := &WhoisPrivacyResponse{}
resp, err := s.client.get(path, privacyResponse) resp, err := s.client.get(ctx, path, privacyResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
privacyResponse.HttpResponse = resp privacyResponse.HTTPResponse = resp
return privacyResponse, nil return privacyResponse, nil
} }
// EnableWhoisPrivacy enables the whois privacy for the domain. // EnableWhoisPrivacy enables the whois privacy for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/whois-privacy/#enable // See https://developer.dnsimple.com/v2/registrar/whois-privacy/#enable
func (s *RegistrarService) EnableWhoisPrivacy(accountID string, domainName string) (*whoisPrivacyResponse, error) { func (s *RegistrarService) EnableWhoisPrivacy(ctx context.Context, accountID string, domainName string) (*WhoisPrivacyResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName))
privacyResponse := &whoisPrivacyResponse{} privacyResponse := &WhoisPrivacyResponse{}
resp, err := s.client.put(path, nil, privacyResponse) resp, err := s.client.put(ctx, path, nil, privacyResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
privacyResponse.HttpResponse = resp privacyResponse.HTTPResponse = resp
return privacyResponse, nil return privacyResponse, nil
} }
// DisableWhoisPrivacy disables the whois privacy for the domain. // DisableWhoisPrivacy disables the whois privacy for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/whois-privacy/#enable // See https://developer.dnsimple.com/v2/registrar/whois-privacy/#enable
func (s *RegistrarService) DisableWhoisPrivacy(accountID string, domainName string) (*whoisPrivacyResponse, error) { func (s *RegistrarService) DisableWhoisPrivacy(ctx context.Context, accountID string, domainName string) (*WhoisPrivacyResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName))
privacyResponse := &whoisPrivacyResponse{} privacyResponse := &WhoisPrivacyResponse{}
resp, err := s.client.delete(path, nil, privacyResponse) resp, err := s.client.delete(ctx, path, nil, privacyResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
privacyResponse.HttpResponse = resp privacyResponse.HTTPResponse = resp
return privacyResponse, nil return privacyResponse, nil
} }
// RenewWhoisPrivacy renews the whois privacy for the domain. // RenewWhoisPrivacy renews the whois privacy for the domain.
// //
// See https://developer.dnsimple.com/v2/registrar/whois-privacy/#renew // See https://developer.dnsimple.com/v2/registrar/whois-privacy/#renew
func (s *RegistrarService) RenewWhoisPrivacy(accountID string, domainName string) (*whoisPrivacyRenewalResponse, error) { func (s *RegistrarService) RenewWhoisPrivacy(ctx context.Context, accountID string, domainName string) (*WhoisPrivacyRenewalResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy/renewals", accountID, domainName)) path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy/renewals", accountID, domainName))
privacyRenewalResponse := &whoisPrivacyRenewalResponse{} privacyRenewalResponse := &WhoisPrivacyRenewalResponse{}
resp, err := s.client.post(path, nil, privacyRenewalResponse) resp, err := s.client.post(ctx, path, nil, privacyRenewalResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
privacyRenewalResponse.HttpResponse = resp privacyRenewalResponse.HTTPResponse = resp
return privacyRenewalResponse, nil return privacyRenewalResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -44,14 +45,14 @@ func servicePath(serviceIdentifier string) (path string) {
return return
} }
// serviceResponse represents a response from an API method that returns a Service struct. // ServiceResponse represents a response from an API method that returns a Service struct.
type serviceResponse struct { type ServiceResponse struct {
Response Response
Data *Service `json:"data"` Data *Service `json:"data"`
} }
// servicesResponse represents a response from an API method that returns a collection of Service struct. // ServicesResponse represents a response from an API method that returns a collection of Service struct.
type servicesResponse struct { type ServicesResponse struct {
Response Response
Data []Service `json:"data"` Data []Service `json:"data"`
} }
@ -59,36 +60,36 @@ type servicesResponse struct {
// ListServices lists the one-click services available in DNSimple. // ListServices lists the one-click services available in DNSimple.
// //
// See https://developer.dnsimple.com/v2/services/#list // See https://developer.dnsimple.com/v2/services/#list
func (s *ServicesService) ListServices(options *ListOptions) (*servicesResponse, error) { func (s *ServicesService) ListServices(ctx context.Context, options *ListOptions) (*ServicesResponse, error) {
path := versioned(servicePath("")) path := versioned(servicePath(""))
servicesResponse := &servicesResponse{} servicesResponse := &ServicesResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, servicesResponse) resp, err := s.client.get(ctx, path, servicesResponse)
if err != nil { if err != nil {
return servicesResponse, err return servicesResponse, err
} }
servicesResponse.HttpResponse = resp servicesResponse.HTTPResponse = resp
return servicesResponse, nil return servicesResponse, nil
} }
// GetService fetches a one-click service. // GetService fetches a one-click service.
// //
// See https://developer.dnsimple.com/v2/services/#get // See https://developer.dnsimple.com/v2/services/#get
func (s *ServicesService) GetService(serviceIdentifier string) (*serviceResponse, error) { func (s *ServicesService) GetService(ctx context.Context, serviceIdentifier string) (*ServiceResponse, error) {
path := versioned(servicePath(serviceIdentifier)) path := versioned(servicePath(serviceIdentifier))
serviceResponse := &serviceResponse{} serviceResponse := &ServiceResponse{}
resp, err := s.client.get(path, serviceResponse) resp, err := s.client.get(ctx, path, serviceResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
serviceResponse.HttpResponse = resp serviceResponse.HTTPResponse = resp
return serviceResponse, nil return serviceResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -19,52 +20,52 @@ type DomainServiceSettings struct {
// AppliedServices lists the applied one-click services for a domain. // AppliedServices lists the applied one-click services for a domain.
// //
// See https://developer.dnsimple.com/v2/services/domains/#applied // See https://developer.dnsimple.com/v2/services/domains/#applied
func (s *ServicesService) AppliedServices(accountID string, domainIdentifier string, options *ListOptions) (*servicesResponse, error) { func (s *ServicesService) AppliedServices(ctx context.Context, accountID string, domainIdentifier string, options *ListOptions) (*ServicesResponse, error) {
path := versioned(domainServicesPath(accountID, domainIdentifier, "")) path := versioned(domainServicesPath(accountID, domainIdentifier, ""))
servicesResponse := &servicesResponse{} servicesResponse := &ServicesResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, servicesResponse) resp, err := s.client.get(ctx, path, servicesResponse)
if err != nil { if err != nil {
return servicesResponse, err return servicesResponse, err
} }
servicesResponse.HttpResponse = resp servicesResponse.HTTPResponse = resp
return servicesResponse, nil return servicesResponse, nil
} }
// ApplyService applies a one-click services to a domain. // ApplyService applies a one-click services to a domain.
// //
// See https://developer.dnsimple.com/v2/services/domains/#apply // See https://developer.dnsimple.com/v2/services/domains/#apply
func (s *ServicesService) ApplyService(accountID string, serviceIdentifier string, domainIdentifier string, settings DomainServiceSettings) (*serviceResponse, error) { func (s *ServicesService) ApplyService(ctx context.Context, accountID string, serviceIdentifier string, domainIdentifier string, settings DomainServiceSettings) (*ServiceResponse, error) {
path := versioned(domainServicesPath(accountID, domainIdentifier, serviceIdentifier)) path := versioned(domainServicesPath(accountID, domainIdentifier, serviceIdentifier))
serviceResponse := &serviceResponse{} serviceResponse := &ServiceResponse{}
resp, err := s.client.post(path, settings, nil) resp, err := s.client.post(ctx, path, settings, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
serviceResponse.HttpResponse = resp serviceResponse.HTTPResponse = resp
return serviceResponse, nil return serviceResponse, nil
} }
// UnapplyService unapplies a one-click services from a domain. // UnapplyService unapplies a one-click services from a domain.
// //
// See https://developer.dnsimple.com/v2/services/domains/#unapply // See https://developer.dnsimple.com/v2/services/domains/#unapply
func (s *ServicesService) UnapplyService(accountID string, serviceIdentifier string, domainIdentifier string) (*serviceResponse, error) { func (s *ServicesService) UnapplyService(ctx context.Context, accountID string, serviceIdentifier string, domainIdentifier string) (*ServiceResponse, error) {
path := versioned(domainServicesPath(accountID, domainIdentifier, serviceIdentifier)) path := versioned(domainServicesPath(accountID, domainIdentifier, serviceIdentifier))
serviceResponse := &serviceResponse{} serviceResponse := &ServiceResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
serviceResponse.HttpResponse = resp serviceResponse.HTTPResponse = resp
return serviceResponse, nil return serviceResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -31,14 +32,14 @@ func templatePath(accountID string, templateIdentifier string) (path string) {
return return
} }
// templateResponse represents a response from an API method that returns a Template struct. // TemplateResponse represents a response from an API method that returns a Template struct.
type templateResponse struct { type TemplateResponse struct {
Response Response
Data *Template `json:"data"` Data *Template `json:"data"`
} }
// templatesResponse represents a response from an API method that returns a collection of Template struct. // TemplatesResponse represents a response from an API method that returns a collection of Template struct.
type templatesResponse struct { type TemplatesResponse struct {
Response Response
Data []Template `json:"data"` Data []Template `json:"data"`
} }
@ -46,84 +47,84 @@ type templatesResponse struct {
// ListTemplates list the templates for an account. // ListTemplates list the templates for an account.
// //
// See https://developer.dnsimple.com/v2/templates/#list // See https://developer.dnsimple.com/v2/templates/#list
func (s *TemplatesService) ListTemplates(accountID string, options *ListOptions) (*templatesResponse, error) { func (s *TemplatesService) ListTemplates(ctx context.Context, accountID string, options *ListOptions) (*TemplatesResponse, error) {
path := versioned(templatePath(accountID, "")) path := versioned(templatePath(accountID, ""))
templatesResponse := &templatesResponse{} templatesResponse := &TemplatesResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, templatesResponse) resp, err := s.client.get(ctx, path, templatesResponse)
if err != nil { if err != nil {
return templatesResponse, err return templatesResponse, err
} }
templatesResponse.HttpResponse = resp templatesResponse.HTTPResponse = resp
return templatesResponse, nil return templatesResponse, nil
} }
// CreateTemplate creates a new template. // CreateTemplate creates a new template.
// //
// See https://developer.dnsimple.com/v2/templates/#create // See https://developer.dnsimple.com/v2/templates/#create
func (s *TemplatesService) CreateTemplate(accountID string, templateAttributes Template) (*templateResponse, error) { func (s *TemplatesService) CreateTemplate(ctx context.Context, accountID string, templateAttributes Template) (*TemplateResponse, error) {
path := versioned(templatePath(accountID, "")) path := versioned(templatePath(accountID, ""))
templateResponse := &templateResponse{} templateResponse := &TemplateResponse{}
resp, err := s.client.post(path, templateAttributes, templateResponse) resp, err := s.client.post(ctx, path, templateAttributes, templateResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateResponse.HttpResponse = resp templateResponse.HTTPResponse = resp
return templateResponse, nil return templateResponse, nil
} }
// GetTemplate fetches a template. // GetTemplate fetches a template.
// //
// See https://developer.dnsimple.com/v2/templates/#get // See https://developer.dnsimple.com/v2/templates/#get
func (s *TemplatesService) GetTemplate(accountID string, templateIdentifier string) (*templateResponse, error) { func (s *TemplatesService) GetTemplate(ctx context.Context, accountID string, templateIdentifier string) (*TemplateResponse, error) {
path := versioned(templatePath(accountID, templateIdentifier)) path := versioned(templatePath(accountID, templateIdentifier))
templateResponse := &templateResponse{} templateResponse := &TemplateResponse{}
resp, err := s.client.get(path, templateResponse) resp, err := s.client.get(ctx, path, templateResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateResponse.HttpResponse = resp templateResponse.HTTPResponse = resp
return templateResponse, nil return templateResponse, nil
} }
// UpdateTemplate updates a template. // UpdateTemplate updates a template.
// //
// See https://developer.dnsimple.com/v2/templates/#update // See https://developer.dnsimple.com/v2/templates/#update
func (s *TemplatesService) UpdateTemplate(accountID string, templateIdentifier string, templateAttributes Template) (*templateResponse, error) { func (s *TemplatesService) UpdateTemplate(ctx context.Context, accountID string, templateIdentifier string, templateAttributes Template) (*TemplateResponse, error) {
path := versioned(templatePath(accountID, templateIdentifier)) path := versioned(templatePath(accountID, templateIdentifier))
templateResponse := &templateResponse{} templateResponse := &TemplateResponse{}
resp, err := s.client.patch(path, templateAttributes, templateResponse) resp, err := s.client.patch(ctx, path, templateAttributes, templateResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateResponse.HttpResponse = resp templateResponse.HTTPResponse = resp
return templateResponse, nil return templateResponse, nil
} }
// DeleteTemplate deletes a template. // DeleteTemplate deletes a template.
// //
// See https://developer.dnsimple.com/v2/templates/#delete // See https://developer.dnsimple.com/v2/templates/#delete
func (s *TemplatesService) DeleteTemplate(accountID string, templateIdentifier string) (*templateResponse, error) { func (s *TemplatesService) DeleteTemplate(ctx context.Context, accountID string, templateIdentifier string) (*TemplateResponse, error) {
path := versioned(templatePath(accountID, templateIdentifier)) path := versioned(templatePath(accountID, templateIdentifier))
templateResponse := &templateResponse{} templateResponse := &TemplateResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateResponse.HttpResponse = resp templateResponse.HTTPResponse = resp
return templateResponse, nil return templateResponse, nil
} }

View File

@ -1,21 +1,22 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
// ApplyTemplate applies a template to the given domain. // ApplyTemplate applies a template to the given domain.
// //
// See https://developer.dnsimple.com/v2/templates/domains/#apply // See https://developer.dnsimple.com/v2/templates/domains/#applyTemplateToDomain
func (s *TemplatesService) ApplyTemplate(accountID string, templateIdentifier string, domainIdentifier string) (*templateResponse, error) { func (s *TemplatesService) ApplyTemplate(ctx context.Context, accountID string, templateIdentifier string, domainIdentifier string) (*TemplateResponse, error) {
path := versioned(fmt.Sprintf("%v/templates/%v", domainPath(accountID, domainIdentifier), templateIdentifier)) path := versioned(fmt.Sprintf("%v/templates/%v", domainPath(accountID, domainIdentifier), templateIdentifier))
templateResponse := &templateResponse{} templateResponse := &TemplateResponse{}
resp, err := s.client.post(path, nil, nil) resp, err := s.client.post(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateResponse.HttpResponse = resp templateResponse.HTTPResponse = resp
return templateResponse, nil return templateResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -25,14 +26,14 @@ func templateRecordPath(accountID string, templateIdentifier string, templateRec
return templatePath(accountID, templateIdentifier) + "/records" return templatePath(accountID, templateIdentifier) + "/records"
} }
// templateRecordResponse represents a response from an API method that returns a TemplateRecord struct. // TemplateRecordResponse represents a response from an API method that returns a TemplateRecord struct.
type templateRecordResponse struct { type TemplateRecordResponse struct {
Response Response
Data *TemplateRecord `json:"data"` Data *TemplateRecord `json:"data"`
} }
// templateRecordsResponse represents a response from an API method that returns a collection of TemplateRecord struct. // TemplateRecordsResponse represents a response from an API method that returns a collection of TemplateRecord struct.
type templateRecordsResponse struct { type TemplateRecordsResponse struct {
Response Response
Data []TemplateRecord `json:"data"` Data []TemplateRecord `json:"data"`
} }
@ -40,68 +41,68 @@ type templateRecordsResponse struct {
// ListTemplateRecords list the templates for an account. // ListTemplateRecords list the templates for an account.
// //
// See https://developer.dnsimple.com/v2/templates/records/#list // See https://developer.dnsimple.com/v2/templates/records/#list
func (s *TemplatesService) ListTemplateRecords(accountID string, templateIdentifier string, options *ListOptions) (*templateRecordsResponse, error) { func (s *TemplatesService) ListTemplateRecords(ctx context.Context, accountID string, templateIdentifier string, options *ListOptions) (*TemplateRecordsResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, 0)) path := versioned(templateRecordPath(accountID, templateIdentifier, 0))
templateRecordsResponse := &templateRecordsResponse{} templateRecordsResponse := &TemplateRecordsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, templateRecordsResponse) resp, err := s.client.get(ctx, path, templateRecordsResponse)
if err != nil { if err != nil {
return templateRecordsResponse, err return templateRecordsResponse, err
} }
templateRecordsResponse.HttpResponse = resp templateRecordsResponse.HTTPResponse = resp
return templateRecordsResponse, nil return templateRecordsResponse, nil
} }
// CreateTemplateRecord creates a new template record. // CreateTemplateRecord creates a new template record.
// //
// See https://developer.dnsimple.com/v2/templates/records/#create // See https://developer.dnsimple.com/v2/templates/records/#create
func (s *TemplatesService) CreateTemplateRecord(accountID string, templateIdentifier string, templateRecordAttributes TemplateRecord) (*templateRecordResponse, error) { func (s *TemplatesService) CreateTemplateRecord(ctx context.Context, accountID string, templateIdentifier string, templateRecordAttributes TemplateRecord) (*TemplateRecordResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, 0)) path := versioned(templateRecordPath(accountID, templateIdentifier, 0))
templateRecordResponse := &templateRecordResponse{} templateRecordResponse := &TemplateRecordResponse{}
resp, err := s.client.post(path, templateRecordAttributes, templateRecordResponse) resp, err := s.client.post(ctx, path, templateRecordAttributes, templateRecordResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateRecordResponse.HttpResponse = resp templateRecordResponse.HTTPResponse = resp
return templateRecordResponse, nil return templateRecordResponse, nil
} }
// GetTemplateRecord fetches a template record. // GetTemplateRecord fetches a template record.
// //
// See https://developer.dnsimple.com/v2/templates/records/#get // See https://developer.dnsimple.com/v2/templates/records/#get
func (s *TemplatesService) GetTemplateRecord(accountID string, templateIdentifier string, templateRecordID int64) (*templateRecordResponse, error) { func (s *TemplatesService) GetTemplateRecord(ctx context.Context, accountID string, templateIdentifier string, templateRecordID int64) (*TemplateRecordResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID)) path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID))
templateRecordResponse := &templateRecordResponse{} templateRecordResponse := &TemplateRecordResponse{}
resp, err := s.client.get(path, templateRecordResponse) resp, err := s.client.get(ctx, path, templateRecordResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateRecordResponse.HttpResponse = resp templateRecordResponse.HTTPResponse = resp
return templateRecordResponse, nil return templateRecordResponse, nil
} }
// DeleteTemplateRecord deletes a template record. // DeleteTemplateRecord deletes a template record.
// //
// See https://developer.dnsimple.com/v2/templates/records/#delete // See https://developer.dnsimple.com/v2/templates/records/#delete
func (s *TemplatesService) DeleteTemplateRecord(accountID string, templateIdentifier string, templateRecordID int64) (*templateRecordResponse, error) { func (s *TemplatesService) DeleteTemplateRecord(ctx context.Context, accountID string, templateIdentifier string, templateRecordID int64) (*TemplateRecordResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID)) path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID))
templateRecordResponse := &templateRecordResponse{} templateRecordResponse := &TemplateRecordResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
templateRecordResponse.HttpResponse = resp templateRecordResponse.HTTPResponse = resp
return templateRecordResponse, nil return templateRecordResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -44,21 +45,21 @@ type TldExtendedAttributeOption struct {
Description string `json:"description"` Description string `json:"description"`
} }
// tldResponse represents a response from an API method that returns a Tld struct. // TldResponse represents a response from an API method that returns a Tld struct.
type tldResponse struct { type TldResponse struct {
Response Response
Data *Tld `json:"data"` Data *Tld `json:"data"`
} }
// tldsResponse represents a response from an API method that returns a collection of Tld struct. // TldsResponse represents a response from an API method that returns a collection of Tld struct.
type tldsResponse struct { type TldsResponse struct {
Response Response
Data []Tld `json:"data"` Data []Tld `json:"data"`
} }
// tldExtendedAttributesResponse represents a response from an API method that returns // TldExtendedAttributesResponse represents a response from an API method that returns
// a collection of Tld extended attributes. // a collection of Tld extended attributes.
type tldExtendedAttributesResponse struct { type TldExtendedAttributesResponse struct {
Response Response
Data []TldExtendedAttribute `json:"data"` Data []TldExtendedAttribute `json:"data"`
} }
@ -66,52 +67,52 @@ type tldExtendedAttributesResponse struct {
// ListTlds lists the supported TLDs. // ListTlds lists the supported TLDs.
// //
// See https://developer.dnsimple.com/v2/tlds/#list // See https://developer.dnsimple.com/v2/tlds/#list
func (s *TldsService) ListTlds(options *ListOptions) (*tldsResponse, error) { func (s *TldsService) ListTlds(ctx context.Context, options *ListOptions) (*TldsResponse, error) {
path := versioned("/tlds") path := versioned("/tlds")
tldsResponse := &tldsResponse{} tldsResponse := &TldsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, tldsResponse) resp, err := s.client.get(ctx, path, tldsResponse)
if err != nil { if err != nil {
return tldsResponse, err return tldsResponse, err
} }
tldsResponse.HttpResponse = resp tldsResponse.HTTPResponse = resp
return tldsResponse, nil return tldsResponse, nil
} }
// GetTld fetches a TLD. // GetTld fetches a TLD.
// //
// See https://developer.dnsimple.com/v2/tlds/#get // See https://developer.dnsimple.com/v2/tlds/#get
func (s *TldsService) GetTld(tld string) (*tldResponse, error) { func (s *TldsService) GetTld(ctx context.Context, tld string) (*TldResponse, error) {
path := versioned(fmt.Sprintf("/tlds/%s", tld)) path := versioned(fmt.Sprintf("/tlds/%s", tld))
tldResponse := &tldResponse{} tldResponse := &TldResponse{}
resp, err := s.client.get(path, tldResponse) resp, err := s.client.get(ctx, path, tldResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
tldResponse.HttpResponse = resp tldResponse.HTTPResponse = resp
return tldResponse, nil return tldResponse, nil
} }
// GetTldExtendedAttributes fetches the extended attributes of a TLD. // GetTldExtendedAttributes fetches the extended attributes of a TLD.
// //
// See https://developer.dnsimple.com/v2/tlds/#get // See https://developer.dnsimple.com/v2/tlds/#get
func (s *TldsService) GetTldExtendedAttributes(tld string) (*tldExtendedAttributesResponse, error) { func (s *TldsService) GetTldExtendedAttributes(ctx context.Context, tld string) (*TldExtendedAttributesResponse, error) {
path := versioned(fmt.Sprintf("/tlds/%s/extended_attributes", tld)) path := versioned(fmt.Sprintf("/tlds/%s/extended_attributes", tld))
tldResponse := &tldExtendedAttributesResponse{} tldResponse := &TldExtendedAttributesResponse{}
resp, err := s.client.get(path, tldResponse) resp, err := s.client.get(ctx, path, tldResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
tldResponse.HttpResponse = resp tldResponse.HTTPResponse = resp
return tldResponse, nil return tldResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -26,40 +27,40 @@ func vanityNameServerPath(accountID string, domainIdentifier string) string {
return fmt.Sprintf("/%v/vanity/%v", accountID, domainIdentifier) return fmt.Sprintf("/%v/vanity/%v", accountID, domainIdentifier)
} }
// vanityNameServerResponse represents a response for vanity name server enable and disable operations. // VanityNameServerResponse represents a response for vanity name server enable and disable operations.
type vanityNameServerResponse struct { type VanityNameServerResponse struct {
Response Response
Data []VanityNameServer `json:"data"` Data []VanityNameServer `json:"data"`
} }
// EnableVanityNameServers Vanity Name Servers for the given domain // EnableVanityNameServers Vanity Name Servers for the given domain
// //
// See https://developer.dnsimple.com/v2/vanity/#enable // See https://developer.dnsimple.com/v2/vanity/#enableVanityNameServers
func (s *VanityNameServersService) EnableVanityNameServers(accountID string, domainIdentifier string) (*vanityNameServerResponse, error) { func (s *VanityNameServersService) EnableVanityNameServers(ctx context.Context, accountID string, domainIdentifier string) (*VanityNameServerResponse, error) {
path := versioned(vanityNameServerPath(accountID, domainIdentifier)) path := versioned(vanityNameServerPath(accountID, domainIdentifier))
vanityNameServerResponse := &vanityNameServerResponse{} vanityNameServerResponse := &VanityNameServerResponse{}
resp, err := s.client.put(path, nil, vanityNameServerResponse) resp, err := s.client.put(ctx, path, nil, vanityNameServerResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
vanityNameServerResponse.HttpResponse = resp vanityNameServerResponse.HTTPResponse = resp
return vanityNameServerResponse, nil return vanityNameServerResponse, nil
} }
// DisableVanityNameServers Vanity Name Servers for the given domain // DisableVanityNameServers Vanity Name Servers for the given domain
// //
// See https://developer.dnsimple.com/v2/vanity/#disable // See https://developer.dnsimple.com/v2/vanity/#disableVanityNameServers
func (s *VanityNameServersService) DisableVanityNameServers(accountID string, domainIdentifier string) (*vanityNameServerResponse, error) { func (s *VanityNameServersService) DisableVanityNameServers(ctx context.Context, accountID string, domainIdentifier string) (*VanityNameServerResponse, error) {
path := versioned(vanityNameServerPath(accountID, domainIdentifier)) path := versioned(vanityNameServerPath(accountID, domainIdentifier))
vanityNameServerResponse := &vanityNameServerResponse{} vanityNameServerResponse := &VanityNameServerResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
vanityNameServerResponse.HttpResponse = resp vanityNameServerResponse.HTTPResponse = resp
return vanityNameServerResponse, nil return vanityNameServerResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -26,78 +27,78 @@ func webhookPath(accountID string, webhookID int64) (path string) {
return return
} }
// webhookResponse represents a response from an API method that returns a Webhook struct. // WebhookResponse represents a response from an API method that returns a Webhook struct.
type webhookResponse struct { type WebhookResponse struct {
Response Response
Data *Webhook `json:"data"` Data *Webhook `json:"data"`
} }
// webhookResponse represents a response from an API method that returns a collection of Webhook struct. // WebhooksResponse represents a response from an API method that returns a collection of Webhook struct.
type webhooksResponse struct { type WebhooksResponse struct {
Response Response
Data []Webhook `json:"data"` Data []Webhook `json:"data"`
} }
// ListWebhooks lists the webhooks for an account. // ListWebhooks lists the webhooks for an account.
// //
// See https://developer.dnsimple.com/v2/webhooks#list // See https://developer.dnsimple.com/v2/webhooks/#listWebhooks
func (s *WebhooksService) ListWebhooks(accountID string, _ *ListOptions) (*webhooksResponse, error) { func (s *WebhooksService) ListWebhooks(ctx context.Context, accountID string, _ *ListOptions) (*WebhooksResponse, error) {
path := versioned(webhookPath(accountID, 0)) path := versioned(webhookPath(accountID, 0))
webhooksResponse := &webhooksResponse{} webhooksResponse := &WebhooksResponse{}
resp, err := s.client.get(path, webhooksResponse) resp, err := s.client.get(ctx, path, webhooksResponse)
if err != nil { if err != nil {
return webhooksResponse, err return webhooksResponse, err
} }
webhooksResponse.HttpResponse = resp webhooksResponse.HTTPResponse = resp
return webhooksResponse, nil return webhooksResponse, nil
} }
// CreateWebhook creates a new webhook. // CreateWebhook creates a new webhook.
// //
// See https://developer.dnsimple.com/v2/webhooks#create // See https://developer.dnsimple.com/v2/webhooks/#createWebhook
func (s *WebhooksService) CreateWebhook(accountID string, webhookAttributes Webhook) (*webhookResponse, error) { func (s *WebhooksService) CreateWebhook(ctx context.Context, accountID string, webhookAttributes Webhook) (*WebhookResponse, error) {
path := versioned(webhookPath(accountID, 0)) path := versioned(webhookPath(accountID, 0))
webhookResponse := &webhookResponse{} webhookResponse := &WebhookResponse{}
resp, err := s.client.post(path, webhookAttributes, webhookResponse) resp, err := s.client.post(ctx, path, webhookAttributes, webhookResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
webhookResponse.HttpResponse = resp webhookResponse.HTTPResponse = resp
return webhookResponse, nil return webhookResponse, nil
} }
// GetWebhook fetches a webhook. // GetWebhook fetches a webhook.
// //
// See https://developer.dnsimple.com/v2/webhooks#get // See https://developer.dnsimple.com/v2/webhooks/#getWebhook
func (s *WebhooksService) GetWebhook(accountID string, webhookID int64) (*webhookResponse, error) { func (s *WebhooksService) GetWebhook(ctx context.Context, accountID string, webhookID int64) (*WebhookResponse, error) {
path := versioned(webhookPath(accountID, webhookID)) path := versioned(webhookPath(accountID, webhookID))
webhookResponse := &webhookResponse{} webhookResponse := &WebhookResponse{}
resp, err := s.client.get(path, webhookResponse) resp, err := s.client.get(ctx, path, webhookResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
webhookResponse.HttpResponse = resp webhookResponse.HTTPResponse = resp
return webhookResponse, nil return webhookResponse, nil
} }
// DeleteWebhook PERMANENTLY deletes a webhook from the account. // DeleteWebhook PERMANENTLY deletes the webhook.
// //
// See https://developer.dnsimple.com/v2/webhooks#delete // See https://developer.dnsimple.com/v2/webhooks/#deleteWebhook
func (s *WebhooksService) DeleteWebhook(accountID string, webhookID int64) (*webhookResponse, error) { func (s *WebhooksService) DeleteWebhook(ctx context.Context, accountID string, webhookID int64) (*WebhookResponse, error) {
path := versioned(webhookPath(accountID, webhookID)) path := versioned(webhookPath(accountID, webhookID))
webhookResponse := &webhookResponse{} webhookResponse := &WebhookResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
webhookResponse.HttpResponse = resp webhookResponse.HTTPResponse = resp
return webhookResponse, nil return webhookResponse, nil
} }

View File

@ -1,14 +1,17 @@
package dnsimple package dnsimple
import "fmt" import (
"context"
"fmt"
)
// ZoneDistribution is the result of the zone distribution check. // ZoneDistribution is the result of the zone distribution check.
type ZoneDistribution struct { type ZoneDistribution struct {
Distributed bool `json:"distributed"` Distributed bool `json:"distributed"`
} }
// zoneDistributionResponse represents a response from an API method that returns a ZoneDistribution struct. // ZoneDistributionResponse represents a response from an API method that returns a ZoneDistribution struct.
type zoneDistributionResponse struct { type ZoneDistributionResponse struct {
Response Response
Data *ZoneDistribution `json:"data"` Data *ZoneDistribution `json:"data"`
} }
@ -16,31 +19,31 @@ type zoneDistributionResponse struct {
// CheckZoneDistribution checks if a zone is fully distributed across DNSimple nodes. // CheckZoneDistribution checks if a zone is fully distributed across DNSimple nodes.
// //
// See https://developer.dnsimple.com/v2/zones/#checkZoneDistribution // See https://developer.dnsimple.com/v2/zones/#checkZoneDistribution
func (s *ZonesService) CheckZoneDistribution(accountID string, zoneName string) (*zoneDistributionResponse, error) { func (s *ZonesService) CheckZoneDistribution(ctx context.Context, accountID string, zoneName string) (*ZoneDistributionResponse, error) {
path := versioned(fmt.Sprintf("/%v/zones/%v/distribution", accountID, zoneName)) path := versioned(fmt.Sprintf("/%v/zones/%v/distribution", accountID, zoneName))
zoneDistributionResponse := &zoneDistributionResponse{} zoneDistributionResponse := &ZoneDistributionResponse{}
resp, err := s.client.get(path, zoneDistributionResponse) resp, err := s.client.get(ctx, path, zoneDistributionResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
zoneDistributionResponse.HttpResponse = resp zoneDistributionResponse.HTTPResponse = resp
return zoneDistributionResponse, nil return zoneDistributionResponse, nil
} }
// CheckZoneRecordDistribution checks if a zone is fully distributed across DNSimple nodes. // CheckZoneRecordDistribution checks if a zone is fully distributed across DNSimple nodes.
// //
// See https://developer.dnsimple.com/v2/zones/#checkZoneRecordDistribution // See https://developer.dnsimple.com/v2/zones/#checkZoneRecordDistribution
func (s *ZonesService) CheckZoneRecordDistribution(accountID string, zoneName string, recordID int64) (*zoneDistributionResponse, error) { func (s *ZonesService) CheckZoneRecordDistribution(ctx context.Context, accountID string, zoneName string, recordID int64) (*ZoneDistributionResponse, error) {
path := versioned(fmt.Sprintf("/%v/zones/%v/records/%v/distribution", accountID, zoneName, recordID)) path := versioned(fmt.Sprintf("/%v/zones/%v/records/%v/distribution", accountID, zoneName, recordID))
zoneDistributionResponse := &zoneDistributionResponse{} zoneDistributionResponse := &ZoneDistributionResponse{}
resp, err := s.client.get(path, zoneDistributionResponse) resp, err := s.client.get(ctx, path, zoneDistributionResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
zoneDistributionResponse.HttpResponse = resp zoneDistributionResponse.HTTPResponse = resp
return zoneDistributionResponse, nil return zoneDistributionResponse, nil
} }

View File

@ -1,6 +1,7 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
@ -27,20 +28,20 @@ type ZoneFile struct {
Zone string `json:"zone,omitempty"` Zone string `json:"zone,omitempty"`
} }
// zoneResponse represents a response from an API method that returns a Zone struct. // ZoneResponse represents a response from an API method that returns a Zone struct.
type zoneResponse struct { type ZoneResponse struct {
Response Response
Data *Zone `json:"data"` Data *Zone `json:"data"`
} }
// zonesResponse represents a response from an API method that returns a collection of Zone struct. // ZonesResponse represents a response from an API method that returns a collection of Zone struct.
type zonesResponse struct { type ZonesResponse struct {
Response Response
Data []Zone `json:"data"` Data []Zone `json:"data"`
} }
// zoneFileResponse represents a response from an API method that returns a ZoneFile struct. // ZoneFileResponse represents a response from an API method that returns a ZoneFile struct.
type zoneFileResponse struct { type ZoneFileResponse struct {
Response Response
Data *ZoneFile `json:"data"` Data *ZoneFile `json:"data"`
} }
@ -49,60 +50,60 @@ type zoneFileResponse struct {
// to customize the ZonesService.ListZones method. // to customize the ZonesService.ListZones method.
type ZoneListOptions struct { type ZoneListOptions struct {
// Select domains where the name contains given string. // Select domains where the name contains given string.
NameLike string `url:"name_like,omitempty"` NameLike *string `url:"name_like,omitempty"`
ListOptions ListOptions
} }
// ListZones the zones for an account. // ListZones the zones for an account.
// //
// See https://developer.dnsimple.com/v2/zones/#list // See https://developer.dnsimple.com/v2/zones/#listZones
func (s *ZonesService) ListZones(accountID string, options *ZoneListOptions) (*zonesResponse, error) { func (s *ZonesService) ListZones(ctx context.Context, accountID string, options *ZoneListOptions) (*ZonesResponse, error) {
path := versioned(fmt.Sprintf("/%v/zones", accountID)) path := versioned(fmt.Sprintf("/%v/zones", accountID))
zonesResponse := &zonesResponse{} zonesResponse := &ZonesResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, zonesResponse) resp, err := s.client.get(ctx, path, zonesResponse)
if err != nil { if err != nil {
return zonesResponse, err return zonesResponse, err
} }
zonesResponse.HttpResponse = resp zonesResponse.HTTPResponse = resp
return zonesResponse, nil return zonesResponse, nil
} }
// GetZone fetches a zone. // GetZone fetches a zone.
// //
// See https://developer.dnsimple.com/v2/zones/#get // See https://developer.dnsimple.com/v2/zones/#getZone
func (s *ZonesService) GetZone(accountID string, zoneName string) (*zoneResponse, error) { func (s *ZonesService) GetZone(ctx context.Context, accountID string, zoneName string) (*ZoneResponse, error) {
path := versioned(fmt.Sprintf("/%v/zones/%v", accountID, zoneName)) path := versioned(fmt.Sprintf("/%v/zones/%v", accountID, zoneName))
zoneResponse := &zoneResponse{} zoneResponse := &ZoneResponse{}
resp, err := s.client.get(path, zoneResponse) resp, err := s.client.get(ctx, path, zoneResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
zoneResponse.HttpResponse = resp zoneResponse.HTTPResponse = resp
return zoneResponse, nil return zoneResponse, nil
} }
// GetZoneFile fetches a zone file. // GetZoneFile fetches a zone file.
// //
// See https://developer.dnsimple.com/v2/zones/#get-file // See https://developer.dnsimple.com/v2/zones/#getZoneFile
func (s *ZonesService) GetZoneFile(accountID string, zoneName string) (*zoneFileResponse, error) { func (s *ZonesService) GetZoneFile(ctx context.Context, accountID string, zoneName string) (*ZoneFileResponse, error) {
path := versioned(fmt.Sprintf("/%v/zones/%v/file", accountID, zoneName)) path := versioned(fmt.Sprintf("/%v/zones/%v/file", accountID, zoneName))
zoneFileResponse := &zoneFileResponse{} zoneFileResponse := &ZoneFileResponse{}
resp, err := s.client.get(path, zoneFileResponse) resp, err := s.client.get(ctx, path, zoneFileResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
zoneFileResponse.HttpResponse = resp zoneFileResponse.HTTPResponse = resp
return zoneFileResponse, nil return zoneFileResponse, nil
} }

View File

@ -1,10 +1,11 @@
package dnsimple package dnsimple
import ( import (
"context"
"fmt" "fmt"
) )
// ZoneRecord represents a DNS record in DNSimple. // ZoneRecord represents a zone record in DNSimple.
type ZoneRecord struct { type ZoneRecord struct {
ID int64 `json:"id,omitempty"` ID int64 `json:"id,omitempty"`
ZoneID string `json:"zone_id,omitempty"` ZoneID string `json:"zone_id,omitempty"`
@ -20,6 +21,21 @@ type ZoneRecord struct {
UpdatedAt string `json:"updated_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"`
} }
// ZoneRecordAttributes represents the attributes you can send to create/update a zone record.
//
// Compared to most other calls in this library, you should not use ZoneRecord as payload for record calls.
// This is because it can lead to side effects due to the inability of go to distinguish between a non-present string
// and an empty string. Name can be both, therefore a specific struct is required.
type ZoneRecordAttributes struct {
ZoneID string `json:"zone_id,omitempty"`
Type string `json:"type,omitempty"`
Name *string `json:"name,omitempty"`
Content string `json:"content,omitempty"`
TTL int `json:"ttl,omitempty"`
Priority int `json:"priority,omitempty"`
Regions []string `json:"regions,omitempty"`
}
func zoneRecordPath(accountID string, zoneName string, recordID int64) (path string) { func zoneRecordPath(accountID string, zoneName string, recordID int64) (path string) {
path = fmt.Sprintf("/%v/zones/%v/records", accountID, zoneName) path = fmt.Sprintf("/%v/zones/%v/records", accountID, zoneName)
if recordID != 0 { if recordID != 0 {
@ -28,14 +44,14 @@ func zoneRecordPath(accountID string, zoneName string, recordID int64) (path str
return return
} }
// zoneRecordResponse represents a response from an API method that returns a ZoneRecord struct. // ZoneRecordResponse represents a response from an API method that returns a ZoneRecord struct.
type zoneRecordResponse struct { type ZoneRecordResponse struct {
Response Response
Data *ZoneRecord `json:"data"` Data *ZoneRecord `json:"data"`
} }
// zoneRecordsResponse represents a response from an API method that returns a collection of ZoneRecord struct. // ZoneRecordsResponse represents a response from an API method that returns a collection of ZoneRecord struct.
type zoneRecordsResponse struct { type ZoneRecordsResponse struct {
Response Response
Data []ZoneRecord `json:"data"` Data []ZoneRecord `json:"data"`
} }
@ -44,14 +60,14 @@ type zoneRecordsResponse struct {
// to customize the ZonesService.ListZoneRecords method. // to customize the ZonesService.ListZoneRecords method.
type ZoneRecordListOptions struct { type ZoneRecordListOptions struct {
// Select records where the name matches given string. // Select records where the name matches given string.
Name string `url:"name,omitempty"` Name *string `url:"name,omitempty"`
// Select records where the name contains given string. // Select records where the name contains given string.
NameLike string `url:"name_like,omitempty"` NameLike *string `url:"name_like,omitempty"`
// Select records of given type. // Select records of given type.
// Eg. TXT, A, NS. // Eg. TXT, A, NS.
Type string `url:"type,omitempty"` Type *string `url:"type,omitempty"`
ListOptions ListOptions
} }
@ -59,84 +75,84 @@ type ZoneRecordListOptions struct {
// ListRecords lists the zone records for a zone. // ListRecords lists the zone records for a zone.
// //
// See https://developer.dnsimple.com/v2/zones/records/#listZoneRecords // See https://developer.dnsimple.com/v2/zones/records/#listZoneRecords
func (s *ZonesService) ListRecords(accountID string, zoneName string, options *ZoneRecordListOptions) (*zoneRecordsResponse, error) { func (s *ZonesService) ListRecords(ctx context.Context, accountID string, zoneName string, options *ZoneRecordListOptions) (*ZoneRecordsResponse, error) {
path := versioned(zoneRecordPath(accountID, zoneName, 0)) path := versioned(zoneRecordPath(accountID, zoneName, 0))
recordsResponse := &zoneRecordsResponse{} recordsResponse := &ZoneRecordsResponse{}
path, err := addURLQueryOptions(path, options) path, err := addURLQueryOptions(path, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := s.client.get(path, recordsResponse) resp, err := s.client.get(ctx, path, recordsResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
recordsResponse.HttpResponse = resp recordsResponse.HTTPResponse = resp
return recordsResponse, nil return recordsResponse, nil
} }
// CreateRecord creates a zone record. // CreateRecord creates a zone record.
// //
// See https://developer.dnsimple.com/v2/zones/records/#createZoneRecord // See https://developer.dnsimple.com/v2/zones/records/#createZoneRecord
func (s *ZonesService) CreateRecord(accountID string, zoneName string, recordAttributes ZoneRecord) (*zoneRecordResponse, error) { func (s *ZonesService) CreateRecord(ctx context.Context, accountID string, zoneName string, recordAttributes ZoneRecordAttributes) (*ZoneRecordResponse, error) {
path := versioned(zoneRecordPath(accountID, zoneName, 0)) path := versioned(zoneRecordPath(accountID, zoneName, 0))
recordResponse := &zoneRecordResponse{} recordResponse := &ZoneRecordResponse{}
resp, err := s.client.post(path, recordAttributes, recordResponse) resp, err := s.client.post(ctx, path, recordAttributes, recordResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
recordResponse.HttpResponse = resp recordResponse.HTTPResponse = resp
return recordResponse, nil return recordResponse, nil
} }
// GetRecord fetches a zone record. // GetRecord fetches a zone record.
// //
// See https://developer.dnsimple.com/v2/zones/records/#getZoneRecord // See https://developer.dnsimple.com/v2/zones/records/#getZoneRecord
func (s *ZonesService) GetRecord(accountID string, zoneName string, recordID int64) (*zoneRecordResponse, error) { func (s *ZonesService) GetRecord(ctx context.Context, accountID string, zoneName string, recordID int64) (*ZoneRecordResponse, error) {
path := versioned(zoneRecordPath(accountID, zoneName, recordID)) path := versioned(zoneRecordPath(accountID, zoneName, recordID))
recordResponse := &zoneRecordResponse{} recordResponse := &ZoneRecordResponse{}
resp, err := s.client.get(path, recordResponse) resp, err := s.client.get(ctx, path, recordResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
recordResponse.HttpResponse = resp recordResponse.HTTPResponse = resp
return recordResponse, nil return recordResponse, nil
} }
// UpdateRecord updates a zone record. // UpdateRecord updates a zone record.
// //
// See https://developer.dnsimple.com/v2/zones/records/#updateZoneRecord // See https://developer.dnsimple.com/v2/zones/records/#updateZoneRecord
func (s *ZonesService) UpdateRecord(accountID string, zoneName string, recordID int64, recordAttributes ZoneRecord) (*zoneRecordResponse, error) { func (s *ZonesService) UpdateRecord(ctx context.Context, accountID string, zoneName string, recordID int64, recordAttributes ZoneRecordAttributes) (*ZoneRecordResponse, error) {
path := versioned(zoneRecordPath(accountID, zoneName, recordID)) path := versioned(zoneRecordPath(accountID, zoneName, recordID))
recordResponse := &zoneRecordResponse{} recordResponse := &ZoneRecordResponse{}
resp, err := s.client.patch(path, recordAttributes, recordResponse) resp, err := s.client.patch(ctx, path, recordAttributes, recordResponse)
if err != nil { if err != nil {
return nil, err return nil, err
} }
recordResponse.HttpResponse = resp recordResponse.HTTPResponse = resp
return recordResponse, nil return recordResponse, nil
} }
// DeleteRecord PERMANENTLY deletes a zone record from the zone. // DeleteRecord PERMANENTLY deletes a zone record from the zone.
// //
// See https://developer.dnsimple.com/v2/zones/records/#deleteZoneRecord // See https://developer.dnsimple.com/v2/zones/records/#deleteZoneRecord
func (s *ZonesService) DeleteRecord(accountID string, zoneName string, recordID int64) (*zoneRecordResponse, error) { func (s *ZonesService) DeleteRecord(ctx context.Context, accountID string, zoneName string, recordID int64) (*ZoneRecordResponse, error) {
path := versioned(zoneRecordPath(accountID, zoneName, recordID)) path := versioned(zoneRecordPath(accountID, zoneName, recordID))
recordResponse := &zoneRecordResponse{} recordResponse := &ZoneRecordResponse{}
resp, err := s.client.delete(path, nil, nil) resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
recordResponse.HttpResponse = resp recordResponse.HTTPResponse = resp
return recordResponse, nil return recordResponse, nil
} }

2
vendor/modules.txt vendored
View File

@ -94,7 +94,7 @@ github.com/dgrijalva/jwt-go
github.com/digitalocean/godo github.com/digitalocean/godo
# github.com/dimchansky/utfbom v1.1.0 # github.com/dimchansky/utfbom v1.1.0
github.com/dimchansky/utfbom github.com/dimchansky/utfbom
# github.com/dnsimple/dnsimple-go v0.31.0 # github.com/dnsimple/dnsimple-go v0.62.0
## explicit ## explicit
github.com/dnsimple/dnsimple-go/dnsimple github.com/dnsimple/dnsimple-go/dnsimple
# github.com/exoscale/egoscale v0.23.0 # github.com/exoscale/egoscale v0.23.0