From c10799c3e55eeb38258d0ce43d2ed49390ca502a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Krzaczkowski?= Date: Fri, 17 Jan 2025 17:09:12 +0100 Subject: [PATCH] feat: add track v2 support --- src/Client.php | 4 ++++ src/Endpoint/Track.php | 41 ++++++++++++++++++++++++++++++++++ src/Region/RegionEu.php | 4 ++-- src/Region/RegionInterface.php | 2 +- src/Region/RegionUs.php | 4 ++-- 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/Endpoint/Track.php diff --git a/src/Client.php b/src/Client.php index 959617e..790693a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -70,6 +70,9 @@ class Client /** @var Endpoint\Collections */ public $collection; + /** @var Endpoint\Track */ + public $track; + /** * Client constructor. * @param string $apiKey Api Key @@ -92,6 +95,7 @@ public function __construct(string $apiKey, string $siteId, array $options = []) $this->senderIdentities = new Endpoint\SenderIdentities($this); $this->send = new Endpoint\Send($this); $this->collection = new Endpoint\Collections($this); + $this->track = new Endpoint\Track($this); $this->apiKey = $apiKey; $this->siteId = $siteId; diff --git a/src/Endpoint/Track.php b/src/Endpoint/Track.php new file mode 100644 index 0000000..302e4da --- /dev/null +++ b/src/Endpoint/Track.php @@ -0,0 +1,41 @@ +mockException('Operation type is required!', 'POST'); + } // @codeCoverageIgnore + + if (!isset($options['action'])) { + $this->mockException('An event action is required!', 'POST'); + } // @codeCoverageIgnore + + if (!isset($options['identifiers'])) { + $this->mockException('Object identifiers is required!', 'POST'); + } // @codeCoverageIgnore + + $path = $this->generatePath('entity'); + $options['endpoint'] = $this->client->getRegion()->trackUri('v2'); + + return $this->client->post($path, $options); + + } + + public function batch(array $options) + { + if (!isset($options['batch'])) { + $this->mockException('Batch paremeter is required!', 'POST'); + } // @codeCoverageIgnore + + $path = $this->generatePath('batch'); + $options['endpoint'] = $this->client->getRegion()->trackUri('v2'); + + return $this->client->post($path, $options); + } +} diff --git a/src/Region/RegionEu.php b/src/Region/RegionEu.php index 86c1dc3..4ab90df 100644 --- a/src/Region/RegionEu.php +++ b/src/Region/RegionEu.php @@ -6,9 +6,9 @@ class RegionEu implements RegionInterface { - public function trackUri(): string + public function trackUri(string $version = 'v1'): string { - return 'https://track-eu.customer.io/api/v1/'; + return 'https://track-eu.customer.io/api/'.$version.'/'; } public function apiUri(): string diff --git a/src/Region/RegionInterface.php b/src/Region/RegionInterface.php index 745148b..c36a254 100644 --- a/src/Region/RegionInterface.php +++ b/src/Region/RegionInterface.php @@ -11,7 +11,7 @@ interface RegionInterface * * @return string */ - public function trackUri(): string; + public function trackUri(string $version = 'v1'): string; /** * API diff --git a/src/Region/RegionUs.php b/src/Region/RegionUs.php index cf196ee..54846eb 100644 --- a/src/Region/RegionUs.php +++ b/src/Region/RegionUs.php @@ -6,9 +6,9 @@ class RegionUs implements RegionInterface { - public function trackUri(): string + public function trackUri(string $version = 'v1'): string { - return 'https://track.customer.io/api/v1/'; + return 'https://track.customer.io/api/'.$version.'/'; } public function apiUri(): string