Skip to content
Merged
Show file tree
Hide file tree
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 Nov 11, 2025
7653480
chore: add unit test
tiwarishubham635 Nov 11, 2025
7ef42e3
chore: fix unit test
tiwarishubham635 Nov 13, 2025
7045afc
Merge branch 'main' into add_token_pagination
tiwarishubham635 Nov 13, 2025
47cb948
chore: add unit tests
tiwarishubham635 Nov 13, 2025
ffa3a06
Merge branch 'main' into add_token_pagination
tiwarishubham635 Nov 21, 2025
1d2e5b7
Merge branch 'main' into add_token_pagination
tiwarishubham635 Nov 24, 2025
7eaa2cf
docs: add documentation for KeyErrorException
tiwarishubham635 Nov 26, 2025
6197096
core: switch full_url to camelCase
tiwarishubham635 Nov 26, 2025
7945dec
chore: use urlencode before adding pageToken
tiwarishubham635 Nov 26, 2025
d489cf6
chore: remove addQueryParam()
tiwarishubham635 Nov 26, 2025
1963019
chore: return null when null token is passed in getNextPageUrl() and …
tiwarishubham635 Nov 26, 2025
96ec664
docs: add TokenPaginationPage.php documentation
tiwarishubham635 Nov 26, 2025
a152794
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
bae09a4
chore: use camelCase for httpClient
tiwarishubham635 Nov 26, 2025
030a30f
Merge remote-tracking branch 'origin/add_token_pagination' into add_t…
tiwarishubham635 Nov 26, 2025
1a5d0c1
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
4c60bca
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
169af69
docs: add docblocks for the functions
tiwarishubham635 Nov 26, 2025
c5c5953
Update tests/Twilio/Unit/TokenPaginationPageTest.php
tiwarishubham635 Nov 26, 2025
8b8d4f3
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
feafb45
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
073ac2f
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
e2bc596
chore: rename query string getter
tiwarishubham635 Nov 26, 2025
506f642
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
1a6d763
Update src/Twilio/TokenPaginationPage.php
tiwarishubham635 Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Twilio/Exceptions/KeyErrorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php


namespace Twilio\Exceptions;


class KeyErrorException extends TwilioException {

}
92 changes: 92 additions & 0 deletions src/Twilio/TokenPaginationPage.php
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;
protected $pageSize;
protected $nextToken;
protected $previousToken;
protected $url;
protected $previousPageUrl;
protected $nextPageUrl;

public function __construct(Version $version, Response $response) {
parent::__construct($version, $response);

$http_client = $version->getDomain()->getClient()->getHttpClient();

$this->url = '';
if($http_client->lastRequest) {
$full_url = $http_client->lastRequest[CURLOPT_URL];
// remove query parameters from url
$parts = explode('?', $full_url);
$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');
if ($this->key) {
return $this->payload[$this->key];
}

throw new KeyErrorException('key not found in the response');
}

protected function addQueryParam(String $query): String {
if($query === '') {
$query .= '?';
} else {
$query .= '&';
}
return $query;
}

protected function getQueryString(?String $pageToken): String {
$queryString = '';
if ($this->pageSize) {
$queryString = $this->addQueryParam($queryString);
$queryString .= 'pageSize=' . $this->pageSize;
}
if ($pageToken && $pageToken !== '') {
$queryString = $this->addQueryParam($queryString);
$queryString .= 'pageToken=' . $pageToken;
}
return $queryString;
}

public function getPreviousPageUrl(): ?string {
if (!$this->previousPageUrl) {
$this->previousPageUrl = $this->url . $this->getQueryString($this->previousToken);
}
return $this->previousPageUrl;
}

public function getNextPageUrl(): ?string {
if (!$this->nextPageUrl) {
$this->nextPageUrl = $this->url . $this->getQueryString($this->nextToken);
}
return $this->nextPageUrl;
}


public function __toString(): string {
return '[TokenPaginationPage]';
}

}
Loading
Loading