Skip to content

Commit

Permalink
fixing #119
Browse files Browse the repository at this point in the history
  • Loading branch information
lleadbet committed Nov 10, 2021
1 parent 9ad36fe commit ffc3992
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewRequest(method string, path string, queryParameters []string, body []byt
if err != nil {
fmt.Println("Error fetching client information", err.Error())
}

isFirstRun := true
for {
var apiResponse models.APIResponse

Expand Down Expand Up @@ -101,25 +101,30 @@ func NewRequest(method string, path string, queryParameters []string, body []byt
return
}

data.Template = apiResponse.Template
if isFirstRun {
data = apiResponse
isFirstRun = false
}

if resp.StatusCode > 299 || resp.StatusCode < 200 {
data = apiResponse
break
}

if data.Data == nil {
break
}
d := data.Data.([]interface{})
if strings.Contains(path, "schedule") || apiResponse.Data == nil {
data.Data = append(d, apiResponse.Data)
} else {
data.Data = append(d, apiResponse.Data.([]interface{})...)
}

if apiResponse.Pagination == nil || *&apiResponse.Pagination.Cursor == "" {
if apiResponse.Pagination == nil || apiResponse.Pagination.Cursor == "" {
break
}

if autopaginate == false {
if !autopaginate {
data.Pagination = &models.APIPagination{
Cursor: apiResponse.Pagination.Cursor,
}
Expand All @@ -130,7 +135,6 @@ func NewRequest(method string, path string, queryParameters []string, body []byt
break
}
cursor = apiResponse.Pagination.Cursor

}

if data.Data == nil {
Expand Down

0 comments on commit ffc3992

Please sign in to comment.