Skip to content

Commit

Permalink
Devedup/master (#48)
Browse files Browse the repository at this point in the history
* Allow cio_id to be used as the identifier on the path

If you want to update identifiers that are already set for a person, you must reference them using their cio_id in the format cio_<cio_id_value>; attempting to update identifier values for a person without referencing them by cio_id will result in an Attribute Update Failure.

* cio_id on the path needed prefix cio_

* allow events to use cio identifier

* fix: customer endpoints

Co-authored-by: DaveC @ DevedUp <[email protected]>
  • Loading branch information
krzaczek and devedup authored Nov 23, 2021
1 parent 80ad77d commit c69fffb
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/Endpoint/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function __construct($client)
*/
public function event(array $options)
{
if (!isset($options['id']) && !isset($options['email'])) {
$this->mockException('User id or email is required!', 'POST');
if (!isset($options['id']) && !isset($options['email']) && !isset($options['cio_id'])) {
$this->mockException('User id, email or cio_id is required!', 'POST');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);
Expand All @@ -44,16 +44,15 @@ public function event(array $options)
*/
public function add(array $options)
{
if (!isset($options['id']) && !isset($options['email'])) {
if (!isset($options['id']) && !isset($options['email']) && !isset($options['cio_id'])) {
$this->mockException('User id or email is required!', 'PUT');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);

return $this->client->put($path, $options);
}




/**
* Delete customer
Expand All @@ -63,7 +62,7 @@ public function add(array $options)
*/
public function delete(array $options)
{
if (!isset($options['id']) && !isset($options['email'])) {
if (!isset($options['id']) && !isset($options['email']) && !isset($options['cio_id'])) {
$this->mockException('User id or email is required!', 'DELETE');
} // @codeCoverageIgnore

Expand Down Expand Up @@ -130,7 +129,7 @@ public function attributes(array $options)
$this->mockException('User id or email is required!', 'GET');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);
$path = $this->setCustomerPathWithIdentifier($options, ['attributes']);

return $this->client->get($path, $options);
}
Expand All @@ -147,7 +146,7 @@ public function segments(array $options)
$this->mockException('User id or email is required!', 'GET');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);
$path = $this->setCustomerPathWithIdentifier($options, ['segments']);

return $this->client->get($path, $options);
}
Expand All @@ -164,8 +163,8 @@ public function messages(array $options)
$this->mockException('User id or email is required!', 'GET');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);
$path = $this->setCustomerPathWithIdentifier($options, ['messages']);

return $this->client->get($path, $options);
}

Expand All @@ -177,11 +176,11 @@ public function messages(array $options)
*/
public function activities(array $options)
{
if (!isset($options['id']) && !isset($options['email'])) {
if (!isset($options['id']) && !isset($options['email'])) {
$this->mockException('User id or email is required!', 'GET');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);
$path = $this->setCustomerPathWithIdentifier($options, ['activities']);

return $this->client->get($path, $options);
}
Expand All @@ -198,8 +197,8 @@ public function suppress(array $options)
$this->mockException('User id or email is required!', 'GET');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);
$path = $this->setCustomerPathWithIdentifier($options, ['suppress']);

return $this->client->post($path, $options);
}

Expand All @@ -211,28 +210,30 @@ public function suppress(array $options)
*/
public function unsuppress(array $options)
{
if (!isset($options['id']) && !isset($options['email'])) {
if (!isset($options['id']) && !isset($options['email'])) {
$this->mockException('User id or email is required!', 'GET');
} // @codeCoverageIgnore

$path = $this->setCustomerPathWithIdentifier($options);
$path = $this->setCustomerPathWithIdentifier($options, ['unsuppress']);

return $this->client->post($path, $options);
}
/**


/**
* Set the customer path with the relevant identifier
* @param array $options
* @param array $params
* @return string
*/
private function setCustomerPathWithIdentifier(array &$options): string {

$customerIdentifierProperty = isset($options['id']) ? 'id' : 'email';
private function setCustomerPathWithIdentifier(array &$options, array $params = []): string
{
$customerIdentifierProperty = isset($options['cio_id']) ? 'cio_id' : (isset($options['id']) ? 'id' : 'email');
$customerIdentifierPrefix = isset($options['cio_id']) ? 'cio_' : '';

$path = $this->customerPath($options[$customerIdentifierProperty]);
$path = $this->customerPath($customerIdentifierPrefix.$options[$customerIdentifierProperty], $params);
unset($options[$customerIdentifierProperty]);

return $path;
}
}

0 comments on commit c69fffb

Please sign in to comment.