Skip to content

Commit

Permalink
Renamed input structs to clarify intent
Browse files Browse the repository at this point in the history
- DomainRegisterRequest -> RegisterDomainInput
- DomainTransferRequest -> TransferDomainInput
- DomainRenewRequest -> RenewDomainInput
  • Loading branch information
weppos committed May 1, 2020
1 parent 5e58562 commit e022ce6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Incompatible changes:
- NEW: Added support for context (dnsimple/dnsimple-go#82, dnsimple/dnsimple-go#90)

- CHANGED: Changed all method signatures so that the returned value is exported (dnsimple/dnsimple-go#91)
- CHANGED: Renamed the following structs to clarify intent:
- DomainRegisterRequest -> RegisterDomainInput
- DomainTransferRequest -> TransferDomainInput
- DomainRenewRequest -> RenewDomainInput


#### Release 0.40.0
Expand Down
4 changes: 2 additions & 2 deletions dnsimple/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestLive_Registration(t *testing.T) {
accountID := whoami.Account.ID

// TODO: fetch the registrant randomly
registerRequest := &DomainRegisterRequest{RegistrantID: 2}
registerRequest := &RegisterDomainInput{RegistrantID: 2}
registrationResponse, err := dnsimpleClient.Registrar.RegisterDomain(context.Background(), fmt.Sprintf("%v", accountID), fmt.Sprintf("example-%v.com", time.Now().Unix()), registerRequest)
if err != nil {
t.Fatalf("Live Registrar.Register() returned error: %v", err)
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestLive_Error(t *testing.T) {
t.Fatalf("Live Error/Whoami() returned error: %v", err)
}

_, err = dnsimpleClient.Registrar.RegisterDomain(context.Background(), fmt.Sprintf("%v", whoami.Account.ID), fmt.Sprintf("example-%v.test", time.Now().Unix()), &DomainRegisterRequest{})
_, err = dnsimpleClient.Registrar.RegisterDomain(context.Background(), fmt.Sprintf("%v", whoami.Account.ID), fmt.Sprintf("example-%v.test", time.Now().Unix()), &RegisterDomainInput{})
if err == nil {
t.Fatalf("Live Error/RegisterDomain() expected to return error")
}
Expand Down
24 changes: 12 additions & 12 deletions dnsimple/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ type DomainRegistrationResponse struct {
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.
Expand All @@ -131,13 +131,13 @@ type DomainRegisterRequest struct {
// RegisterDomain registers a domain name.
//
// See https://developer.dnsimple.com/v2/registrar/#register
func (s *RegistrarService) RegisterDomain(ctx context.Context, 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{}

// TODO: validate mandatory attributes RegistrantID

resp, err := s.client.post(ctx, path, request, registrationResponse)
resp, err := s.client.post(ctx, path, input, registrationResponse)
if err != nil {
return nil, err
}
Expand All @@ -164,9 +164,9 @@ type DomainTransferResponse struct {
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.
Expand All @@ -187,13 +187,13 @@ type DomainTransferRequest struct {
// TransferDomain transfers a domain name.
//
// See https://developer.dnsimple.com/v2/registrar/#transferDomain
func (s *RegistrarService) TransferDomain(ctx context.Context, accountID string, domainName string, request *DomainTransferRequest) (*DomainTransferResponse, error) {
func (s *RegistrarService) TransferDomain(ctx context.Context, accountID string, domainName string, input *TransferDomainInput) (*DomainTransferResponse, error) {
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/transfers", accountID, domainName))
transferResponse := &DomainTransferResponse{}

// TODO: validate mandatory attributes RegistrantID

resp, err := s.client.post(ctx, path, request, transferResponse)
resp, err := s.client.post(ctx, path, input, transferResponse)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -240,9 +240,9 @@ type DomainRenewalResponse struct {
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.
Expand All @@ -252,11 +252,11 @@ type DomainRenewRequest struct {
// RenewDomain renews a domain name.
//
// See https://developer.dnsimple.com/v2/registrar/#register
func (s *RegistrarService) RenewDomain(ctx context.Context, 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{}

resp, err := s.client.post(ctx, path, request, renewalResponse)
resp, err := s.client.post(ctx, path, input, renewalResponse)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions dnsimple/registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestRegistrarService_RegisterDomain(t *testing.T) {
io.Copy(w, httpResponse.Body)
})

registerRequest := &DomainRegisterRequest{RegistrantID: 2}
registerRequest := &RegisterDomainInput{RegistrantID: 2}

registrationResponse, err := client.Registrar.RegisterDomain(context.Background(), "1010", "example.com", registerRequest)
if err != nil {
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestRegistrarService_RegisterDomain_ExtendedAttributes(t *testing.T) {
io.Copy(w, httpResponse.Body)
})

registerRequest := &DomainRegisterRequest{RegistrantID: 2, ExtendedAttributes: map[string]string{"att1": "val1", "att2": "val2"}}
registerRequest := &RegisterDomainInput{RegistrantID: 2, ExtendedAttributes: map[string]string{"att1": "val1", "att2": "val2"}}

if _, err := client.Registrar.RegisterDomain(context.Background(), "1010", "example.com", registerRequest); err != nil {
t.Fatalf("Registrar.RegisterDomain() returned error: %v", err)
Expand All @@ -157,7 +157,7 @@ func TestRegistrarService_TransferDomain(t *testing.T) {
io.Copy(w, httpResponse.Body)
})

transferRequest := &DomainTransferRequest{RegistrantID: 2, AuthCode: "x1y2z3"}
transferRequest := &TransferDomainInput{RegistrantID: 2, AuthCode: "x1y2z3"}

transferResponse, err := client.Registrar.TransferDomain(context.Background(), "1010", "example.com", transferRequest)
if err != nil {
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestRegistrarService_TransferDomain_ExtendedAttributes(t *testing.T) {
io.Copy(w, httpResponse.Body)
})

transferRequest := &DomainTransferRequest{RegistrantID: 2, AuthCode: "x1y2z3", ExtendedAttributes: map[string]string{"att1": "val1", "att2": "val2"}}
transferRequest := &TransferDomainInput{RegistrantID: 2, AuthCode: "x1y2z3", ExtendedAttributes: map[string]string{"att1": "val1", "att2": "val2"}}

if _, err := client.Registrar.TransferDomain(context.Background(), "1010", "example.com", transferRequest); err != nil {
t.Fatalf("Registrar.TransferDomain() returned error: %v", err)
Expand Down

0 comments on commit e022ce6

Please sign in to comment.