-
Notifications
You must be signed in to change notification settings - Fork 582
feat: Add support for token based pagination strategy #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0cfb598
chore: add support for token based pagination
tiwarishubham635 7653480
chore: add unit test
tiwarishubham635 7ef42e3
chore: fix unit test
tiwarishubham635 7045afc
Merge branch 'main' into add_token_pagination
tiwarishubham635 47cb948
chore: add unit tests
tiwarishubham635 ffa3a06
Merge branch 'main' into add_token_pagination
tiwarishubham635 1d2e5b7
Merge branch 'main' into add_token_pagination
tiwarishubham635 7eaa2cf
docs: add documentation for KeyErrorException
tiwarishubham635 6197096
core: switch full_url to camelCase
tiwarishubham635 7945dec
chore: use urlencode before adding pageToken
tiwarishubham635 d489cf6
chore: remove addQueryParam()
tiwarishubham635 1963019
chore: return null when null token is passed in getNextPageUrl() and …
tiwarishubham635 96ec664
docs: add TokenPaginationPage.php documentation
tiwarishubham635 a152794
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 bae09a4
chore: use camelCase for httpClient
tiwarishubham635 030a30f
Merge remote-tracking branch 'origin/add_token_pagination' into add_t…
tiwarishubham635 1a5d0c1
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 4c60bca
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 169af69
docs: add docblocks for the functions
tiwarishubham635 c5c5953
Update tests/Twilio/Unit/TokenPaginationPageTest.php
tiwarishubham635 8b8d4f3
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 feafb45
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 073ac2f
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 e2bc596
chore: rename query string getter
tiwarishubham635 506f642
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 1a6d763
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace Twilio\Exceptions; | ||
|
|
||
|
|
||
| class KeyErrorException extends TwilioException { | ||
|
|
||
| } | ||
This file contains hidden or 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,92 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace Twilio; | ||
|
|
||
|
|
||
| use Twilio\Exceptions\KeyErrorException; | ||
| use Twilio\Http\Response; | ||
|
|
||
| abstract class TokenPaginationPage extends Page { | ||
|
|
||
| protected $key; | ||
tiwarishubham635 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| protected $pageSize; | ||
| protected $nextToken; | ||
| protected $previousToken; | ||
| protected $url; | ||
| protected $previousPageUrl; | ||
| protected $nextPageUrl; | ||
|
|
||
tiwarishubham635 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public function __construct(Version $version, Response $response) { | ||
| parent::__construct($version, $response); | ||
|
|
||
| $http_client = $version->getDomain()->getClient()->getHttpClient(); | ||
|
|
||
| $this->url = ''; | ||
| if($http_client->lastRequest) { | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $full_url = $http_client->lastRequest[CURLOPT_URL]; | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // remove query parameters from url | ||
| $parts = explode('?', $full_url); | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $this->url = $parts[0]; | ||
| } | ||
|
|
||
| $this->key = $this->getMeta('key'); | ||
| $this->pageSize = (int) $this->getMeta('pageSize'); | ||
| $this->nextToken = $this->getMeta('nextToken'); | ||
| $this->previousToken = $this->getMeta('previousToken'); | ||
| } | ||
|
|
||
| /** | ||
| * @throws KeyErrorException | ||
| */ | ||
| protected function loadPage(): array { | ||
| $this->key = $this->getMeta('key'); | ||
tiwarishubham635 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if ($this->key) { | ||
| return $this->payload[$this->key]; | ||
| } | ||
|
|
||
tiwarishubham635 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw new KeyErrorException('key not found in the response'); | ||
| } | ||
|
|
||
| protected function addQueryParam(String $query): String { | ||
| if($query === '') { | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $query .= '?'; | ||
| } else { | ||
| $query .= '&'; | ||
| } | ||
| return $query; | ||
| } | ||
|
|
||
| protected function getQueryString(?String $pageToken): String { | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $queryString = ''; | ||
| if ($this->pageSize) { | ||
tiwarishubham635 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $queryString = $this->addQueryParam($queryString); | ||
| $queryString .= 'pageSize=' . $this->pageSize; | ||
| } | ||
| if ($pageToken && $pageToken !== '') { | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $queryString = $this->addQueryParam($queryString); | ||
| $queryString .= 'pageToken=' . $pageToken; | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return $queryString; | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public function getPreviousPageUrl(): ?string { | ||
| if (!$this->previousPageUrl) { | ||
| $this->previousPageUrl = $this->url . $this->getQueryString($this->previousToken); | ||
| } | ||
| return $this->previousPageUrl; | ||
tiwarishubham635 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public function getNextPageUrl(): ?string { | ||
| if (!$this->nextPageUrl) { | ||
| $this->nextPageUrl = $this->url . $this->getQueryString($this->nextToken); | ||
| } | ||
| return $this->nextPageUrl; | ||
tiwarishubham635 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
tiwarishubham635 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public function __toString(): string { | ||
| return '[TokenPaginationPage]'; | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.