Skip to content

Commit

Permalink
Merge pull request prasmussen#8 from captncraig/paging
Browse files Browse the repository at this point in the history
Support Paging in domain and record list methods
  • Loading branch information
prasmussen authored Sep 8, 2017
2 parents d5d052a + 4f6fcd5 commit 931915c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
27 changes: 18 additions & 9 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,25 @@ func (self *Domain) Info(name string) (*DomainInfo, error) {

// List domains associated to the contact represented by apikey
func (self *Domain) List() ([]*DomainInfoBase, error) {
var res []interface{}
params := []interface{}{self.Key}
if err := self.Call("domain.list", params, &res); err != nil {
return nil, err
}

opts := &struct {
Page int `xmlrpc:"page"`
}{0}
const perPage = 100
params := []interface{}{self.Key, opts}
domains := make([]*DomainInfoBase, 0)
for _, r := range res {
domain := ToDomainInfoBase(r.(map[string]interface{}))
domains = append(domains, domain)
for {
var res []interface{}
if err := self.Call("domain.list", params, &res); err != nil {
return nil, err
}
for _, r := range res {
domain := ToDomainInfoBase(r.(map[string]interface{}))
domains = append(domains, domain)
}
if len(res) < perPage {
break
}
opts.Page++
}
return domains, nil
}
Expand Down
31 changes: 21 additions & 10 deletions domain/zone/record/record.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package record

import "github.com/prasmussen/gandi-api/client"
import (
"github.com/prasmussen/gandi-api/client"
)

type Record struct {
*client.Client
Expand All @@ -22,16 +24,25 @@ func (self *Record) Count(zoneId, version int64) (int64, error) {

// List records of a version of a DNS zone
func (self *Record) List(zoneId, version int64) ([]*RecordInfo, error) {
var res []interface{}
params := []interface{}{self.Key, zoneId, version}
if err := self.Call("domain.zone.record.list", params, &res); err != nil {
return nil, err
}

opts := &struct {
Page int `xmlrpc:"page"`
}{0}
const perPage = 100
params := []interface{}{self.Key, zoneId, version, opts}
records := make([]*RecordInfo, 0)
for _, r := range res {
record := ToRecordInfo(r.(map[string]interface{}))
records = append(records, record)
for {
var res []interface{}
if err := self.Call("domain.zone.record.list", params, &res); err != nil {
return nil, err
}
for _, r := range res {
record := ToRecordInfo(r.(map[string]interface{}))
records = append(records, record)
}
if len(res) < perPage {
break
}
opts.Page++
}
return records, nil
}
Expand Down

0 comments on commit 931915c

Please sign in to comment.