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

View File

@ -1,5 +1,13 @@
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 {
client *Client
}
@ -13,8 +21,8 @@ type Account struct {
UpdatedAt string `json:"updated_at,omitempty"`
}
// accountsResponse represents a response from an API method that returns a collection of Account struct.
type accountsResponse struct {
// AccountsResponse represents a response from an API method that returns a collection of Account struct.
type AccountsResponse struct {
Response
Data []Account `json:"data"`
}
@ -22,20 +30,20 @@ type accountsResponse struct {
// ListAccounts list the accounts for an user.
//
// 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")
accountsResponse := &accountsResponse{}
accountsResponse := &AccountsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(path, accountsResponse)
resp, err := s.client.get(ctx, path, accountsResponse)
if err != nil {
return accountsResponse, err
}
accountsResponse.HttpResponse = resp
accountsResponse.HTTPResponse = resp
return accountsResponse, nil
}

View File

@ -1,9 +1,24 @@
package dnsimple
import (
"context"
"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
// using HTTP Basic Authentication with the provided username and password.
type BasicAuthTransport struct {

View File

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

View File

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

View File

@ -4,7 +4,9 @@ package dnsimple
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
@ -23,7 +25,7 @@ const (
// This is a pro-forma convention given that Go dependencies
// tends to be fetched directly from the repo.
// 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 = "https://api.dnsimple.com"
@ -68,18 +70,18 @@ type Client struct {
}
// 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 {
// The page to return
Page int `url:"page,omitempty"`
Page *int `url:"page,omitempty"`
// 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 value is a comma-separated list of field[:direction],
// 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.
@ -104,10 +106,101 @@ func NewClient(httpClient *http.Client) *Client {
return c
}
// 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) {
// SetUserAgent overrides the default UserAgent.
//
// When 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 (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
body := new(bytes.Buffer)
@ -123,91 +216,36 @@ func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Req
return nil, err
}
combinedHeaders := make(http.Header)
copyHeader(combinedHeaders, headers)
req.Header = combinedHeaders
req.Header.Set("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
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.
//
// 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.
//
// dnsimple-go/1.0 customAgentFlag
//
func formatUserAgent(customUserAgent string) string {
if customUserAgent == "" {
return defaultUserAgent
// 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
}
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.
// request sends the HTTP request and returns the HTTP response.
//
// The API response is JSON decoded and stored in the value pointed by obj,
// The HTTP response is JSON decoded and stored in the value pointed by obj,
// 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,
// without attempting to decode it.
func (c *Client) Do(req *http.Request, obj interface{}) (*http.Response, error) {
if c.Debug {
log.Printf("Executing request (%v): %#v", req.URL, req)
func (c *Client) request(ctx context.Context, req *http.Request, obj interface{}) (*http.Response, error) {
if ctx == nil {
return nil, errors.New("context must be non-nil")
}
req = req.WithContext(ctx)
resp, err := c.httpClient.Do(req)
if err != nil {
@ -215,10 +253,6 @@ func (c *Client) Do(req *http.Request, obj interface{}) (*http.Response, error)
}
defer resp.Body.Close()
if c.Debug {
log.Printf("Response received: %#v", resp)
}
err = CheckResponse(resp)
if err != nil {
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.
type Response struct {
// HTTP response
HttpResponse *http.Response
HTTPResponse *http.Response
// If the response is paginated, the Pagination will store them.
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.
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
}
// RateLimitRemaining returns the remaining amount of requests this account can send within this hour window.
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
}
// RateLimitReset returns when the throttling window will be reset for this account.
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)
}
// If the response is paginated, Pagination represents the pagination information.
// Pagination represents the pagination information, if the response is paginated.
type Pagination struct {
CurrentPage int `json:"current_page"`
PerPage int `json:"per_page"`
@ -283,8 +317,8 @@ type ErrorResponse struct {
// Error implements the error interface.
func (r *ErrorResponse) Error() string {
return fmt.Sprintf("%v %v: %v %v",
r.HttpResponse.Request.Method, r.HttpResponse.Request.URL,
r.HttpResponse.StatusCode, r.Message)
r.HTTPResponse.Request.Method, r.HTTPResponse.Request.URL,
r.HTTPResponse.StatusCode, r.Message)
}
// 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.HttpResponse = resp
errorResponse.HTTPResponse = resp
err := json.NewDecoder(resp.Body).Decode(errorResponse)
if err != nil {
@ -329,10 +363,22 @@ func addURLQueryOptions(path string, options interface{}) (string, error) {
}
uqs := u.Query()
for k, _ := range qs {
for k := range qs {
uqs.Set(k, qs.Get(k))
}
u.RawQuery = uqs.Encode()
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
import (
"context"
"fmt"
)
@ -36,14 +37,14 @@ func domainPath(accountID string, domainIdentifier string) (path string) {
return
}
// domainResponse represents a response from an API method that returns a Domain struct.
type domainResponse struct {
// DomainResponse represents a response from an API method that returns a Domain struct.
type DomainResponse struct {
Response
Data *Domain `json:"data"`
}
// domainsResponse represents a response from an API method that returns a collection of Domain struct.
type domainsResponse struct {
// DomainsResponse represents a response from an API method that returns a collection of Domain struct.
type DomainsResponse struct {
Response
Data []Domain `json:"data"`
}
@ -52,10 +53,10 @@ type domainsResponse struct {
// to customize the DomainsService.ListDomains method.
type DomainListOptions struct {
// 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.
RegistrantID int `url:"registrant_id,omitempty"`
RegistrantID *int `url:"registrant_id,omitempty"`
ListOptions
}
@ -63,76 +64,68 @@ type DomainListOptions struct {
// ListDomains lists the domains for an account.
//
// 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, ""))
domainsResponse := &domainsResponse{}
domainsResponse := &DomainsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(path, domainsResponse)
resp, err := s.client.get(ctx, path, domainsResponse)
if err != nil {
return nil, err
}
domainsResponse.HttpResponse = resp
domainsResponse.HTTPResponse = resp
return domainsResponse, nil
}
// CreateDomain creates a new domain in the account.
//
// 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, ""))
domainResponse := &domainResponse{}
domainResponse := &DomainResponse{}
resp, err := s.client.post(path, domainAttributes, domainResponse)
resp, err := s.client.post(ctx, path, domainAttributes, domainResponse)
if err != nil {
return nil, err
}
domainResponse.HttpResponse = resp
domainResponse.HTTPResponse = resp
return domainResponse, nil
}
// GetDomain fetches a domain.
//
// 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))
domainResponse := &domainResponse{}
domainResponse := &DomainResponse{}
resp, err := s.client.get(path, domainResponse)
resp, err := s.client.get(ctx, path, domainResponse)
if err != nil {
return nil, err
}
domainResponse.HttpResponse = resp
domainResponse.HTTPResponse = resp
return domainResponse, nil
}
// DeleteDomain PERMANENTLY deletes a domain from the account.
//
// 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))
domainResponse := &domainResponse{}
domainResponse := &DomainResponse{}
resp, err := s.client.delete(path, nil, nil)
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
domainResponse.HttpResponse = resp
domainResponse.HTTPResponse = resp
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
import (
"context"
"fmt"
)
@ -30,14 +31,14 @@ type CollaboratorAttributes struct {
Email string `json:"email,omitempty"`
}
// collaboratorResponse represents a response from an API method that returns a Collaborator struct.
type collaboratorResponse struct {
// CollaboratorResponse represents a response from an API method that returns a Collaborator struct.
type CollaboratorResponse struct {
Response
Data *Collaborator `json:"data"`
}
// collaboratorsResponse represents a response from an API method that returns a collection of Collaborator struct.
type collaboratorsResponse struct {
// CollaboratorsResponse represents a response from an API method that returns a collection of Collaborator struct.
type CollaboratorsResponse struct {
Response
Data []Collaborator `json:"data"`
}
@ -45,52 +46,52 @@ type collaboratorsResponse struct {
// ListCollaborators list the collaborators for a domain.
//
// 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))
collaboratorsResponse := &collaboratorsResponse{}
collaboratorsResponse := &CollaboratorsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(path, collaboratorsResponse)
resp, err := s.client.get(ctx, path, collaboratorsResponse)
if err != nil {
return collaboratorsResponse, err
}
collaboratorsResponse.HttpResponse = resp
collaboratorsResponse.HTTPResponse = resp
return collaboratorsResponse, nil
}
// AddCollaborator adds a new collaborator to the domain in the account.
//
// 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))
collaboratorResponse := &collaboratorResponse{}
collaboratorResponse := &CollaboratorResponse{}
resp, err := s.client.post(path, attributes, collaboratorResponse)
resp, err := s.client.post(ctx, path, attributes, collaboratorResponse)
if err != nil {
return nil, err
}
collaboratorResponse.HttpResponse = resp
collaboratorResponse.HTTPResponse = resp
return collaboratorResponse, nil
}
// RemoveCollaborator PERMANENTLY deletes a domain from the account.
//
// 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))
collaboratorResponse := &collaboratorResponse{}
collaboratorResponse := &CollaboratorResponse{}
resp, err := s.client.delete(path, nil, nil)
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
collaboratorResponse.HttpResponse = resp
collaboratorResponse.HTTPResponse = resp
return collaboratorResponse, nil
}

View File

@ -1,6 +1,9 @@
package dnsimple
import "fmt"
import (
"context"
"fmt"
)
// DelegationSignerRecord represents a delegation signer record for a domain in DNSimple.
type DelegationSignerRecord struct {
@ -22,14 +25,14 @@ func delegationSignerRecordPath(accountID string, domainIdentifier string, dsRec
return
}
// delegationSignerRecordResponse represents a response from an API method that returns a DelegationSignerRecord struct.
type delegationSignerRecordResponse struct {
// DelegationSignerRecordResponse represents a response from an API method that returns a DelegationSignerRecord struct.
type DelegationSignerRecordResponse struct {
Response
Data *DelegationSignerRecord `json:"data"`
}
// delegationSignerRecordResponse represents a response from an API method that returns a DelegationSignerRecord struct.
type delegationSignerRecordsResponse struct {
// DelegationSignerRecordsResponse represents a response from an API method that returns a DelegationSignerRecord struct.
type DelegationSignerRecordsResponse struct {
Response
Data []DelegationSignerRecord `json:"data"`
}
@ -37,53 +40,53 @@ type delegationSignerRecordsResponse struct {
// ListDelegationSignerRecords lists the delegation signer records for a domain.
//
// 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))
dsRecordsResponse := &delegationSignerRecordsResponse{}
dsRecordsResponse := &DelegationSignerRecordsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(path, dsRecordsResponse)
resp, err := s.client.get(ctx, path, dsRecordsResponse)
if err != nil {
return nil, err
}
dsRecordsResponse.HttpResponse = resp
dsRecordsResponse.HTTPResponse = resp
return dsRecordsResponse, nil
}
// CreateDelegationSignerRecord creates a new delegation signer record.
//
// 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))
dsRecordResponse := &delegationSignerRecordResponse{}
dsRecordResponse := &DelegationSignerRecordResponse{}
resp, err := s.client.post(path, dsRecordAttributes, dsRecordResponse)
resp, err := s.client.post(ctx, path, dsRecordAttributes, dsRecordResponse)
if err != nil {
return nil, err
}
dsRecordResponse.HttpResponse = resp
dsRecordResponse.HTTPResponse = resp
return dsRecordResponse, nil
}
// GetDelegationSignerRecord fetches a delegation signer record.
//
// 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))
dsRecordResponse := &delegationSignerRecordResponse{}
dsRecordResponse := &DelegationSignerRecordResponse{}
resp, err := s.client.get(path, dsRecordResponse)
resp, err := s.client.get(ctx, path, dsRecordResponse)
if err != nil {
return nil, err
}
dsRecordResponse.HttpResponse = resp
dsRecordResponse.HTTPResponse = resp
return dsRecordResponse, nil
}
@ -91,15 +94,15 @@ func (s *DomainsService) GetDelegationSignerRecord(accountID string, domainIdent
// from the domain.
//
// 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))
dsRecordResponse := &delegationSignerRecordResponse{}
dsRecordResponse := &DelegationSignerRecordResponse{}
resp, err := s.client.delete(path, nil, nil)
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
dsRecordResponse.HttpResponse = resp
dsRecordResponse.HTTPResponse = resp
return dsRecordResponse, nil
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package dnsimple
import (
"context"
"fmt"
)
@ -19,8 +20,8 @@ type DomainCheck struct {
Premium bool `json:"premium"`
}
// domainCheckResponse represents a response from a domain check request.
type domainCheckResponse struct {
// DomainCheckResponse represents a response from a domain check request.
type DomainCheckResponse struct {
Response
Data *DomainCheck `json:"data"`
}
@ -28,16 +29,16 @@ type domainCheckResponse struct {
// CheckDomain checks a domain name.
//
// 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))
checkResponse := &domainCheckResponse{}
checkResponse := &DomainCheckResponse{}
resp, err := s.client.get(path, checkResponse)
resp, err := s.client.get(ctx, path, checkResponse)
if err != nil {
return nil, err
}
checkResponse.HttpResponse = resp
checkResponse.HTTPResponse = resp
return checkResponse, nil
}
@ -50,8 +51,8 @@ type DomainPremiumPrice struct {
Action string `json:"action"`
}
// domainPremiumPriceResponse represents a response from a domain premium price request.
type domainPremiumPriceResponse struct {
// DomainPremiumPriceResponse represents a response from a domain premium price request.
type DomainPremiumPriceResponse struct {
Response
Data *DomainPremiumPrice `json:"data"`
}
@ -70,10 +71,10 @@ type DomainPremiumPriceOptions struct {
// - renewal
//
// 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
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/premium_price", accountID, domainName))
priceResponse := &domainPremiumPriceResponse{}
priceResponse := &DomainPremiumPriceResponse{}
if options != nil {
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 {
return nil, err
}
priceResponse.HttpResponse = resp
priceResponse.HTTPResponse = resp
return priceResponse, nil
}
@ -104,15 +105,15 @@ type DomainRegistration struct {
UpdatedAt string `json:"updated_at,omitempty"`
}
// domainRegistrationResponse represents a response from an API method that results in a domain registration.
type domainRegistrationResponse struct {
// DomainRegistrationResponse represents a response from an API method that results in a domain registration.
type DomainRegistrationResponse struct {
Response
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.
type DomainRegisterRequest struct {
type RegisterDomainInput struct {
// The ID of the Contact to use as registrant for the domain
RegistrantID int `json:"registrant_id"`
// 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.
// Default to true.
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.
PremiumPrice string `json:"premium_price,omitempty"`
}
@ -128,42 +131,43 @@ type DomainRegisterRequest struct {
// RegisterDomain registers a domain name.
//
// 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))
registrationResponse := &domainRegistrationResponse{}
registrationResponse := &DomainRegistrationResponse{}
// 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 {
return nil, err
}
registrationResponse.HttpResponse = resp
registrationResponse.HTTPResponse = resp
return registrationResponse, nil
}
// DomainTransfer represents the result of a domain renewal call.
type DomainTransfer struct {
ID int `json:"id"`
DomainID int `json:"domain_id"`
RegistrantID int `json:"registrant_id"`
State string `json:"state"`
AutoRenew bool `json:"auto_renew"`
WhoisPrivacy bool `json:"whois_privacy"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
ID int `json:"id"`
DomainID int `json:"domain_id"`
RegistrantID int `json:"registrant_id"`
State string `json:"state"`
AutoRenew bool `json:"auto_renew"`
WhoisPrivacy bool `json:"whois_privacy"`
StatusDescription string `json:"status_description"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
// domainTransferResponse represents a response from an API method that results in a domain transfer.
type domainTransferResponse struct {
// DomainTransferResponse represents a response from an API method that results in a domain transfer.
type DomainTransferResponse struct {
Response
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.
type DomainTransferRequest struct {
type TransferDomainInput struct {
// The ID of the Contact to use as registrant for the domain
RegistrantID int `json:"registrant_id"`
// 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.
// Default to true.
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.
PremiumPrice string `json:"premium_price,omitempty"`
}
// TransferDomain transfers a domain name.
//
// See https://developer.dnsimple.com/v2/registrar/#transfer
func (s *RegistrarService) TransferDomain(accountID string, domainName string, request *DomainTransferRequest) (*domainTransferResponse, error) {
// See https://developer.dnsimple.com/v2/registrar/#transferDomain
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))
transferResponse := &domainTransferResponse{}
transferResponse := &DomainTransferResponse{}
// 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 {
return nil, err
}
transferResponse.HttpResponse = resp
transferResponse.HTTPResponse = resp
return transferResponse, nil
}
// domainTransferOutResponse represents a response from an API method that results in a domain transfer out.
type domainTransferOutResponse struct {
// GetDomainTransfer fetches a domain transfer.
//
// 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
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
func (s *RegistrarService) TransferDomainOut(accountID string, domainName string) (*domainTransferOutResponse, error) {
// See https://developer.dnsimple.com/v2/registrar/#authorizeDomainTransferOut
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))
transferResponse := &domainTransferOutResponse{}
transferResponse := &DomainTransferOutResponse{}
resp, err := s.client.post(path, nil, nil)
resp, err := s.client.post(ctx, path, nil, nil)
if err != nil {
return nil, err
}
transferResponse.HttpResponse = resp
transferResponse.HTTPResponse = resp
return transferResponse, nil
}
@ -229,15 +267,15 @@ type DomainRenewal struct {
UpdatedAt string `json:"updated_at,omitempty"`
}
// domainRenewalResponse represents a response from an API method that returns a domain renewal.
type domainRenewalResponse struct {
// DomainRenewalResponse represents a response from an API method that returns a domain renewal.
type DomainRenewalResponse struct {
Response
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.
type DomainRenewRequest struct {
type RenewDomainInput struct {
// The number of years
Period int `json:"period"`
// Required as confirmation of the price, only if the domain is premium.
@ -247,15 +285,15 @@ type DomainRenewRequest struct {
// RenewDomain renews a domain name.
//
// 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))
renewalResponse := &domainRenewalResponse{}
renewalResponse := &DomainRenewalResponse{}
resp, err := s.client.post(path, request, renewalResponse)
resp, err := s.client.post(ctx, path, input, renewalResponse)
if err != nil {
return nil, err
}
renewalResponse.HttpResponse = resp
renewalResponse.HTTPResponse = resp
return renewalResponse, nil
}

View File

@ -1,37 +1,38 @@
package dnsimple
import (
"context"
"fmt"
)
// EnableDomainAutoRenewal enables auto-renewal for the domain.
//
// 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))
domainResponse := &domainResponse{}
domainResponse := &DomainResponse{}
resp, err := s.client.put(path, nil, nil)
resp, err := s.client.put(ctx, path, nil, nil)
if err != nil {
return nil, err
}
domainResponse.HttpResponse = resp
domainResponse.HTTPResponse = resp
return domainResponse, nil
}
// DisableDomainAutoRenewal disables auto-renewal for the domain.
//
// 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))
domainResponse := &domainResponse{}
domainResponse := &DomainResponse{}
resp, err := s.client.delete(path, nil, nil)
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
domainResponse.HttpResponse = resp
domainResponse.HTTPResponse = resp
return domainResponse, nil
}

View File

@ -1,20 +1,21 @@
package dnsimple
import (
"context"
"fmt"
)
// Delegation represents a list of name servers that correspond to a domain delegation.
type Delegation []string
// delegationResponse represents a response from an API method that returns a delegation struct.
type delegationResponse struct {
// DelegationResponse represents a response from an API method that returns a delegation struct.
type DelegationResponse struct {
Response
Data *Delegation `json:"data"`
}
// vanityDelegationResponse represents a response for vanity name server enable and disable operations.
type vanityDelegationResponse struct {
// VanityDelegationResponse represents a response for vanity name server enable and disable operations.
type VanityDelegationResponse struct {
Response
Data []VanityNameServer `json:"data"`
}
@ -22,63 +23,63 @@ type vanityDelegationResponse struct {
// GetDomainDelegation gets the current delegated name servers for the domain.
//
// 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))
delegationResponse := &delegationResponse{}
delegationResponse := &DelegationResponse{}
resp, err := s.client.get(path, delegationResponse)
resp, err := s.client.get(ctx, path, delegationResponse)
if err != nil {
return nil, err
}
delegationResponse.HttpResponse = resp
delegationResponse.HTTPResponse = resp
return delegationResponse, nil
}
// ChangeDomainDelegation updates the delegated name severs for the domain.
//
// 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))
delegationResponse := &delegationResponse{}
delegationResponse := &DelegationResponse{}
resp, err := s.client.put(path, newDelegation, delegationResponse)
resp, err := s.client.put(ctx, path, newDelegation, delegationResponse)
if err != nil {
return nil, err
}
delegationResponse.HttpResponse = resp
delegationResponse.HTTPResponse = resp
return delegationResponse, nil
}
// ChangeDomainDelegationToVanity enables vanity name servers for the given domain.
//
// 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))
delegationResponse := &vanityDelegationResponse{}
delegationResponse := &VanityDelegationResponse{}
resp, err := s.client.put(path, newDelegation, delegationResponse)
resp, err := s.client.put(ctx, path, newDelegation, delegationResponse)
if err != nil {
return nil, err
}
delegationResponse.HttpResponse = resp
delegationResponse.HTTPResponse = resp
return delegationResponse, nil
}
// ChangeDomainDelegationFromVanity disables vanity name servers for the given domain.
//
// 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))
delegationResponse := &vanityDelegationResponse{}
delegationResponse := &VanityDelegationResponse{}
resp, err := s.client.delete(path, nil, nil)
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
delegationResponse.HttpResponse = resp
delegationResponse.HTTPResponse = resp
return delegationResponse, nil
}

View File

@ -1,6 +1,7 @@
package dnsimple
import (
"context"
"fmt"
)
@ -26,14 +27,14 @@ type WhoisPrivacyRenewal struct {
UpdatedAt string `json:"updated_at,omitempty"`
}
// whoisPrivacyResponse represents a response from an API method that returns a WhoisPrivacy struct.
type whoisPrivacyResponse struct {
// WhoisPrivacyResponse represents a response from an API method that returns a WhoisPrivacy struct.
type WhoisPrivacyResponse struct {
Response
Data *WhoisPrivacy `json:"data"`
}
// whoisPrivacyRenewalResponse represents a response from an API method that returns a WhoisPrivacyRenewal struct.
type whoisPrivacyRenewalResponse struct {
// WhoisPrivacyRenewalResponse represents a response from an API method that returns a WhoisPrivacyRenewal struct.
type WhoisPrivacyRenewalResponse struct {
Response
Data *WhoisPrivacyRenewal `json:"data"`
}
@ -41,63 +42,63 @@ type whoisPrivacyRenewalResponse struct {
// GetWhoisPrivacy gets the whois privacy for the domain.
//
// 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))
privacyResponse := &whoisPrivacyResponse{}
privacyResponse := &WhoisPrivacyResponse{}
resp, err := s.client.get(path, privacyResponse)
resp, err := s.client.get(ctx, path, privacyResponse)
if err != nil {
return nil, err
}
privacyResponse.HttpResponse = resp
privacyResponse.HTTPResponse = resp
return privacyResponse, nil
}
// EnableWhoisPrivacy enables the whois privacy for the domain.
//
// 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))
privacyResponse := &whoisPrivacyResponse{}
privacyResponse := &WhoisPrivacyResponse{}
resp, err := s.client.put(path, nil, privacyResponse)
resp, err := s.client.put(ctx, path, nil, privacyResponse)
if err != nil {
return nil, err
}
privacyResponse.HttpResponse = resp
privacyResponse.HTTPResponse = resp
return privacyResponse, nil
}
// DisableWhoisPrivacy disables the whois privacy for the domain.
//
// 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))
privacyResponse := &whoisPrivacyResponse{}
privacyResponse := &WhoisPrivacyResponse{}
resp, err := s.client.delete(path, nil, privacyResponse)
resp, err := s.client.delete(ctx, path, nil, privacyResponse)
if err != nil {
return nil, err
}
privacyResponse.HttpResponse = resp
privacyResponse.HTTPResponse = resp
return privacyResponse, nil
}
// RenewWhoisPrivacy renews the whois privacy for the domain.
//
// 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))
privacyRenewalResponse := &whoisPrivacyRenewalResponse{}
privacyRenewalResponse := &WhoisPrivacyRenewalResponse{}
resp, err := s.client.post(path, nil, privacyRenewalResponse)
resp, err := s.client.post(ctx, path, nil, privacyRenewalResponse)
if err != nil {
return nil, err
}
privacyRenewalResponse.HttpResponse = resp
privacyRenewalResponse.HTTPResponse = resp
return privacyRenewalResponse, nil
}

View File

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

View File

@ -1,6 +1,7 @@
package dnsimple
import (
"context"
"fmt"
)
@ -19,52 +20,52 @@ type DomainServiceSettings struct {
// AppliedServices lists the applied one-click services for a domain.
//
// 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, ""))
servicesResponse := &servicesResponse{}
servicesResponse := &ServicesResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(path, servicesResponse)
resp, err := s.client.get(ctx, path, servicesResponse)
if err != nil {
return servicesResponse, err
}
servicesResponse.HttpResponse = resp
servicesResponse.HTTPResponse = resp
return servicesResponse, nil
}
// ApplyService applies a one-click services to a domain.
//
// 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))
serviceResponse := &serviceResponse{}
serviceResponse := &ServiceResponse{}
resp, err := s.client.post(path, settings, nil)
resp, err := s.client.post(ctx, path, settings, nil)
if err != nil {
return nil, err
}
serviceResponse.HttpResponse = resp
serviceResponse.HTTPResponse = resp
return serviceResponse, nil
}
// UnapplyService unapplies a one-click services from a domain.
//
// 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))
serviceResponse := &serviceResponse{}
serviceResponse := &ServiceResponse{}
resp, err := s.client.delete(path, nil, nil)
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
serviceResponse.HttpResponse = resp
serviceResponse.HTTPResponse = resp
return serviceResponse, nil
}

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package dnsimple
import (
"context"
"fmt"
)
@ -44,21 +45,21 @@ type TldExtendedAttributeOption struct {
Description string `json:"description"`
}
// tldResponse represents a response from an API method that returns a Tld struct.
type tldResponse struct {
// TldResponse represents a response from an API method that returns a Tld struct.
type TldResponse struct {
Response
Data *Tld `json:"data"`
}
// tldsResponse represents a response from an API method that returns a collection of Tld struct.
type tldsResponse struct {
// TldsResponse represents a response from an API method that returns a collection of Tld struct.
type TldsResponse struct {
Response
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.
type tldExtendedAttributesResponse struct {
type TldExtendedAttributesResponse struct {
Response
Data []TldExtendedAttribute `json:"data"`
}
@ -66,52 +67,52 @@ type tldExtendedAttributesResponse struct {
// ListTlds lists the supported TLDs.
//
// 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")
tldsResponse := &tldsResponse{}
tldsResponse := &TldsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(path, tldsResponse)
resp, err := s.client.get(ctx, path, tldsResponse)
if err != nil {
return tldsResponse, err
}
tldsResponse.HttpResponse = resp
tldsResponse.HTTPResponse = resp
return tldsResponse, nil
}
// GetTld fetches a TLD.
//
// 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))
tldResponse := &tldResponse{}
tldResponse := &TldResponse{}
resp, err := s.client.get(path, tldResponse)
resp, err := s.client.get(ctx, path, tldResponse)
if err != nil {
return nil, err
}
tldResponse.HttpResponse = resp
tldResponse.HTTPResponse = resp
return tldResponse, nil
}
// GetTldExtendedAttributes fetches the extended attributes of a TLD.
//
// 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))
tldResponse := &tldExtendedAttributesResponse{}
tldResponse := &TldExtendedAttributesResponse{}
resp, err := s.client.get(path, tldResponse)
resp, err := s.client.get(ctx, path, tldResponse)
if err != nil {
return nil, err
}
tldResponse.HttpResponse = resp
tldResponse.HTTPResponse = resp
return tldResponse, nil
}

View File

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

View File

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

View File

@ -1,14 +1,17 @@
package dnsimple
import "fmt"
import (
"context"
"fmt"
)
// ZoneDistribution is the result of the zone distribution check.
type ZoneDistribution struct {
Distributed bool `json:"distributed"`
}
// zoneDistributionResponse represents a response from an API method that returns a ZoneDistribution struct.
type zoneDistributionResponse struct {
// ZoneDistributionResponse represents a response from an API method that returns a ZoneDistribution struct.
type ZoneDistributionResponse struct {
Response
Data *ZoneDistribution `json:"data"`
}
@ -16,31 +19,31 @@ type zoneDistributionResponse struct {
// CheckZoneDistribution checks if a zone is fully distributed across DNSimple nodes.
//
// 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))
zoneDistributionResponse := &zoneDistributionResponse{}
zoneDistributionResponse := &ZoneDistributionResponse{}
resp, err := s.client.get(path, zoneDistributionResponse)
resp, err := s.client.get(ctx, path, zoneDistributionResponse)
if err != nil {
return nil, err
}
zoneDistributionResponse.HttpResponse = resp
zoneDistributionResponse.HTTPResponse = resp
return zoneDistributionResponse, nil
}
// CheckZoneRecordDistribution checks if a zone is fully distributed across DNSimple nodes.
//
// 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))
zoneDistributionResponse := &zoneDistributionResponse{}
zoneDistributionResponse := &ZoneDistributionResponse{}
resp, err := s.client.get(path, zoneDistributionResponse)
resp, err := s.client.get(ctx, path, zoneDistributionResponse)
if err != nil {
return nil, err
}
zoneDistributionResponse.HttpResponse = resp
zoneDistributionResponse.HTTPResponse = resp
return zoneDistributionResponse, nil
}

View File

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

View File

@ -1,10 +1,11 @@
package dnsimple
import (
"context"
"fmt"
)
// ZoneRecord represents a DNS record in DNSimple.
// ZoneRecord represents a zone record in DNSimple.
type ZoneRecord struct {
ID int64 `json:"id,omitempty"`
ZoneID string `json:"zone_id,omitempty"`
@ -20,6 +21,21 @@ type ZoneRecord struct {
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) {
path = fmt.Sprintf("/%v/zones/%v/records", accountID, zoneName)
if recordID != 0 {
@ -28,14 +44,14 @@ func zoneRecordPath(accountID string, zoneName string, recordID int64) (path str
return
}
// zoneRecordResponse represents a response from an API method that returns a ZoneRecord struct.
type zoneRecordResponse struct {
// ZoneRecordResponse represents a response from an API method that returns a ZoneRecord struct.
type ZoneRecordResponse struct {
Response
Data *ZoneRecord `json:"data"`
}
// zoneRecordsResponse represents a response from an API method that returns a collection of ZoneRecord struct.
type zoneRecordsResponse struct {
// ZoneRecordsResponse represents a response from an API method that returns a collection of ZoneRecord struct.
type ZoneRecordsResponse struct {
Response
Data []ZoneRecord `json:"data"`
}
@ -44,14 +60,14 @@ type zoneRecordsResponse struct {
// to customize the ZonesService.ListZoneRecords method.
type ZoneRecordListOptions struct {
// 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.
NameLike string `url:"name_like,omitempty"`
NameLike *string `url:"name_like,omitempty"`
// Select records of given type.
// Eg. TXT, A, NS.
Type string `url:"type,omitempty"`
Type *string `url:"type,omitempty"`
ListOptions
}
@ -59,84 +75,84 @@ type ZoneRecordListOptions struct {
// ListRecords lists the zone records for a zone.
//
// 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))
recordsResponse := &zoneRecordsResponse{}
recordsResponse := &ZoneRecordsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(path, recordsResponse)
resp, err := s.client.get(ctx, path, recordsResponse)
if err != nil {
return nil, err
}
recordsResponse.HttpResponse = resp
recordsResponse.HTTPResponse = resp
return recordsResponse, nil
}
// CreateRecord creates a zone record.
//
// 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))
recordResponse := &zoneRecordResponse{}
recordResponse := &ZoneRecordResponse{}
resp, err := s.client.post(path, recordAttributes, recordResponse)
resp, err := s.client.post(ctx, path, recordAttributes, recordResponse)
if err != nil {
return nil, err
}
recordResponse.HttpResponse = resp
recordResponse.HTTPResponse = resp
return recordResponse, nil
}
// GetRecord fetches a zone record.
//
// 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))
recordResponse := &zoneRecordResponse{}
recordResponse := &ZoneRecordResponse{}
resp, err := s.client.get(path, recordResponse)
resp, err := s.client.get(ctx, path, recordResponse)
if err != nil {
return nil, err
}
recordResponse.HttpResponse = resp
recordResponse.HTTPResponse = resp
return recordResponse, nil
}
// UpdateRecord updates a zone record.
//
// 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))
recordResponse := &zoneRecordResponse{}
resp, err := s.client.patch(path, recordAttributes, recordResponse)
recordResponse := &ZoneRecordResponse{}
resp, err := s.client.patch(ctx, path, recordAttributes, recordResponse)
if err != nil {
return nil, err
}
recordResponse.HttpResponse = resp
recordResponse.HTTPResponse = resp
return recordResponse, nil
}
// DeleteRecord PERMANENTLY deletes a zone record from the zone.
//
// 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))
recordResponse := &zoneRecordResponse{}
recordResponse := &ZoneRecordResponse{}
resp, err := s.client.delete(path, nil, nil)
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
recordResponse.HttpResponse = resp
recordResponse.HTTPResponse = resp
return recordResponse, nil
}