Skip to content

Commit

Permalink
New channel API endpoints (#54)
Browse files Browse the repository at this point in the history
* 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
bverbeken authored Jun 15, 2022
1 parent c82d4b4 commit 0a0d69e
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 56 deletions.
157 changes: 157 additions & 0 deletions src/Events/Channels.php
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]);
}

}
20 changes: 6 additions & 14 deletions src/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ class Events
*/
private $client;

/**
* @var Channels
*/
public $channels;

public function __construct(Client $client)
{
$this->client = $client;
$this->channels = new Channels($client);
}

public function create(string $chartKey, string $eventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null, array $objectCategories = null): Event
Expand Down Expand Up @@ -178,20 +184,6 @@ public function statusChangesForObject(string $eventKey, string $objectId): Stat
}));
}

public function updateChannels(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]);
}

public function assignObjectsToChannels(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]);
}

public function markAsForSale(string $eventKey, array $objects = null, array $categories = null): void
{
$request = new stdClass();
Expand Down
8 changes: 4 additions & 4 deletions tests/Events/BookObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["A-1", "A-2"]
]);

Expand All @@ -98,10 +98,10 @@ public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["A-1", "A-2"]
]);

Expand Down
8 changes: 4 additions & 4 deletions tests/Events/ChangeBestAvailableObjectStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["B-6"]
]);

Expand All @@ -166,10 +166,10 @@ public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["B-5"]
]);

Expand Down
8 changes: 4 additions & 4 deletions tests/Events/ChangeObjectStatusInBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["A-1"]
]);

Expand All @@ -51,10 +51,10 @@ public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["A-1"]
]);

Expand Down
8 changes: 4 additions & 4 deletions tests/Events/ChangeObjectStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["A-1", "A-2"]
]);

Expand All @@ -144,10 +144,10 @@ public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->updateChannels($event->key, [
$this->seatsioClient->events->channels->replace($event->key, [
"channelKey1" => new Channel("channel 1", "#FF0000", 1)
]);
$this->seatsioClient->events->assignObjectsToChannels($event->key, [
$this->seatsioClient->events->channels->setObjects($event->key, [
"channelKey1" => ["A-1", "A-2"]
]);

Expand Down
55 changes: 55 additions & 0 deletions tests/Events/Channels/AddChannelTest.php
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);
}

}
29 changes: 29 additions & 0 deletions tests/Events/Channels/AddObjectsToChannelTest.php
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);
}

}
Loading

0 comments on commit 0a0d69e

Please sign in to comment.