diff --git a/README.md b/README.md index 260b40fe..0415df67 100644 --- a/README.md +++ b/README.md @@ -386,11 +386,9 @@ $client->customerEntry()->deleteWebsite($customerId, $websiteId); ### Properties -Get a customer's properties and their values +Get a customer's properties and their values. ```php -use HelpScout\Api\Customers\Entry\Website; - $customer = $client->customers()->get(418048101); // ... @@ -399,6 +397,20 @@ foreach ($customer->getProperties() as $property) { } ``` +Update a customer's properties. +```php +use HelpScout\Api\Entity\Collection; +use HelpScout\Api\Entity\Patch; + +$operations = new Collection( + [ + new Patch('remove', 'property-1'), + new Patch('replace', 'property-2', 'value'), + ]; +); +$client->customerEntry()->updateProperties($customerId, $operations); + +``` ## Mailboxes Get a mailbox. diff --git a/src/Customers/Entry/CustomerEntryEndpoint.php b/src/Customers/Entry/CustomerEntryEndpoint.php index f6a84a23..a628076d 100644 --- a/src/Customers/Entry/CustomerEntryEndpoint.php +++ b/src/Customers/Entry/CustomerEntryEndpoint.php @@ -5,6 +5,7 @@ namespace HelpScout\Api\Customers\Entry; use HelpScout\Api\Endpoint; +use HelpScout\Api\Entity\Collection; class CustomerEntryEndpoint extends Endpoint { @@ -19,6 +20,7 @@ class CustomerEntryEndpoint extends Endpoint public const CUSTOMER_SOCIAL = '/v2/customers/%d/social-profiles/%d'; public const CREATE_CUSTOMER_WEBSITE = '/v2/customers/%d/websites'; public const CUSTOMER_WEBSITE = '/v2/customers/%d/websites/%d'; + public const CUSTOMER_PROPERTIES= '/v2/customers/%d/properties'; public function createAddress(int $customerId, Address $address): ?int { @@ -156,4 +158,12 @@ public function deleteWebsite(int $customerId, int $websiteId): void sprintf(self::CUSTOMER_WEBSITE, $customerId, $websiteId) ); } + + public function updateProperties(int $customerId, Collection $propertyPatches): void + { + $this->restClient->patchResource( + $propertyPatches, + sprintf(self::CUSTOMER_PROPERTIES, $customerId) + ); + } } diff --git a/tests/Customers/Entry/CustomerEntryClientIntegrationTest.php b/tests/Customers/Entry/CustomerEntryClientIntegrationTest.php index 5dd80e26..e1cea5b4 100644 --- a/tests/Customers/Entry/CustomerEntryClientIntegrationTest.php +++ b/tests/Customers/Entry/CustomerEntryClientIntegrationTest.php @@ -10,6 +10,8 @@ use HelpScout\Api\Customers\Entry\Phone; use HelpScout\Api\Customers\Entry\SocialProfile; use HelpScout\Api\Customers\Entry\Website; +use HelpScout\Api\Entity\Collection; +use HelpScout\Api\Entity\Patch; use HelpScout\Api\Tests\ApiClientIntegrationTestCase; /** @@ -361,4 +363,21 @@ public function testDeleteCustomerWebsite() 'DELETE' ); } + + public function testUpdateCustomerProperties() + { + $this->stubResponse($this->getResponse(204)); + + $operations = new Collection( + [ + new Patch('remove', 'value1'), + ] + ); + $this->client->customerEntry()->updateProperties(12, $operations); + + $this->verifySingleRequest( + 'https://api.helpscout.net/v2/customers/12/properties', + 'PATCH' + ); + } }