Skip to content

Commit

Permalink
feat: add track v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
krzaczek committed Jan 17, 2025
1 parent 09666dc commit c10799c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Client
/** @var Endpoint\Collections */
public $collection;

/** @var Endpoint\Track */
public $track;

/**
* Client constructor.
* @param string $apiKey Api Key
Expand All @@ -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;
Expand Down
41 changes: 41 additions & 0 deletions src/Endpoint/Track.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Customerio\Endpoint;

use GuzzleHttp\Exception\GuzzleException;

class Track extends Base
{
public function entity(array $options)
{
if (!isset($options['type'])) {
$this->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);
}
}
4 changes: 2 additions & 2 deletions src/Region/RegionEu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Region/RegionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface RegionInterface
*
* @return string
*/
public function trackUri(): string;
public function trackUri(string $version = 'v1'): string;

/**
* API
Expand Down
4 changes: 2 additions & 2 deletions src/Region/RegionUs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c10799c

Please sign in to comment.