-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add track v2 support * chore: code cleanup * feat: update descriptions * fix: add basic tests
- Loading branch information
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Customerio\Endpoint; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
|
||
class Track extends Base | ||
{ | ||
/** | ||
* Make a single request | ||
* @see https://docs.customer.io/api/track/#operation/entity | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
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); | ||
} | ||
|
||
/** | ||
* Send multiple requests | ||
* @see https://docs.customer.io/api/track/#operation/batch | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Customerio\Tests; | ||
|
||
use Customerio\Endpoint\Track; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TrackTest extends TestCase | ||
{ | ||
public function testSingleEntity() | ||
{ | ||
$stub = $this->getMockBuilder('Customerio\Client')->disableOriginalConstructor()->getMock(); | ||
$stub->method('post')->willReturn('foo'); | ||
$events = new Track($stub); | ||
$this->assertEquals('foo', $events->entity([ | ||
'type' => 'person', | ||
'identifiers' => [ | ||
'id' => '12345', | ||
], | ||
'action' => 'event', | ||
'name' => 'test new event', | ||
])); | ||
} | ||
|
||
public function testBatchEntity() | ||
{ | ||
$stub = $this->getMockBuilder('Customerio\Client')->disableOriginalConstructor()->getMock(); | ||
$stub->method('post')->willReturn('foo'); | ||
$events = new Track($stub); | ||
$this->assertEquals('foo', $events->batch( | ||
["batch" => [[ | ||
'type' => 'person', | ||
'identifiers' => [ | ||
'id' => 'ziT8aeAcSdYBKvYCzx', | ||
], | ||
'action' => 'event', | ||
'name' => 'test new event', | ||
], | ||
[ | ||
'type' => 'person', | ||
'identifiers' => [ | ||
'id' => 'ziT8aeAcSdYBKvYCzx', | ||
], | ||
'action' => 'event', | ||
'name' => 'test new event 2', | ||
]]] | ||
)); | ||
} | ||
} |