Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to support latest Cloudflare Registrar responses #719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 82 additions & 1 deletion registrar.go
Expand Up @@ -10,9 +10,25 @@ import (
"github.com/pkg/errors"
)

type RegistrarDomainContacts struct {
Administrator RegistrantContact `json:"administrator"`
Billing RegistrantContact `json:"billing"`
Registrant RegistrantContact `json:"registrant"`
Technical RegistrantContact `json:"technical"`
}

type RegistrarFees struct {
Icann float64 `json:"icann_fee"`
Redemption float64 `json:"redemption_fee"`
Registration float64 `json:"registration_fee"`
Renewal float64 `json:"renewal_fee"`
Transfer float64 `json:"transfer_fee"`
}

// RegistrarDomain is the structure of the API response for a new
// Cloudflare Registrar domain.
type RegistrarDomain struct {
RegistrarDomainConfiguration
ID string `json:"id"`
Available bool `json:"available"`
SupportedTLD bool `json:"supported_tld"`
Expand All @@ -21,10 +37,13 @@ type RegistrarDomain struct {
CurrentRegistrar string `json:"current_registrar"`
ExpiresAt time.Time `json:"expires_at"`
RegistryStatuses string `json:"registry_statuses"`
Locked bool `json:"locked"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
RegistrantContact RegistrantContact `json:"registrant_contact"`
Fees RegistrarFees `json:"fees"`
Name string `json:"name"`
PendingTransfer bool `json:"pending_transfer"`
Permissions []string `json:"permissions"`
}

// RegistrarTransferIn contains the structure for a domain transfer in
Expand Down Expand Up @@ -53,6 +72,8 @@ type RegistrantContact struct {
Phone string `json:"phone"`
Email string `json:"email"`
Fax string `json:"fax"`
Verified bool `json:"email_verified"`
Label string `json:"label"`
}

// RegistrarDomainConfiguration is the structure for making updates to
Expand All @@ -78,6 +99,16 @@ type RegistrarDomainsDetailResponse struct {
Result []RegistrarDomain `json:"result"`
}

type RegistrarContactsDetailResponse struct {
Response
Result []RegistrantContact `json:"result"`
}

type RegistrarContactDetailResponse struct {
Response
Result RegistrantContact `json:"result"`
}

// RegistrarDomain returns a single domain based on the account ID and
// domain name.
//
Expand Down Expand Up @@ -175,3 +206,53 @@ func (api *API) UpdateRegistrarDomain(ctx context.Context, accountID, domainName
}
return r.Result, nil
}

func (api *API) getContacts(ctx context.Context, uri string) ([]RegistrantContact, error) {
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []RegistrantContact{}, err
}

var r RegistrarContactsDetailResponse
err = json.Unmarshal(res, &r)
if err != nil {
return []RegistrantContact{}, errors.Wrap(err, errUnmarshalError)
}

return r.Result, nil
}

// RegistrarContacts gets a list of all Contacts based on the account ID
//
// API reference: undocumented
func (api *API) RegistrarContacts(ctx context.Context, accountID string) ([]RegistrantContact, error) {
uri := fmt.Sprintf("/accounts/%s/registrar/contacts", accountID)
return api.getContacts(ctx, uri)
}

// RegistrarContact gets a RegistrantContact based on the account ID and contact ID
//
// API reference: undocumented
func (api *API) RegistrarContact(ctx context.Context, accountID, contactID string) (RegistrantContact, error) {
uri := fmt.Sprintf("/accounts/%s/registrar/contacts/%s", accountID, contactID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return RegistrantContact{}, err
}

var r RegistrarContactDetailResponse
err = json.Unmarshal(res, &r)
if err != nil {
return RegistrantContact{}, errors.Wrap(err, errUnmarshalError)
}

return r.Result, nil
}

// RegistrarDomainContacts gets a list of all Contacts based on the account and domain ID
//
// API reference: undocumented
func (api *API) RegistrarDomainContacts(ctx context.Context, accountID, domainName string) ([]RegistrantContact, error) {
uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s/contacts", accountID, domainName)
return api.getContacts(ctx, uri)
}