Skip to content

Commit

Permalink
add new endpoint to fetch contact ids from list
Browse files Browse the repository at this point in the history
- AUT-2568
  • Loading branch information
akapa committed Feb 9, 2024
1 parent 63e5de1 commit e8af41a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Suite/Api/ContactList.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public function deleteContactsFromList(int $customerId, int $contactListId, arra

}

/**
* @deprecated
*/
public function getContactsOfList(int $customerId, int $contactListId, int $limit, int $offset)
{
try {
Expand All @@ -116,6 +119,14 @@ public function getContactsOfList(int $customerId, int $contactListId, int $limi
}
}

public function getContactIdsInList(int $customerId, int $contactListId)
{
try {
return $this->apiClient->get($this->endPoints->contactIdsInList($customerId, $contactListId));
} catch (Error $error) {
throw new RequestFailed('Could not fetch contact ids: ' . $error->getMessage(), $error->getCode(), $error);
}
}

/**
* @param int $customerId
Expand Down
5 changes: 5 additions & 0 deletions src/Suite/Api/ContactListEndPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public function contactsOfList(int $customerId, int $contactListId, int $limit,
return $this->baseUrl($customerId) . "/{$contactListId}/contacts/?limit={$limit}&offset={$offset}";
}

public function contactIdsInList(int $customerId, int $contactListId)
{
return $this->baseUrl($customerId) . "/{$contactListId}/contactIds";
}

public function deleteContactsFromList(int $customerId, int $contactListId): string
{
return $this->baseUrl($customerId) . "/{$contactListId}/delete";
Expand Down
25 changes: 25 additions & 0 deletions test/unit/Suite/Api/ContactListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,31 @@ public function replaceContactList_ApiFailure_ThrowsException()
$this->listService->replaceContactList($this->customerId, $this->contactListId, $contactIds);
}

/**
* @test
*/
public function getContactIdsInList_Perfect_Perfect()
{
$response = ['value' => [1, 2, 3], 'next' => null];
$this->apiClient->expects($this->once())->method('get')->with(
$this->endPoints->contactIdsInList($this->customerId, $this->contactListId)
)->willReturn($response);

$result = $this->listService->getContactIdsInList($this->customerId, $this->contactListId);
$this->assertEquals($response, $result);
}

/**
* @test
*/
public function getContactIdsInList_ApiCallFails_ExceptionThrown()
{
$this->apiClient->expects($this->once())->method('get')->will($this->apiFailure());
$this->expectException(RequestFailed::class);

$this->listService->getContactIdsInList($this->customerId, $this->contactListId);
}


/**
* @test
Expand Down

0 comments on commit e8af41a

Please sign in to comment.