-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from cyberstudio/add-page-limit
Add page limit
- Loading branch information
Showing
11 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.. _pagination: | ||
|
||
Pagination | ||
========== | ||
|
||
You'll often need to work with collections of elements API provides. | ||
|
||
Cybsi Cloud SDK provides two ways to traverse collections. | ||
|
||
The **first** way is pages traversing. | ||
This approach fits for cases when you need to get page's properties i.e. cursor. | ||
For walking by page elements just iterate through the page. | ||
|
||
.. literalinclude:: ../../examples/pagination_manual.py | ||
|
||
The **second** way is elements traversing. This approach allows you to iterate through | ||
collections without working with pages. To work with collections as with iterator use `chain_pages`. | ||
|
||
.. literalinclude:: ../../examples/get_collection_objects_chained.py | ||
|
||
Limit | ||
----- | ||
|
||
You can define page limit. Backend returns the specified maximum number of elements per page. | ||
Backend overrides this value if limit is not set or value is out of bounds. | ||
|
||
.. literalinclude:: ../../examples/page_limit.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
from typing import Optional | ||
|
||
from cybsi.cloud import Client, Config | ||
from cybsi.cloud.auth import ResourceView | ||
from cybsi.cloud.pagination import Page | ||
|
||
if __name__ == "__main__": | ||
config = Config(api_key="the cryptic string") | ||
|
||
with Client(config) as client: | ||
page: Optional[Page[ResourceView]] = client.auth.resources.filter(limit=3) | ||
while page: | ||
# Got page with maximum of 3 elements | ||
# Page is iterable | ||
for item in page: | ||
# Do something with an item | ||
pass | ||
# Fetch next page | ||
page = page.next_page() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters