1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
package dnsimple
import (
"context"
"fmt"
)
// TldsService handles communication with the Tld related
// methods of the DNSimple API.
//
// See https://developer.dnsimple.com/v2/tlds/
type TldsService struct {
client *Client
}
// Tld represents a TLD in DNSimple.
type Tld struct {
Tld string `json:"tld"`
TldType int `json:"tld_type"`
WhoisPrivacy bool `json:"whois_privacy"`
AutoRenewOnly bool `json:"auto_renew_only"`
MinimumRegistration int `json:"minimum_registration"`
RegistrationEnabled bool `json:"registration_enabled"`
RenewalEnabled bool `json:"renewal_enabled"`
TransferEnabled bool `json:"transfer_enabled"`
DnssecInterfaceType string `json:"dnssec_interface_type"`
}
// TldExtendedAttribute represents an extended attributes supported or required
// by a specific TLD.
//
// See https://developer.dnsimple.com/v2/tlds/
type TldExtendedAttribute struct {
Name string `json:"name"`
Description string `json:"description"`
Required bool `json:"required"`
Options []TldExtendedAttributeOption `json:"options"`
}
// TldExtendedAttributeOption represents a single option you can assign to an extended attributes.
//
// See https://developer.dnsimple.com/v2/tlds/
type TldExtendedAttributeOption struct {
Title string `json:"title"`
Value string `json:"value"`
Description string `json:"description"`
}
// 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 {
Response
Data []Tld `json:"data"`
}
// TldExtendedAttributesResponse represents a response from an API method that returns
// a collection of Tld extended attributes.
type TldExtendedAttributesResponse struct {
Response
Data []TldExtendedAttribute `json:"data"`
}
// ListTlds lists the supported TLDs.
//
// See https://developer.dnsimple.com/v2/tlds/#list
func (s *TldsService) ListTlds(ctx context.Context, options *ListOptions) (*TldsResponse, error) {
path := versioned("/tlds")
tldsResponse := &TldsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(ctx, path, tldsResponse)
if err != nil {
return tldsResponse, err
}
tldsResponse.HTTPResponse = resp
return tldsResponse, nil
}
// GetTld fetches a TLD.
//
// See https://developer.dnsimple.com/v2/tlds/#get
func (s *TldsService) GetTld(ctx context.Context, tld string) (*TldResponse, error) {
path := versioned(fmt.Sprintf("/tlds/%s", tld))
tldResponse := &TldResponse{}
resp, err := s.client.get(ctx, path, tldResponse)
if err != nil {
return nil, err
}
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(ctx context.Context, tld string) (*TldExtendedAttributesResponse, error) {
path := versioned(fmt.Sprintf("/tlds/%s/extended_attributes", tld))
tldResponse := &TldExtendedAttributesResponse{}
resp, err := s.client.get(ctx, path, tldResponse)
if err != nil {
return nil, err
}
tldResponse.HTTPResponse = resp
return tldResponse, nil
}
|