Skip to content

Commit

Permalink
Add total_pages to PaginatedResponse.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvandersluis committed Apr 12, 2021
1 parent 4afd129 commit 6877907
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Note: The Pexels API returns a maximum of 80 records for one request.
```ruby
response = client.photos.search('dog', page: 2, per_page: 50)
response.total_results #=> 1000
response.total_pages #= 20
```

If there are further pages, you can also paginate through the API client:
Expand Down
4 changes: 4 additions & 0 deletions lib/pexels/paginated_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def initialize(response)
@next_page = attrs.fetch('next_page', nil)
end

def total_pages
total_results.fdiv(per_page).ceil
end

def each(&block)
if block_given?
data.each(&block)
Expand Down

0 comments on commit 6877907

Please sign in to comment.