From c69fffbc4ddeff87348af5d6b46fc3d27a57ab75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Krzaczkowski?= Date: Tue, 23 Nov 2021 10:38:11 +0100 Subject: [PATCH] Devedup/master (#48) * 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_; 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 --- src/Endpoint/Customers.php | 49 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Endpoint/Customers.php b/src/Endpoint/Customers.php index c237b69..b9d9b30 100644 --- a/src/Endpoint/Customers.php +++ b/src/Endpoint/Customers.php @@ -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); @@ -44,7 +44,7 @@ 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 @@ -52,8 +52,7 @@ public function add(array $options) return $this->client->put($path, $options); } - - + /** * Delete customer @@ -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 @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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; } }