Skip to content

Commit 862d983

Browse files
bencekadaremarkozma
andcommitted
Add getContactIdsByNextUrl function because we need to get contacts by next url
- AUT-3915 Co-authored-by: Peter Kozma <peter.kozma@emarsys.com>
1 parent e1787ed commit 862d983

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/Suite/Api/ContactList.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public function getContactIdsInList(int $customerId, int $contactListId, int $to
127127
}
128128
}
129129

130+
public function getContactIdsByNextUrl(string $nextUrl): array
131+
{
132+
try {
133+
$response = $this->apiClient->get($nextUrl);
134+
return $response['data'] ?? [];
135+
} catch (Error $error) {
136+
throw new RequestFailed('Could not fetch contact ids: ' . $error->getMessage(), $error->getCode(), $error);
137+
}
138+
}
139+
130140
public function getListChunkIterator(int $customerId, int $contactListId, int $chunkSize = null) : iterable
131141
{
132142
$nextUrlFull = $this->endPoints->contactIdsInList($customerId, $contactListId, $chunkSize);

test/unit/Suite/Api/ContactListTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,33 @@ public function getContactIdsInList_ApiCallFails_ExceptionThrown(): void
279279
$this->listService->getContactIdsInList($this->customerId, $this->contactListId);
280280
}
281281

282+
/**
283+
* @test
284+
*/
285+
public function getContactIdsByNextUrl_CalledWithProperUrl_ApiResponseConverted(): void
286+
{
287+
$nextUrl = "/123/contactlist/456/contactIds";
288+
$response = ['value' => [1, 2, 3], 'next' => '/next/url'];
289+
$this->apiClient
290+
->method('get')
291+
->with($nextUrl)
292+
->willReturn($this->apiSuccess($response));
293+
294+
$result = $this->listService->getContactIdsByNextUrl($nextUrl);
295+
$this->assertEquals($response, $result);
296+
}
297+
298+
/**
299+
* @test
300+
*/
301+
public function getContactIdsByNextUrl_ApiCallFails_ExceptionThrown(): void
302+
{
303+
$this->apiClient->method('get')->will($this->apiFailure());
304+
$this->expectException(RequestFailed::class);
305+
306+
$this->listService->getContactIdsByNextUrl('/test');
307+
}
308+
282309
/**
283310
* @test
284311
*/

0 commit comments

Comments
 (0)