Skip to content

Commit

Permalink
Merge pull request #283 from leewillis77/master
Browse files Browse the repository at this point in the history
Add support to CustomerEntry for patching customer properties
  • Loading branch information
bkuhl authored Aug 12, 2021
2 parents 3a0984d + 10653d0 commit 658c37e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// ...

Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/Customers/Entry/CustomerEntryEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace HelpScout\Api\Customers\Entry;

use HelpScout\Api\Endpoint;
use HelpScout\Api\Entity\Collection;

class CustomerEntryEndpoint extends Endpoint
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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)
);
}
}
19 changes: 19 additions & 0 deletions tests/Customers/Entry/CustomerEntryClientIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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'
);
}
}

0 comments on commit 658c37e

Please sign in to comment.