diff --git a/src/EventLog/EventLog.php b/src/EventLog/EventLog.php new file mode 100644 index 0000000..dca12af --- /dev/null +++ b/src/EventLog/EventLog.php @@ -0,0 +1,47 @@ +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(); + })); + } +} diff --git a/src/EventLog/EventLogItem.php b/src/EventLog/EventLogItem.php new file mode 100644 index 0000000..bab2f0f --- /dev/null +++ b/src/EventLog/EventLogItem.php @@ -0,0 +1,31 @@ +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); + } +} diff --git a/src/EventLog/EventLogItemPage.php b/src/EventLog/EventLogItemPage.php new file mode 100644 index 0000000..372a12b --- /dev/null +++ b/src/EventLog/EventLogItemPage.php @@ -0,0 +1,14 @@ +clientConfig($secretKey, $workspaceKey, $region->url(), $maxRetries)); @@ -71,6 +77,7 @@ public function __construct(Region $region, string $secretKey, string $workspace $this->usageReports = new UsageReports($client); $this->workspaces = new Workspaces($client); $this->holdTokens = new HoldTokens($client); + $this->eventLog = new EventLog($client); } private function clientConfig($secretKey, $workspaceKey, $baseUrl, $maxRetries) diff --git a/tests/EventLog/ListAllEventLogItemsTest.php b/tests/EventLog/ListAllEventLogItemsTest.php new file mode 100644 index 0000000..a017868 --- /dev/null +++ b/tests/EventLog/ListAllEventLogItemsTest.php @@ -0,0 +1,49 @@ +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); + } +}