-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
353 additions
and
1 deletion.
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
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,149 @@ | ||
<?php | ||
|
||
namespace Customerio\Endpoint; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
|
||
class Collections extends Base | ||
{ | ||
|
||
/** | ||
* List collections | ||
* @see https://customer.io/docs/api/#operation/getCollections | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
public function search(array $options) | ||
{ | ||
$path = $this->collectionsPath(); | ||
|
||
return $this->client->get($path, $options); | ||
} | ||
|
||
/** | ||
* Get collection | ||
* @see https://customer.io/docs/api/#operation/getCollection | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
public function get(array $options) | ||
{ | ||
if (!isset($options['id'])) { | ||
$this->mockException('Collection id is required!', 'GET'); | ||
} // @codeCoverageIgnore | ||
|
||
$path = $this->collectionsPath($options['id']); | ||
unset($options['id']); | ||
|
||
return $this->client->get($path, $options); | ||
} | ||
|
||
/** | ||
* Create collection | ||
* @see https://customer.io/docs/api/#operation/addCollection | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
public function create(array $options) | ||
{ | ||
if (!isset($options['name'])) { | ||
$this->mockException('Collection name is required!', 'POST'); | ||
} | ||
|
||
if (!isset($options['data']) && !isset($options['url'])) { | ||
$this->mockException('Collection data or url is required!', 'POST'); | ||
} // @codeCoverageIgnore | ||
|
||
$path = $this->collectionsPath(); | ||
$options['endpoint'] = $this->client->getRegion()->betaUri(); | ||
|
||
return $this->client->post($path, $options); | ||
} | ||
|
||
/** | ||
* Delete a collection | ||
* @see https://customer.io/docs/api/#operation/deleteCollection | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
public function delete(array $options) | ||
{ | ||
if (!isset($options['collection_id'])) { | ||
$this->mockException('Collection collection_id is required!', 'POST'); | ||
} | ||
|
||
$path = $this->collectionsPath($options['collection_id']); | ||
unset($options['collection_id']); | ||
$options['endpoint'] = $this->client->getRegion()->betaUri(); | ||
|
||
return $this->client->delete($path, $options); | ||
} | ||
|
||
/** | ||
* Update a collection name or data | ||
* @see https://customer.io/docs/api/#operation/updateCollection | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
public function update(array $options) | ||
{ | ||
if (!isset($options['collection_id'])) { | ||
$this->mockException('Collection collection_id is required!', 'POST'); | ||
} | ||
|
||
$path = $this->collectionsPath($options['collection_id']); | ||
unset($options['collection_id']); | ||
$options['endpoint'] = $this->client->getRegion()->betaUri(); | ||
|
||
return $this->client->put($path, $options); | ||
} | ||
|
||
/** | ||
* Get collection content | ||
* @see https://customer.io/docs/api/#operation/getCollectionContents | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
public function content(array $options) | ||
{ | ||
if (!isset($options['collection_id'])) { | ||
$this->mockException('Collection collection_id is required!', 'POST'); | ||
} | ||
|
||
$path = $this->collectionsPath($options['collection_id'], ['content']); | ||
unset($options['collection_id']); | ||
$options['raw'] = true; | ||
|
||
return $this->client->get($path, $options); | ||
} | ||
|
||
/** | ||
* Update collection data | ||
* @see https://customer.io/docs/api/#operation/updateCollectionContents | ||
* @param array $options | ||
* @return mixed | ||
* @throws GuzzleException | ||
*/ | ||
public function updateContent(array $options) | ||
{ | ||
if (!isset($options['collection_id'])) { | ||
$this->mockException('Collection collection_id is required!', 'POST'); | ||
} | ||
|
||
if (!isset($options['data'])) { | ||
$this->mockException('Collection data is required!', 'POST'); | ||
} // @codeCoverageIgnore | ||
|
||
$path = $this->collectionsPath($options['collection_id'], ['content']); | ||
$options = $options['data']; | ||
$options['endpoint'] = $this->client->getRegion()->betaUri(); | ||
|
||
return $this->client->put($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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ public function testBasicClientUs() | |
new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}"), | ||
new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}"), | ||
new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}"), | ||
new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}"), | ||
]); | ||
$container = []; | ||
$history = Middleware::history($container); | ||
|
@@ -35,6 +36,9 @@ public function testBasicClientUs() | |
$client->customers->get([ | ||
'email' => '[email protected]', | ||
]); | ||
$client->collection->content([ | ||
'collection_id' => 1, | ||
]); | ||
$client->customers->add([ | ||
'id' => 10, | ||
'email' => '[email protected]', | ||
|
Oops, something went wrong.