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
14 changes: 10 additions & 4 deletions src/Requests/Contacts/ContactRetrieveRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ class ContactRetrieveRequest extends Request
{
protected Method $method = Method::GET;

public function __construct(protected readonly string $email)
{
public function __construct(
protected readonly string|null $email = null,
protected readonly string|null $userId = null
) {
if (($email === null && $userId === null) || ($email !== null && $userId !== null)) {
throw new \InvalidArgumentException('Exactly one of email or userId must be provided');
}
}

public function createDtoFromResponse(Response $response): Contact|null
Expand All @@ -31,9 +36,10 @@ public function createDtoFromResponse(Response $response): Contact|null

protected function defaultQuery(): array
{
return [
return array_filter([
'email' => $this->email,
];
'userId' => $this->userId,
]);
}

public function resolveEndpoint(): string
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/ContactResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function delete(string|null $email = null, string|null $userId = null): C
return $response;
}

public function retrieve(string $email): Contact
public function retrieve(?string $email = null, ?string $userId = null): Contact|null
{
/** @var Contact $contact */
$contact = $this->connector->send(new ContactRetrieveRequest($email))->dto();
/** @var Contact|null $contact */
$contact = $this->connector->send(new ContactRetrieveRequest($email, $userId))->dto();

return $contact;
}
Expand Down