Skip to content

Commit

Permalink
parse $skiptoken and $top from next url in suite response and generat…
Browse files Browse the repository at this point in the history
…e the full url using those instead of manipulating the path in it

- AUT-3246

Co-authored-by: Levente Loki <[email protected]>
  • Loading branch information
fqqdk and lloki-emarsys committed Sep 24, 2024
1 parent 1329e89 commit d8772db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Suite/Api/ContactList.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getContactsOfList(int $customerId, int $contactListId, int $limi
}
}

public function getContactIdsInList(int $customerId, int $contactListId, int $top = null, string $skiptoken = null): array
public function getContactIdsInList(int $customerId, int $contactListId, int $top = null, int $skiptoken = null): array
{
try {
$response = $this->apiClient->get($this->endPoints->contactIdsInList($customerId, $contactListId, $top, $skiptoken));
Expand All @@ -135,7 +135,7 @@ public function getListChunkIterator(int $customerId, int $contactListId, int $c
try {
do {
['value' => $value, 'next' => $next] = $this->apiClient->get($nextUrlFull)['data'];
$nextUrlFull = $this->endPoints->contactIdsInListNextChunk($customerId, $next);
$nextUrlFull = $this->endPoints->contactIdsInListNextChunk($customerId, $contactListId, $next);
yield $value;
} while ($next !== null);
} catch (Error $error) {
Expand Down
15 changes: 7 additions & 8 deletions src/Suite/Api/ContactListEndPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ public function contactIdsInList(int $customerId, int $contactListId, int $top =
);
}

public function contactIdsInListNextChunk(int $customerId, string $next = null): ?string
public function contactIdsInListNextChunk(int $customerId, int $contactListId, string $next = null): ?string
{

return $next ? $this->getBaseUrlWithoutInternalPostfix() . "{$next}" : null;
if (null === $next) {
return null;
}
$rawQuery = parse_url($next, PHP_URL_QUERY);
parse_str($rawQuery, $query);
return $this->contactIdsInList($customerId, $contactListId, $query['$top'] ?? null, $query['$skiptoken'] ?? null);
}

public function deleteContactsFromList(int $customerId, int $contactListId): string
{
return $this->baseUrl($customerId) . "/{$contactListId}/delete";
}

public function getBaseUrlWithoutInternalPostfix(): string
{
return preg_replace('/\/internal$/', '', $this->apiBaseUrl);
}
}

0 comments on commit d8772db

Please sign in to comment.