From 8cb37b91cd2bc9ae31a7167cf7e4d669e859a618 Mon Sep 17 00:00:00 2001 From: "Renzo Robles (AWF)" Date: Fri, 10 Sep 2021 17:55:19 -0500 Subject: [PATCH] Updating GetProjects, GetResults, GetResultsForCase, GetRuns, GetSections to support pagination --- client.go | 8 ++++---- project.go | 7 ++++++- result.go | 14 ++++++++++++-- run.go | 7 ++++++- section.go | 7 ++++++- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index 16ec091..2274da2 100644 --- a/client.go +++ b/client.go @@ -114,8 +114,8 @@ func (c *Client) sendRequest(method, uri string, data, v interface{}) error { } type Links struct { - Next string `json:"next"` - Prev string `json:"prev"` + Next *string `json:"next"` + Prev *string `json:"prev"` } func (c *Client) sendRequestBeta(method, uri string, data, v interface{}, itemsKeyName string) error { @@ -134,8 +134,8 @@ func (c *Client) sendRequestBeta(method, uri string, data, v interface{}, itemsK returnItems = tempItems - for err == nil && links.Next != "" && len(tempItems) == 250 { - nextUri := strings.TrimPrefix(links.Next, "/api/v2/") + for err == nil && links.Next != nil { + nextUri := strings.TrimPrefix(*links.Next, "/api/v2/") err = c.sendRequest("GET", nextUri, nil, &wraperMap) if err == nil { json.Unmarshal(wraperMap[itemsKeyName], &tempItems) diff --git a/project.go b/project.go index 6fa67ce..4d72846 100644 --- a/project.go +++ b/project.go @@ -41,7 +41,12 @@ func (c *Client) GetProjects(isCompleted ...bool) ([]Project, error) { } returnProjects := []Project{} - err := c.sendRequest("GET", uri, nil, &returnProjects) + var err error + if c.useBetaApi { + err = c.sendRequestBeta("GET", uri, nil, &returnProjects, "projects") + } else { + err = c.sendRequest("GET", uri, nil, &returnProjects) + } return returnProjects, err } diff --git a/result.go b/result.go index 36eaab7..9e397a6 100644 --- a/result.go +++ b/result.go @@ -94,7 +94,12 @@ func (c *Client) GetResults(testID int, filters ...RequestFilterForCaseResults) if len(filters) > 0 { uri = applyFiltersForCaseResults(uri, filters[0]) } - err := c.sendRequest("GET", uri, nil, &returnResults) + var err error + if c.useBetaApi { + err = c.sendRequestBeta("GET", uri, nil, &returnResults, "results") + } else { + err = c.sendRequest("GET", uri, nil, &returnResults) + } return returnResults, err } @@ -107,7 +112,12 @@ func (c *Client) GetResultsForCase(runID, caseID int, filters ...RequestFilterFo if len(filters) > 0 { uri = applyFiltersForCaseResults(uri, filters[0]) } - err := c.sendRequest("GET", uri, nil, &returnResults) + var err error + if c.useBetaApi { + err = c.sendRequestBeta("GET", uri, nil, &returnResults, "results") + } else { + err = c.sendRequest("GET", uri, nil, &returnResults) + } return returnResults, err } diff --git a/run.go b/run.go index 8a222d2..3c94383 100644 --- a/run.go +++ b/run.go @@ -87,7 +87,12 @@ func (c *Client) GetRuns(projectID int, filters ...RequestFilterForRun) ([]Run, } returnRun := []Run{} - err := c.sendRequest("GET", uri, nil, &returnRun) + var err error + if c.useBetaApi { + err = c.sendRequestBeta("GET", uri, nil, &returnRun, "runs") + } else { + err = c.sendRequest("GET", uri, nil, &returnRun) + } return returnRun, err } diff --git a/section.go b/section.go index 8879f66..3cbd9ba 100644 --- a/section.go +++ b/section.go @@ -45,7 +45,12 @@ func (c *Client) GetSections(projectID int, suiteID ...int) ([]Section, error) { if len(suiteID) > 0 { uri = uri + "&suite_id=" + strconv.Itoa(suiteID[0]) } - err := c.sendRequest("GET", uri, nil, &returnSection) + var err error + if c.useBetaApi { + err = c.sendRequestBeta("GET", uri, nil, &returnSection, "sections") + } else { + err = c.sendRequest("GET", uri, nil, &returnSection) + } return returnSection, err }