Skip to content

Commit

Permalink
add support for creating and updating events with objectCategories (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
bverbeken authored Feb 24, 2022
1 parent 6e78268 commit 8abbac2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class Event
*/
public $isEventInSeason;

/**
* @var array
*/
public $objectCategories;

public function isSeason() {
return false;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(Client $client)
$this->client = $client;
}

public function create(string $chartKey, string $eventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null): Event
public function create(string $chartKey, string $eventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null, array $objectCategories = null): Event
{
$request = new stdClass();

Expand All @@ -42,6 +42,10 @@ public function create(string $chartKey, string $eventKey = null, TableBookingCo
$request->socialDistancingRulesetKey = $socialDistancingRulesetKey;
}

if ($objectCategories !== null) {
$request->objectCategories = $objectCategories;
}

$res = $this->client->post('/events', ['json' => $request]);
$json = \GuzzleHttp\json_decode($res->getBody());
$mapper = SeatsioJsonMapper::create();
Expand Down Expand Up @@ -90,7 +94,7 @@ public function retrieve(string $eventKey): Event
return $mapper->map($json, new Event());
}

public function update(string $eventKey, string $chartKey = null, string $newEventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null): void
public function update(string $eventKey, string $chartKey = null, string $newEventKey = null, TableBookingConfig $tableBookingConfig = null, string $socialDistancingRulesetKey = null, $objectCategories = null): void
{
$request = new stdClass();

Expand All @@ -110,6 +114,10 @@ public function update(string $eventKey, string $chartKey = null, string $newEve
$request->socialDistancingRulesetKey = $socialDistancingRulesetKey;
}

if ($objectCategories !== null) {
$request->objectCategories = $objectCategories;
}

$this->client->post(UriTemplate::expand('/events/{key}', array("key" => $eventKey)), ['json' => $request]);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Events/CreateEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ public function testSocialDistancingRulesetKeyCanBePassedIn()
self::assertEquals("ruleset1", $event->socialDistancingRulesetKey);
}

public function testObjectCategoriesCanBePassedIn()
{
$chartKey = $this->createTestChart();

$event = $this->seatsioClient->events->create($chartKey, null, null, null, ["A-1" => 10]);

self::assertEquals(["A-1" => 10], $event->objectCategories);
}

}
22 changes: 22 additions & 0 deletions tests/Events/UpdateEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Seatsio\Charts\SocialDistancingRuleset;
use Seatsio\SeatsioClientTest;
use stdClass;

class UpdateEventTest extends SeatsioClientTest
{
Expand Down Expand Up @@ -75,4 +76,25 @@ public function testRemoveSocialDistancingRulesetKey()
self::assertNull($retrievedEvent->socialDistancingRulesetKey);
}

public function testUpdateObjectCategories()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey, null, null, null, ["A-1" => 9]);

$this->seatsioClient->events->update($event->key, null, null, null, null, ["A-2" => 10]);

$retrievedEvent = $this->seatsioClient->events->retrieve($event->key);
self::assertEquals(["A-2" => 10], $retrievedEvent->objectCategories);
}

public function testRemoveObjectCategories()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey, null, null, null, ["A-1" => 9]);

$this->seatsioClient->events->update($event->key, null, null, null, null, new stdClass());

$retrievedEvent = $this->seatsioClient->events->retrieve($event->key);
self::assertNull($retrievedEvent->objectCategories);
}
}

0 comments on commit 8abbac2

Please sign in to comment.