-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* renamed tests * moved updateChannels() and assignObjectsToChannel() to Channels object (and renamed to replace() and setObjects()) * add Channel * AddObjectsToChannel, RemoveChannel, RemoveObjectsFromChannel, ReplaceCHannels * update channel
- Loading branch information
Showing
17 changed files
with
399 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
namespace Seatsio\Events; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\UriTemplate\UriTemplate; | ||
use stdClass; | ||
|
||
class Channels | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
private $client; | ||
|
||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
|
||
/** | ||
* Add a channel | ||
* | ||
* @param string $eventKey | ||
* @param string $channelKey | ||
* @param string $name | ||
* @param string $color | ||
* @param int|null $index | ||
* @param array|null $objects | ||
* @return void | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function add(string $eventKey, string $channelKey, string $name, string $color, int $index = null, array $objects = null) | ||
{ | ||
$request = new stdClass(); | ||
$request->key = $channelKey; | ||
$request->name = $name; | ||
$request->color = $color; | ||
if ($index !== null) { | ||
$request->index = $index; | ||
} | ||
if ($objects !== null) { | ||
$request->objects = $objects; | ||
} | ||
$this->client->post(UriTemplate::expand('/events/{key}/channels', array("key" => $eventKey)), ['json' => $request]); | ||
} | ||
|
||
/** | ||
* remove a channel by channel key | ||
* | ||
* @param string $eventKey | ||
* @param string $channelKey | ||
* @return void | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function remove(string $eventKey, string $channelKey) | ||
{ | ||
$this->client->delete(UriTemplate::expand('/events/{eventKey}/channels/{channelKey}', array("eventKey" => $eventKey, "channelKey" => $channelKey))); | ||
} | ||
|
||
/** | ||
* update the name, color or objects of a channel | ||
* | ||
* @param string $eventKey | ||
* @param string $channelKey | ||
* @param string|null $name | ||
* @param string|null $color | ||
* @param array|null $objects | ||
* @return void | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function update(string $eventKey, string $channelKey, string $name = null, string $color = null, array $objects = null) | ||
{ | ||
$request = new stdClass(); | ||
if ($name !== null) { | ||
$request->name = $name; | ||
} | ||
if ($color !== null) { | ||
$request->color = $color; | ||
} | ||
if ($objects !== null) { | ||
$request->objects = $objects; | ||
} | ||
$this->client->post(UriTemplate::expand('/events/{eventKey}/channels/{channelKey}', array("eventKey" => $eventKey, "channelKey" => $channelKey)), | ||
['json' => $request]); | ||
} | ||
|
||
/** | ||
* add objects to a channel. | ||
* | ||
* @param string $eventKey | ||
* @param string $channelKey | ||
* @param array $objects | ||
* @return void | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function addObjects(string $eventKey, string $channelKey, array $objects) | ||
{ | ||
$request = new stdClass(); | ||
$request->objects = $objects; | ||
$this->client->post(UriTemplate::expand('/events/{eventKey}/channels/{channelKey}/objects', array( | ||
"eventKey" => $eventKey, | ||
"channelKey" => $channelKey) | ||
), ['json' => $request]); | ||
} | ||
|
||
/** | ||
* Remove objects from a channel | ||
* | ||
* @param string $eventKey | ||
* @param string $channelKey | ||
* @param array $objects | ||
* @return void | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function removeObjects(string $eventKey, string $channelKey, array $objects) | ||
{ | ||
$request = new stdClass(); | ||
$request->objects = $objects; | ||
$this->client->delete(UriTemplate::expand('/events/{eventKey}/channels/{channelKey}/objects', array( | ||
"eventKey" => $eventKey, | ||
"channelKey" => $channelKey) | ||
), ['json' => $request]); | ||
} | ||
|
||
/** | ||
* Replace one channel completely with a new channel | ||
* | ||
* @param string $eventKey | ||
* @param array $channels | ||
* @return void | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function replace(string $eventKey, array $channels): void | ||
{ | ||
$request = new stdClass(); | ||
$request->channels = $channels; | ||
$this->client->post(UriTemplate::expand('/events/{key}/channels/update', array("key" => $eventKey)), ['json' => $request]); | ||
} | ||
|
||
/** | ||
* Replace the list of current object labels on a channel with a new list of object labels. | ||
* | ||
* @param string $eventKey | ||
* @param array $channelConfig | ||
* @return void | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function setObjects(string $eventKey, array $channelConfig): void | ||
{ | ||
$request = new stdClass(); | ||
$request->channelConfig = $channelConfig; | ||
$this->client->post(UriTemplate::expand('/events/{key}/channels/assign-objects', array("key" => $eventKey)), ['json' => $request]); | ||
} | ||
|
||
} |
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
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,55 @@ | ||
<?php | ||
|
||
namespace Seatsio\Events\Channels; | ||
|
||
use Seatsio\Events\Channel; | ||
use Seatsio\SeatsioClientTest; | ||
|
||
class AddChannelTest extends SeatsioClientTest | ||
{ | ||
|
||
public function testAddChannel() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$event = $this->seatsioClient->events->create($chartKey); | ||
|
||
$this->seatsioClient->events->channels->add($event->key, "channelKey1", "channel 1", "#FFFF98", 1, ["A-1", "A-2"]); | ||
$this->seatsioClient->events->channels->add($event->key, "channelKey2", "channel 2", "#FFFF99", 2, ["A-3"]); | ||
|
||
$retrievedEvent = $this->seatsioClient->events->retrieve($event->key); | ||
|
||
self::assertEquals([ | ||
new Channel("channel 1", "#FFFF98", 1, "channelKey1", ["A-1", "A-2"]), | ||
new Channel("channel 2", "#FFFF99", 2, "channelKey2", ["A-3"]) | ||
], $retrievedEvent->channels); | ||
} | ||
|
||
public function testIndexIsOptional() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$event = $this->seatsioClient->events->create($chartKey); | ||
|
||
$this->seatsioClient->events->channels->add($event->key, "channelKey1", "channel 1", "#FFFF98", null, ["A-1", "A-2"]); | ||
|
||
$retrievedEvent = $this->seatsioClient->events->retrieve($event->key); | ||
|
||
self::assertEquals([ | ||
new Channel("channel 1", "#FFFF98", 0, "channelKey1", ["A-1", "A-2"]), | ||
], $retrievedEvent->channels); | ||
} | ||
|
||
public function testObjectsAreOptional() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$event = $this->seatsioClient->events->create($chartKey); | ||
|
||
$this->seatsioClient->events->channels->add($event->key, "channelKey1", "channel 1", "#FFFF98", 1, null); | ||
|
||
$retrievedEvent = $this->seatsioClient->events->retrieve($event->key); | ||
|
||
self::assertEquals([ | ||
new Channel("channel 1", "#FFFF98", 1, "channelKey1", []), | ||
], $retrievedEvent->channels); | ||
} | ||
|
||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace Seatsio\Events\Channels; | ||
|
||
use Seatsio\Events\Channel; | ||
use Seatsio\SeatsioClientTest; | ||
|
||
class AddObjectsToChannelTest extends SeatsioClientTest | ||
{ | ||
|
||
public function test() | ||
{ | ||
$chartKey = $this->createTestChart(); | ||
$event = $this->seatsioClient->events->create($chartKey); | ||
|
||
$this->seatsioClient->events->channels->add($event->key, "channelKey1", "channel 1", "#FFFF98", 1, ["A-1", "A-2"]); | ||
$this->seatsioClient->events->channels->add($event->key, "channelKey2", "channel 2", "#FFFF99", 2, ["A-3", "A-4"]); | ||
|
||
$this->seatsioClient->events->channels->addObjects($event->key, "channelKey1", ["A-3", "A-4"]); | ||
|
||
$retrievedEvent = $this->seatsioClient->events->retrieve($event->key); | ||
|
||
self::assertEquals([ | ||
new Channel("channel 1", "#FFFF98", 1, "channelKey1", ["A-1", "A-2", "A-3", "A-4"]), | ||
new Channel("channel 2", "#FFFF99", 2, "channelKey2", []) | ||
], $retrievedEvent->channels); | ||
} | ||
|
||
} |
Oops, something went wrong.