Remaining pagination support
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "net/url"
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
GID string `json:"gid"`
|
GID string `json:"gid"`
|
||||||
@@ -13,17 +14,30 @@ type projectResponse struct {
|
|||||||
|
|
||||||
type projectsResponse struct {
|
type projectsResponse struct {
|
||||||
Data []*Project `json:"data"`
|
Data []*Project `json:"data"`
|
||||||
|
NextPage *nextPage `json:"next_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WorkspaceClient) GetProjects() ([]*Project, error) {
|
func (wc *WorkspaceClient) GetProjects() (ret []*Project, err error) {
|
||||||
// TODO: Handle pagination
|
|
||||||
path := fmt.Sprintf("workspaces/%s/projects", wc.workspace.GID)
|
path := fmt.Sprintf("workspaces/%s/projects", wc.workspace.GID)
|
||||||
|
values := &url.Values{}
|
||||||
|
|
||||||
|
for {
|
||||||
resp := &projectsResponse{}
|
resp := &projectsResponse{}
|
||||||
err := wc.client.get(path, nil, resp)
|
err = wc.client.get(path, values, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
return resp.Data, nil
|
|
||||||
|
ret = append(ret, resp.Data...)
|
||||||
|
|
||||||
|
if resp.NextPage == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
values.Set("offset", resp.NextPage.Offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Project) String() string {
|
func (p *Project) String() string {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "net/url"
|
||||||
|
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
GID string `json:"gid"`
|
GID string `json:"gid"`
|
||||||
@@ -9,17 +10,30 @@ type Tag struct {
|
|||||||
|
|
||||||
type tagsResponse struct {
|
type tagsResponse struct {
|
||||||
Data []*Tag `json:"data"`
|
Data []*Tag `json:"data"`
|
||||||
|
NextPage *nextPage `json:"next_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WorkspaceClient) GetTags() ([]*Tag, error) {
|
func (wc *WorkspaceClient) GetTags() (ret []*Tag, err error) {
|
||||||
// TODO: Handle pagination
|
|
||||||
path := fmt.Sprintf("workspaces/%s/tags", wc.workspace.GID)
|
path := fmt.Sprintf("workspaces/%s/tags", wc.workspace.GID)
|
||||||
|
values := &url.Values{}
|
||||||
|
|
||||||
|
for {
|
||||||
resp := &tagsResponse{}
|
resp := &tagsResponse{}
|
||||||
err := wc.client.get(path, nil, resp)
|
err := wc.client.get(path, values, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
return resp.Data, nil
|
|
||||||
|
ret = append(ret, resp.Data...)
|
||||||
|
|
||||||
|
if resp.NextPage == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
values.Set("offset", resp.NextPage.Offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WorkspaceClient) GetTagsByName() (map[string]*Tag, error) {
|
func (wc *WorkspaceClient) GetTagsByName() (map[string]*Tag, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user