Skip to content

Commit

Permalink
Add pagination options details
Browse files Browse the repository at this point in the history
  • Loading branch information
harrylewis committed Aug 24, 2023
1 parent 1383557 commit 31d7df2
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,6 @@ merchants.each do |merchant|
end
```

#### Paginating

Payrix supports pagination for paging through a collection of resources. By default, the initial
`.list` call requests the first page of resources, and returns an object to page through more.

```ruby
ids = []
merchants = Payrix::Merchant.list

ids += merchants.map { |merchant| merchant.id }

while merchants.more?
merchants.page_forward

ids += merchants.map { |merchant| merchant.id }
end
```

Use the manual approach above, or use a library helper to make this easier.

```ruby
ids = Payrix::Merchant.list.auto_paging_map { |merchant| merchant.id }
```

There are a few other helpers.

- `#auto_paging_each` - Pass in a `&block` to execute some code for each resource.
- `#auto_paging_count` - Return a count of all resources in the collection.

#### Filtering

Filter through the returned results by passing an argument to `.list`.
Expand Down Expand Up @@ -142,6 +113,41 @@ merchants = Payrix::Merchants.list(filter)
The available compound operators are `Payrix::Search.or` and `Payrix::Search.and`. Both operators
takes 2+ simple or compound search nodes.

#### Paginating

Payrix supports pagination for paging through a collection of resources. By default, the initial
`.list` call requests the first page of resources, and returns an object to page through more.

```ruby
ids = []
merchants = Payrix::Merchant.list

ids += merchants.map { |merchant| merchant.id }

while merchants.more?
merchants.page_forward

ids += merchants.map { |merchant| merchant.id }
end
```

Use the manual approach above, or use a library helper to make this easier.

```ruby
ids = Payrix::Merchant.list.auto_paging_map { |merchant| merchant.id }
```

There are a few other helpers.

- `#auto_paging_each` - Pass in a `&block` to execute some code for each resource.
- `#auto_paging_count` - Return a count of all resources in the collection.

Use the `:page` and `:limit` parameter to skip to a certain page and limit the results returned.

```ruby
Payrix::Merchant.list({}, { page: 2, limit: 10 })
```

### Create

Create a single resource.
Expand Down

0 comments on commit 31d7df2

Please sign in to comment.