diff --git a/src/IntercomClient.php b/src/IntercomClient.php index 076f9ed..602b94a 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -294,9 +294,14 @@ public function nextSearchPage(string $path, array $query, $pages) * @param string $startingAfter * @return stdClass */ - public function nextCursorPage(string $path, string $startingAfter) + public function nextCursorPage(string $path, $pages) { - return $this->get($path . "?starting_after=" . $startingAfter); + $queryParams = [ + "starting_after" => $pages->next->starting_after, + "per_page" => $pages->per_page, + ]; + + return $this->get($path, $queryParams); } /** diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 7cfc073..2cac13d 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -118,8 +118,7 @@ public function nextSearch(array $query, $pages) public function nextCursor($pages) { $path = 'contacts'; - $starting_after = $pages->next->starting_after; - return $this->client->nextCursorPage($path, $starting_after); + return $this->client->nextCursorPage($path, $pages); } /** diff --git a/tests/IntercomClientTest.php b/tests/IntercomClientTest.php index c04abac..db15cfe 100644 --- a/tests/IntercomClientTest.php +++ b/tests/IntercomClientTest.php @@ -117,6 +117,29 @@ public function testPaginationHelper() } } + public function testCursorHelper() + { + $httpClient = new Client(); + $httpClient->addResponse( + new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") + ); + + $client = new IntercomClient('u', 'p'); + $client->setHttpClient($httpClient); + + $pages = new stdClass; + $pages->per_page = 150; + $pages->next = new stdClass; + $pages->next->starting_after = "abc"; + + $client->nextCursorPage('path', $pages); + + foreach ($httpClient->getRequests() as $request) { + $query = $request->getUri()->getQuery(); + $this->assertSame("starting_after=abc&per_page=150", $query); + } + } + public function testRateLimitDetails() { date_default_timezone_set('UTC'); diff --git a/tests/IntercomContactsTest.php b/tests/IntercomContactsTest.php index 9d1578d..05960ec 100644 --- a/tests/IntercomContactsTest.php +++ b/tests/IntercomContactsTest.php @@ -68,11 +68,12 @@ public function testContactNextSearch() $this->assertSame('foo', $contacts->nextSearch([], $pages)); } - public function testConversationNextCursor() + public function testContactNextCursor() { $this->client->method('nextCursorPage')->willReturn('foo'); $query = []; $pages = new stdClass; + $pages->per_page = 150; $pages->next = new stdClass; $pages->next->starting_after = "abc";