From 8cddfd568be67096b967fd73415f27e0434297ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Mon, 11 Feb 2019 11:21:21 +0100 Subject: [PATCH 1/4] RSH1b2 list pagination, test next() --- tests/PushDeviceRegistrationsTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/PushDeviceRegistrationsTest.php b/tests/PushDeviceRegistrationsTest.php index 3f2f2ec..38e0782 100644 --- a/tests/PushDeviceRegistrationsTest.php +++ b/tests/PushDeviceRegistrationsTest.php @@ -87,6 +87,12 @@ public function testList() { $response = self::$ably->push->admin->deviceRegistrations->list_([ 'limit' => 2 ]); $this->assertEquals(count($response->items), 2); + // pagination + $response = self::$ably->push->admin->deviceRegistrations->list_([ 'limit' => 1 ]); + $this->assertEquals(count($response->items), 1); + $response = $response->next(); + $this->assertEquals(count($response->items), 1); + // Filter by device id $first = $datas[0]; $response = self::$ably->push->admin->deviceRegistrations->list_([ 'deviceId' => $first['id'] ]); From f66479af3ec04d59bd813a9861b8fd5810333926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Wed, 3 Feb 2021 09:15:05 +0100 Subject: [PATCH 2/4] Fix pagination in push notifications --- src/Models/PaginatedResult.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Models/PaginatedResult.php b/src/Models/PaginatedResult.php index 7faf731..bfca23c 100644 --- a/src/Models/PaginatedResult.php +++ b/src/Models/PaginatedResult.php @@ -35,7 +35,8 @@ class PaginatedResult { * @param array $headers Headers to be sent with the request * @throws AblyException */ - public function __construct( \Ably\AblyRest $ably, $model, $cipherParams, $method, $path, $params = [], $headers = [] ) { + public function __construct( \Ably\AblyRest $ably, $model, $cipherParams, + $method, $path, $params = [], $headers = [] ) { $this->ably = $ably; $this->model = $model; $this->cipherParams = $cipherParams; @@ -140,7 +141,6 @@ public function isPaginated() { * Parses HTTP headers for pagination links */ private function parsePaginationHeaders($headers) { - $path = preg_replace('/\/[^\/]*$/', '/', $this->path); preg_match_all('/Link: *\<([^\>]*)\>; *rel="([^"]*)"/i', $headers, $matches, PREG_SET_ORDER); @@ -148,7 +148,6 @@ private function parsePaginationHeaders($headers) { if (!$matches) return; $this->paginationHeaders = []; - foreach ($matches as $m) { $link = $m[1]; $rel = $m[2]; @@ -157,7 +156,10 @@ private function parsePaginationHeaders($headers) { throw new AblyException( "Server error - only relative URLs are supported in pagination" ); } - $this->paginationHeaders[$rel] = $path.substr($link, 2); + $link = $path . substr($link, 2); + $link = str_replace( '/push/push/', '/push/', $link ); // cf. https://github.com/ably/ably-php/pull/81 + + $this->paginationHeaders[$rel] = $link; } } } From 03a3541bc20b0660f6c45e7d0653c2d192cbae61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Fri, 5 Feb 2021 13:58:44 +0100 Subject: [PATCH 3/4] Different workaround to resolve links --- src/Models/PaginatedResult.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Models/PaginatedResult.php b/src/Models/PaginatedResult.php index bfca23c..7ec7c06 100644 --- a/src/Models/PaginatedResult.php +++ b/src/Models/PaginatedResult.php @@ -156,8 +156,8 @@ private function parsePaginationHeaders($headers) { throw new AblyException( "Server error - only relative URLs are supported in pagination" ); } - $link = $path . substr($link, 2); - $link = str_replace( '/push/push/', '/push/', $link ); // cf. https://github.com/ably/ably-php/pull/81 + $link = explode('/', $link); + $link = $path . end($link); $this->paginationHeaders[$rel] = $link; } From 4b5c2a7d0e6b8cb8b15ab6714d811c15d1c7fed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Fri, 5 Feb 2021 16:45:38 +0100 Subject: [PATCH 4/4] Fix testHttpTimeout --- tests/AblyRestTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/AblyRestTest.php b/tests/AblyRestTest.php index 79c6bfa..1aca39d 100644 --- a/tests/AblyRestTest.php +++ b/tests/AblyRestTest.php @@ -398,13 +398,13 @@ public function testHttpTimeout() { $ablyTimeout = new AblyRest( [ 'key' => 'fake.key:veryFake', - 'httpRequestTimeout' => 50, // 50 ms + 'httpRequestTimeout' => 20, // 20 ms ]); $ably->http->get('https://cdn.ably.io/lib/ably.js'); // should work $this->expectException(AblyRequestException::class); $this->expectExceptionCode(50003); - $ablyTimeout->http->get('https://cdn.ably.io/lib/ably.js'); // guaranteed to take more than 50 ms + $ablyTimeout->http->get('https://cdn.ably.io/lib/ably.js'); // guaranteed to take more than 20 ms } }