-
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.
* Added method to list event log items * Check event log item properties
- Loading branch information
Showing
7 changed files
with
199 additions
and
0 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,47 @@ | ||
<?php | ||
|
||
namespace Seatsio\EventLog; | ||
|
||
use GuzzleHttp\Client; | ||
use Seatsio\PageFetcher; | ||
|
||
class EventLog | ||
{ | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
private $client; | ||
|
||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
public function listAll(): EventLogItemPagedIterator | ||
{ | ||
return $this->iterator()->all(); | ||
} | ||
|
||
public function listFirstPage(int $pageSize = null): EventLogItemPage | ||
{ | ||
return $this->iterator()->firstPage($pageSize); | ||
} | ||
|
||
public function listPageAfter(int $afterId, int $pageSize = null): EventLogItemPage | ||
{ | ||
return $this->iterator()->pageAfter($afterId, $pageSize); | ||
} | ||
|
||
public function listPageBefore(int $beforeId, int $pageSize = null): EventLogItemPage | ||
{ | ||
return $this->iterator()->pageBefore($beforeId, $pageSize); | ||
} | ||
|
||
private function iterator(): EventLogItemLister | ||
{ | ||
return new EventLogItemLister(new PageFetcher('/event-log', $this->client, function () { | ||
return new EventLogItemPage(); | ||
})); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Seatsio\EventLog; | ||
|
||
class EventLogItem | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $type; | ||
|
||
/** | ||
* @var \Seatsio\LocalDate | ||
*/ | ||
public $date; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $workspaceKey; | ||
|
||
/** | ||
* @var object | ||
*/ | ||
public $data; | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Seatsio\EventLog; | ||
|
||
use Seatsio\PageFetcher; | ||
|
||
class EventLogItemLister | ||
{ | ||
|
||
protected $pageFetcher; | ||
|
||
public function __construct(PageFetcher $pageFetcher) | ||
{ | ||
$this->pageFetcher = $pageFetcher; | ||
} | ||
|
||
public function all(): EventLogItemPagedIterator | ||
{ | ||
return new EventLogItemPagedIterator($this->pageFetcher); | ||
} | ||
|
||
public function firstPage(int $pageSize = null): EventLogItemPage | ||
{ | ||
return $this->pageFetcher->fetchAfter(null, [], $pageSize); | ||
} | ||
|
||
public function pageAfter(int $afterId, int $pageSize = null): EventLogItemPage | ||
{ | ||
return $this->pageFetcher->fetchAfter($afterId, [], $pageSize); | ||
} | ||
|
||
public function pageBefore(int $beforeId, int $pageSize = null): EventLogItemPage | ||
{ | ||
return $this->pageFetcher->fetchBefore($beforeId, [], $pageSize); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Seatsio\EventLog; | ||
|
||
use Seatsio\Page; | ||
|
||
class EventLogItemPage extends Page | ||
{ | ||
/** | ||
* @var EventLogItem[] | ||
*/ | ||
public $items; | ||
|
||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace Seatsio\EventLog; | ||
|
||
use Seatsio\PagedIterator; | ||
|
||
class EventLogItemPagedIterator extends PagedIterator | ||
{ | ||
|
||
public function current(): EventLogItem | ||
{ | ||
return parent::current(); | ||
} | ||
|
||
} |
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 Seatsio\EventLog; | ||
|
||
use Seatsio\Charts\ChartListParams; | ||
use Seatsio\Events\CreateEventParams; | ||
use Seatsio\Events\ForSaleConfig; | ||
use Seatsio\SeatsioClientTest; | ||
use function Functional\map; | ||
|
||
class ListAllEventLogItemsTest extends SeatsioClientTest | ||
{ | ||
|
||
public function testListAll() | ||
{ | ||
$chart = $this->seatsioClient->charts->create(); | ||
$this->seatsioClient->charts->update($chart->key, "a chart"); | ||
|
||
$this->waitUntilEventLogItemsAvailable(); | ||
|
||
$eventLogItems = $this->seatsioClient->eventLog->listAll(); | ||
$types = map($eventLogItems, function ($eventLogItem) { | ||
return $eventLogItem->type; | ||
}); | ||
|
||
self::assertEquals(["chart.created", "chart.published"], array_values($types)); | ||
} | ||
|
||
public function testProperties() | ||
{ | ||
$chart = $this->seatsioClient->charts->create(); | ||
$this->seatsioClient->charts->update($chart->key, "a chart"); | ||
|
||
$this->waitUntilEventLogItemsAvailable(); | ||
|
||
$eventLogItem = $this->seatsioClient->eventLog->listAll()->current(); | ||
|
||
self::assertEquals("chart.created", $eventLogItem->type); | ||
self::assertEquals($this->workspace->key, $eventLogItem->workspaceKey); | ||
self::assertNotNull($eventLogItem->date); | ||
self::assertGreaterThan(0, $eventLogItem->id); | ||
self::assertEquals((object)["key" => $chart->key], $eventLogItem->data); | ||
} | ||
|
||
private function waitUntilEventLogItemsAvailable() | ||
{ | ||
sleep(2); | ||
} | ||
} |