Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/contact-lists/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
}


/**
* Get all Contact Lists filtered by name (case-insensitive prefix match).
*
* GET https://mailtrap.io/api/accounts/{account_id}/contacts/lists?search=news
*/
try {
$response = $contacts->getAllContactLists('news'); // Replace 'news' with your desired name prefix

// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}


/**
* Get a specific Contact List by ID.
*
Expand Down
10 changes: 8 additions & 2 deletions src/Api/General/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ public function __construct(ConfigInterface $config, private int $accountId)
/**
* Get all Contact Lists.
*
* @param string|null $search Filter contact lists by name (case-insensitive prefix match), or null to get all.
* @return ResponseInterface
*/
public function getAllContactLists(): ResponseInterface
public function getAllContactLists(?string $search = null): ResponseInterface
{
$parameters = [];
if ($search !== null) {
$parameters['search'] = $search;
}

return $this->handleResponse(
$this->httpGet($this->getBasePath() . '/lists')
$this->httpGet($this->getBasePath() . '/lists', $parameters)
);
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Api/General/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ public function testGetAllContactLists(): void
$this->assertArrayHasKey('id', $responseData[0]);
}

public function testGetAllContactListsWithSearch(): void
{
$search = 'news';

$this->contact->expects($this->once())
->method('httpGet')
->with(
AbstractApi::DEFAULT_HOST . '/api/accounts/' . self::FAKE_ACCOUNT_ID . '/contacts/lists',
['search' => $search]
)
->willReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode($this->getExpectedContactLists())));

$response = $this->contact->getAllContactLists($search);
$responseData = ResponseHelper::toArray($response);

$this->assertInstanceOf(Response::class, $response);
$this->assertCount(2, $responseData);
$this->assertArrayHasKey('id', $responseData[0]);
}

public function testGetContactList(): void
{
$contactListId = 1;
Expand Down
Loading