From 8b9b3a55cbbf7eddf07f338372b5658c0acdeb25 Mon Sep 17 00:00:00 2001 From: mroloux Date: Wed, 5 Jun 2019 11:12:59 +0200 Subject: [PATCH 1/3] Added usage reports --- src/Reports/{ => Charts}/ChartReportItem.php | 4 +- src/Reports/{ => Charts}/ChartReports.php | 2 +- src/Reports/{ => Events}/EventReportItem.php | 2 +- src/Reports/{ => Events}/EventReports.php | 4 +- .../DetailsForEventInMonth/UsageForObject.php | 34 +++++++++++ src/Reports/Usage/DetailsForMonth/Chart.php | 19 ++++++ src/Reports/Usage/DetailsForMonth/Event.php | 19 ++++++ .../Usage/DetailsForMonth/Subaccount.php | 14 +++++ .../Usage/DetailsForMonth/UsageByChart.php | 19 ++++++ .../Usage/DetailsForMonth/UsageByEvent.php | 44 ++++++++++++++ .../Usage/DetailsForMonth/UsageDetails.php | 19 ++++++ src/Reports/Usage/SummaryForMonths/Month.php | 30 ++++++++++ .../SummaryForMonths/UsageSummaryForMonth.php | 35 +++++++++++ src/Reports/Usage/UsageReports.php | 60 +++++++++++++++++++ src/SeatsioClient.php | 8 ++- .../ChartReportTest.php | 2 +- .../EventReportSummaryTest.php | 2 +- .../EventReportTest.php | 2 +- tests/Reports/UsageReportTest.php | 28 +++++++++ 19 files changed, 335 insertions(+), 12 deletions(-) rename src/Reports/{ => Charts}/ChartReportItem.php (93%) rename src/Reports/{ => Charts}/ChartReports.php (97%) rename src/Reports/{ => Events}/EventReportItem.php (96%) rename src/Reports/{ => Events}/EventReports.php (99%) create mode 100644 src/Reports/Usage/DetailsForEventInMonth/UsageForObject.php create mode 100644 src/Reports/Usage/DetailsForMonth/Chart.php create mode 100644 src/Reports/Usage/DetailsForMonth/Event.php create mode 100644 src/Reports/Usage/DetailsForMonth/Subaccount.php create mode 100644 src/Reports/Usage/DetailsForMonth/UsageByChart.php create mode 100644 src/Reports/Usage/DetailsForMonth/UsageByEvent.php create mode 100644 src/Reports/Usage/DetailsForMonth/UsageDetails.php create mode 100644 src/Reports/Usage/SummaryForMonths/Month.php create mode 100644 src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php create mode 100644 src/Reports/Usage/UsageReports.php rename tests/{ChartReports => Reports}/ChartReportTest.php (98%) rename tests/{EventReports => Reports}/EventReportSummaryTest.php (99%) rename tests/{EventReports => Reports}/EventReportTest.php (99%) create mode 100644 tests/Reports/UsageReportTest.php diff --git a/src/Reports/ChartReportItem.php b/src/Reports/Charts/ChartReportItem.php similarity index 93% rename from src/Reports/ChartReportItem.php rename to src/Reports/Charts/ChartReportItem.php index 12f757f..231e384 100644 --- a/src/Reports/ChartReportItem.php +++ b/src/Reports/Charts/ChartReportItem.php @@ -1,6 +1,6 @@ $eventKey, "reportType" => $reportType)); } -} \ No newline at end of file +} diff --git a/src/Reports/Usage/DetailsForEventInMonth/UsageForObject.php b/src/Reports/Usage/DetailsForEventInMonth/UsageForObject.php new file mode 100644 index 0000000..26a28b5 --- /dev/null +++ b/src/Reports/Usage/DetailsForEventInMonth/UsageForObject.php @@ -0,0 +1,34 @@ +year = $year; + $this->month = $month; + } + + public function serialize() { + return $this->year . '-' . str_pad($this->month, 2, '0', STR_PAD_LEFT); + } + +} diff --git a/src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php b/src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php new file mode 100644 index 0000000..eef962e --- /dev/null +++ b/src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php @@ -0,0 +1,35 @@ +client = $client; + } + + /** + * @return UsageSummaryForMonth[] + */ + public function summaryForAllMonths() + { + $res = $this->client->get('/reports/usage'); + $json = \GuzzleHttp\json_decode($res->getBody()); + $mapper = SeatsioJsonMapper::create(); + return $mapper->mapArray($json, array(), UsageSummaryForMonth::class); + } + + /** + * @param Month $month + * @return UsageDetails[] + */ + public function detailsForMonth($month) + { + $res = $this->client->get('/reports/usage/month/' . $month->serialize()); + $json = \GuzzleHttp\json_decode($res->getBody()); + $mapper = SeatsioJsonMapper::create(); + return $mapper->mapArray($json, array(), UsageDetails::class); + } + + /** + * @param int $eventId + * @param Month $month + * @return UsageForObject[] + */ + public function detailsForEventInMonth($eventId, $month) + { + $res = $this->client->get('/reports/usage/month/' . $month->serialize() . '/event/' . $eventId); + $json = \GuzzleHttp\json_decode($res->getBody()); + $mapper = SeatsioJsonMapper::create(); + return $mapper->mapArray($json, array(), UsageForObject::class); + } + +} diff --git a/src/SeatsioClient.php b/src/SeatsioClient.php index eb1cb30..74c5791 100644 --- a/src/SeatsioClient.php +++ b/src/SeatsioClient.php @@ -7,10 +7,11 @@ use Psr\Http\Message\ResponseInterface; use Seatsio\Accounts\Accounts; use Seatsio\Charts\Charts; -use Seatsio\Reports\EventReports; -use Seatsio\Reports\ChartReports; use Seatsio\Events\Events; use Seatsio\HoldTokens\HoldTokens; +use Seatsio\Reports\Charts\ChartReports; +use Seatsio\Reports\Events\EventReports; +use Seatsio\Reports\usage\UsageReports; use Seatsio\Subaccounts\Subaccounts; class SeatsioClient @@ -67,6 +68,7 @@ public function __construct($secretKey, $baseUrl = 'https://api.seatsio.net/') $this->events = new Events($client); $this->eventReports = new EventReports($client); $this->chartReports = new ChartReports($client); + $this->usageReports = new UsageReports($client); $this->accounts = new Accounts($client); $this->subaccounts = new Subaccounts($client); $this->holdTokens = new HoldTokens($client); @@ -89,4 +91,4 @@ function (ResponseInterface $response) use ($request, $handler) { }; } -} \ No newline at end of file +} diff --git a/tests/ChartReports/ChartReportTest.php b/tests/Reports/ChartReportTest.php similarity index 98% rename from tests/ChartReports/ChartReportTest.php rename to tests/Reports/ChartReportTest.php index b9e8ad5..ce68801 100644 --- a/tests/ChartReports/ChartReportTest.php +++ b/tests/Reports/ChartReportTest.php @@ -1,6 +1,6 @@ seatsioClient->usageReports->summaryForAllMonths(); + } + + public function testDetailsForMonth() + { + $report = $this->seatsioClient->usageReports->detailsForMonth(new Month(2019, 5)); + } + + public function testDetailsForEventInMonth() + { + $chart = $this->seatsioClient->charts->create(); + $event = $this->seatsioClient->events->create($chart->key); + $report = $this->seatsioClient->usageReports->detailsForEventInMonth($event->id, new Month(2019, 5)); + } + +} From e938785460ae88c1641b30f2d87f1a223e1fa20b Mon Sep 17 00:00:00 2001 From: mroloux Date: Wed, 5 Jun 2019 11:16:40 +0200 Subject: [PATCH 2/3] Fixed errors --- src/Events/BestAvailableObjects.php | 4 ++-- src/Events/ChangeObjectStatusResult.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Events/BestAvailableObjects.php b/src/Events/BestAvailableObjects.php index b0730f1..aa39e58 100644 --- a/src/Events/BestAvailableObjects.php +++ b/src/Events/BestAvailableObjects.php @@ -9,7 +9,7 @@ class BestAvailableObjects */ public $objects; /** - * @var array[\Seatsio\Reports\EventReportItem] + * @var array[\Seatsio\Reports\Events\EventReportItem] */ public $objectDetails; /** @@ -17,4 +17,4 @@ class BestAvailableObjects */ public $nextToEachOther; -} \ No newline at end of file +} diff --git a/src/Events/ChangeObjectStatusResult.php b/src/Events/ChangeObjectStatusResult.php index 3b62ada..da92915 100644 --- a/src/Events/ChangeObjectStatusResult.php +++ b/src/Events/ChangeObjectStatusResult.php @@ -5,8 +5,8 @@ class ChangeObjectStatusResult { /** - * @var array[\Seatsio\Reports\EventReportItem] + * @var array[\Seatsio\Reports\Events\EventReportItem] */ var $objects; -} \ No newline at end of file +} From b4bf6f47d692acf892b3d1336f0334fc44582168 Mon Sep 17 00:00:00 2001 From: mroloux Date: Wed, 5 Jun 2019 11:28:11 +0200 Subject: [PATCH 3/3] Fixed typo --- src/SeatsioClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SeatsioClient.php b/src/SeatsioClient.php index 74c5791..513d93e 100644 --- a/src/SeatsioClient.php +++ b/src/SeatsioClient.php @@ -11,7 +11,7 @@ use Seatsio\HoldTokens\HoldTokens; use Seatsio\Reports\Charts\ChartReports; use Seatsio\Reports\Events\EventReports; -use Seatsio\Reports\usage\UsageReports; +use Seatsio\Reports\Usage\UsageReports; use Seatsio\Subaccounts\Subaccounts; class SeatsioClient