Skip to content

Commit

Permalink
feat: add nameserver.ListWithParams (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
costasd and ldez committed Oct 12, 2023
1 parent dfd35b6 commit 2dbc0cc
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (s *NameserverService) Check(domain string, nameservers []string) (*Nameser
}

// Info gets information.
func (s *NameserverService) Info(request *NameserverInfoRequest) (*NamserverInfoResponse, error) {
func (s *NameserverService) Info(request *NameserverInfoRequest) (*NameserverInfoResponse, error) {
req := s.client.NewRequest(methodNameserverInfo, structs.Map(request))

resp, err := s.client.Do(req)
if err != nil {
return nil, err
}

result := NamserverInfoResponse{}
result := NameserverInfoResponse{}
err = mapstructure.Decode(resp, &result)
if err != nil {
return nil, err
Expand All @@ -64,7 +64,8 @@ func (s *NameserverService) Info(request *NameserverInfoRequest) (*NamserverInfo
}

// List lists nameservers for a domain.
func (s *NameserverService) List(domain string) (*NamserverListResponse, error) {
// Deprecated: use ListWithParams instead.
func (s *NameserverService) List(domain string) (*NameserverListResponse, error) {
requestMap := map[string]interface{}{
"domain": "*",
"wide": 2,
Expand All @@ -81,7 +82,32 @@ func (s *NameserverService) List(domain string) (*NamserverListResponse, error)
return nil, err
}

result := NamserverListResponse{}
result := NameserverListResponse{}
err = mapstructure.Decode(resp, &result)
if err != nil {
return nil, err
}

return &result, nil
}

// ListWithParams lists nameservers for a domain.
func (s *NameserverService) ListWithParams(request *NameserverListRequest) (*NameserverListResponse, error) {
if request == nil {
return nil, errors.New("request can't be nil")
}

requestMap := structs.Map(request)
requestMap["wide"] = "2"

req := s.client.NewRequest(methodNameserverList, requestMap)

resp, err := s.client.Do(req)
if err != nil {
return nil, err
}

result := NameserverListResponse{}
err = mapstructure.Decode(resp, &result)
if err != nil {
return nil, err
Expand Down Expand Up @@ -161,7 +187,7 @@ func (s *NameserverService) DeleteRecord(recID int) error {

// FindRecordByID search a DNS record by ID.
func (s *NameserverService) FindRecordByID(recID int) (*NameserverRecord, *NameserverDomain, error) {
listResp, err := s.client.Nameservers.List("")
listResp, err := s.client.Nameservers.ListWithParams(&NameserverListRequest{})
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -235,7 +261,11 @@ type NameserverInfoRequest struct {
}

// NamserverInfoResponse API model.
type NamserverInfoResponse struct {
// Deprecated: Use NameserverInfoResponse instead.
type NamserverInfoResponse = NameserverInfoResponse

// NameserverInfoResponse API model.
type NameserverInfoResponse struct {
RoID int `mapstructure:"roId"`
Domain string `mapstructure:"domain"`
Type string `mapstructure:"type"`
Expand Down Expand Up @@ -268,8 +298,20 @@ type NameserverRecord struct {
URLRedirectFavIcon string `mapstructure:"urlRedirectFavIcon"`
}

// NameserverListRequest API model.
type NameserverListRequest struct {
Domain string `structs:"domain,omitempty"`
Wide int `structs:"wide,omitempty"`
Page int `structs:"page,omitempty"`
PageLimit int `structs:"pagelimit,omitempty"`
}

// NamserverListResponse API model.
type NamserverListResponse struct {
// Deprecated: Use NameserverListResponse instead.
type NamserverListResponse = NameserverListResponse

// NameserverListResponse API model.
type NameserverListResponse struct {
Count int `mapstructure:"count"`
Domains []NameserverDomain `mapstructure:"domains"`
}
Expand Down

0 comments on commit 2dbc0cc

Please sign in to comment.