Skip to content

Commit

Permalink
Merge pull request #1409 from jesopo/list-search-and-per-page
Browse files Browse the repository at this point in the history
add list item search & list item pagination page size
  • Loading branch information
jacobbednarz authored Sep 26, 2023
2 parents 8b7f984 + 9c451c7 commit feebb8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/1409.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
list_item: allow filtering by search term, cursor and per page attributes
```
17 changes: 9 additions & 8 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ type ListDeleteParams struct {
}

type ListListItemsParams struct {
ID string
ID string `url:"-"`
Search string `url:"search,omitempty"`
PerPage int `url:"per_page,omitempty"`
Cursor string `url:"cursor,omitempty"`
}

type ListCreateItemsParams struct {
Expand Down Expand Up @@ -336,14 +339,10 @@ func (api *API) DeleteList(ctx context.Context, rc *ResourceContainer, listID st
// API reference: https://api.cloudflare.com/#rules-lists-list-list-items
func (api *API) ListListItems(ctx context.Context, rc *ResourceContainer, params ListListItemsParams) ([]ListItem, error) {
var list []ListItem
var cursor string
var cursorQuery string

for {
if len(cursor) > 0 {
cursorQuery = fmt.Sprintf("?cursor=%s", cursor)
}
uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items%s", rc.Identifier, params.ID, cursorQuery)
uri := buildURI(fmt.Sprintf("/accounts/%s/rules/lists/%s/items", rc.Identifier, params.ID), params)

res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []ListItem{}, err
Expand All @@ -355,8 +354,10 @@ func (api *API) ListListItems(ctx context.Context, rc *ResourceContainer, params
}

list = append(list, result.Result...)
if cursor = result.ResultInfo.Cursors.After; cursor == "" {
if cursor := result.ResultInfo.Cursors.After; cursor == "" {
break
} else {
params.Cursor = cursor
}
}

Expand Down

0 comments on commit feebb8a

Please sign in to comment.