Skip to content

Commit 462405e

Browse files
author
Gergely Illyes
committed
AUT-2569: add limit and offset params to contactlist fetching endpoint
1 parent b8d6f21 commit 462405e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/Suite/Api/ContactList.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public function getContactsOfList(int $customerId, int $contactListId, int $limi
119119
}
120120
}
121121

122-
public function getContactIdsInList(int $customerId, int $contactListId)
122+
public function getContactIdsInList(int $customerId, int $contactListId, int $limit = null, int $offset = null)
123123
{
124124
try {
125-
$response = $this->apiClient->get($this->endPoints->contactIdsInList($customerId, $contactListId));
125+
$response = $this->apiClient->get($this->endPoints->contactIdsInList($customerId, $contactListId, $limit, $offset));
126126
return $response['data'] ?? [];
127127
} catch (Error $error) {
128128
throw new RequestFailed('Could not fetch contact ids: ' . $error->getMessage(), $error->getCode(), $error);

src/Suite/Api/ContactListEndPoints.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ public function contactsOfList(int $customerId, int $contactListId, int $limit,
4444
return $this->baseUrl($customerId) . "/{$contactListId}/contacts/?limit={$limit}&offset={$offset}";
4545
}
4646

47-
public function contactIdsInList(int $customerId, int $contactListId)
47+
public function contactIdsInList(int $customerId, int $contactListId, int $limit = null, int $offset = null)
4848
{
49-
return $this->baseUrl($customerId) . "/{$contactListId}/contactIds";
49+
$result = $this->baseUrl($customerId) . "/{$contactListId}/contactIds";
50+
if (null !== $limit && null !== $offset) {
51+
$result .= "?\$top={$limit}&\$skiptoken={$offset}";
52+
}
53+
return $result;
5054
}
5155

5256
public function deleteContactsFromList(int $customerId, int $contactListId): string

test/unit/Suite/Api/ContactListTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@ public function getContactIdsInList_CalledWithProperUrl_ApiResponseConverted():
254254
$this->assertEquals($response, $result);
255255
}
256256

257+
/**
258+
* @test
259+
*/
260+
public function getContactIdsInList_CalledWithProperUrlAndParams_ApiResponseConverted(): void
261+
{
262+
$response = ['value' => [1, 2, 3], 'next' => null];
263+
$this->apiClient
264+
->method('get')
265+
->with("api_base_url/$this->customerId/contactlist/$this->contactListId/contactIds?\$top=1&\$skiptoken=1")
266+
->willReturn($this->apiSuccess($response));
267+
268+
$result = $this->listService->getContactIdsInList($this->customerId, $this->contactListId, 1, 1);
269+
$this->assertEquals($response, $result);
270+
}
271+
257272
/**
258273
* @test
259274
*/

0 commit comments

Comments
 (0)