Skip to content

Commit

Permalink
Exposed usage report cutoff date (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Oct 13, 2023
1 parent 58b8c10 commit 40946ad
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ jobs:
timezone: Europe/Brussels

- run: vendor/bin/paratest
env:
DEMO_COMPANY_SECRET_KEY: ${{ secrets.DEMO_COMPANY_SECRET_KEY }}
9 changes: 9 additions & 0 deletions src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ class UsageForObjectV1
* @var int
*/
public $numFirstBookingsOrSelections;

public function __construct(string $object = null, int $numFirstBookings = null, \DateTime $firstBookingDate = null, int $numFirstSelections = null, int $numFirstBookingsOrSelections = null)
{
$this->object = $object;
$this->numFirstBookings = $numFirstBookings;
$this->firstBookingDate = $firstBookingDate;
$this->numFirstSelections = $numFirstSelections;
$this->numFirstBookingsOrSelections = $numFirstBookingsOrSelections;
}
}
7 changes: 7 additions & 0 deletions src/Reports/Usage/DetailsForEventInMonth/UsageForObjectV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ class UsageForObjectV2
* @var array
*/
public $usageByReason;

public function __construct(string $object = null, int $numUsedObjects = null, array $usageByReason = null)
{
$this->object = $object;
$this->numUsedObjects = $numUsedObjects;
$this->usageByReason = $usageByReason;
}
}
6 changes: 6 additions & 0 deletions src/Reports/Usage/DetailsForMonth/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ class Chart
* @var string
*/
public $key;

public function __construct(string $name = null, string $key = null)
{
$this->name = $name;
$this->key = $key;
}
}
12 changes: 12 additions & 0 deletions src/Reports/Usage/DetailsForMonth/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ class Event
* @var string
*/
public $key;

/**
* @var boolean
*/
public $deleted;

public function __construct(int $id = null, string $key = null, bool $deleted = null)
{
$this->id = $id;
$this->key = $key;
$this->deleted = $deleted;
}
}
6 changes: 6 additions & 0 deletions src/Reports/Usage/DetailsForMonth/UsageByChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ class UsageByChart
* @var UsageByEvent[]
*/
public $usageByEvent;

public function __construct(Chart $chart = null, array $usageByEvent = null)
{
$this->chart = $chart;
$this->usageByEvent = $usageByEvent;
}
}
10 changes: 10 additions & 0 deletions src/Reports/Usage/DetailsForMonth/UsageByEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ class UsageByEvent
* @var int
*/
public $numUsedObjects;

/**
* @param Event $event
* @param int $numUsedObjects
*/
public function __construct(Event $event = null, int $numUsedObjects = null)
{
$this->event = $event;
$this->numUsedObjects = $numUsedObjects;
}
}
6 changes: 6 additions & 0 deletions src/Reports/Usage/DetailsForMonth/UsageDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ class UsageDetails
* @var UsageByChart[]
*/
public $usageByChart;

public function __construct(int $workspace = null, array $usageByChart = null)
{
$this->workspace = $workspace;
$this->usageByChart = $usageByChart;
}
}
1 change: 0 additions & 1 deletion src/Reports/Usage/SummaryForMonths/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function serialize(): string
{
return $this->year . '-' . str_pad($this->month, 2, '0', STR_PAD_LEFT);
}

}
29 changes: 29 additions & 0 deletions src/Reports/Usage/SummaryForMonths/UsageSummaryForAllMonths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php


namespace Seatsio\Reports\Usage\SummaryForMonths;


class UsageSummaryForAllMonths
{

/**
* @var \DateTime
*/
public $usageCutoffDate;

/**
* @var UsageSummaryForMonth[]
*/
public $usage;

/**
* @param \DateTime $usageCutoffDate
* @param UsageSummaryForMonth[] $usage
*/
public function __construct(\DateTime $usageCutoffDate = null, array $usage = null)
{
$this->usageCutoffDate = $usageCutoffDate;
$this->usage = $usage;
}
}
9 changes: 9 additions & 0 deletions src/Reports/Usage/SummaryForMonths/UsageSummaryForMonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ class UsageSummaryForMonth
*/
public $numUsedObjects;

/**
* @param Month $month
* @param int $numUsedObjects
*/
public function __construct(Month $month = null, int $numUsedObjects = null)
{
$this->month = $month;
$this->numUsedObjects = $numUsedObjects;
}
}
10 changes: 4 additions & 6 deletions src/Reports/Usage/UsageReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Seatsio\Reports\Usage\DetailsForEventInMonth\UsageForObjectV2;
use Seatsio\Reports\Usage\DetailsForMonth\UsageDetails;
use Seatsio\Reports\Usage\SummaryForMonths\Month;
use Seatsio\Reports\Usage\SummaryForMonths\UsageSummaryForAllMonths;
use Seatsio\Reports\Usage\SummaryForMonths\UsageSummaryForMonth;
use Seatsio\SeatsioJsonMapper;

Expand All @@ -24,15 +25,12 @@ public function __construct(Client $client)
$this->client = $client;
}

/**
* @return UsageSummaryForMonth[]
*/
public function summaryForAllMonths(): array
public function summaryForAllMonths(): UsageSummaryForAllMonths
{
$res = $this->client->get('/reports/usage');
$res = $this->client->get('/reports/usage?version=2');
$json = Utils::jsonDecode($res->getBody());
$mapper = SeatsioJsonMapper::create();
return $mapper->mapArray($json, array(), UsageSummaryForMonth::class);
return $mapper->map($json, new UsageSummaryForAllMonths());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Seatsio\Reports;
namespace Reports\Charts;

use Seatsio\SeatsioClient;
use Seatsio\SeatsioClientTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Seatsio\Reports;
namespace Reports\Charts;

use Seatsio\Common\IDs;
use Seatsio\SeatsioClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Seatsio\Reports;
namespace Reports\Events;

use Seatsio\Events\EventObjectInfo;
use Seatsio\Events\ObjectProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Seatsio\Reports;
namespace Reports\Events;

use Seatsio\Events\Channel;
use Seatsio\Events\CreateEventParams;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Seatsio\Reports;
namespace Reports\Events;

use Seatsio\Common\IDs;
use Seatsio\Events\Channel;
Expand Down
56 changes: 56 additions & 0 deletions tests/Reports/Usage/UsageReportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Reports\Usage;

use Seatsio\Reports\Usage\DetailsForEventInMonth\UsageForObjectV1;
use Seatsio\Reports\Usage\DetailsForMonth\Event;
use Seatsio\Reports\Usage\DetailsForMonth\UsageByEvent;
use Seatsio\Reports\Usage\SummaryForMonths\Month;
use Seatsio\SeatsioClientTest;

class UsageReportTest extends SeatsioClientTest
{
public function testUsageReportForAllMonths()
{
$this->skipTestIfDemoCompanySecretKeyNotSet();
$client = $this->createSeatsioClient($this->demoCompanySecretKey());

$report = $client->usageReports->summaryForAllMonths();

self::assertNotNull($report->usageCutoffDate);
self::assertGreaterThan(0, count($report->usage));
self::assertEquals(new Month(2014, 2), $report->usage[0]->month);
}

public function testUsageReportForMonth()
{
$this->skipTestIfDemoCompanySecretKeyNotSet();
$client = $this->createSeatsioClient($this->demoCompanySecretKey());

$report = $client->usageReports->detailsForMonth(new Month(2021, 11));

self::assertGreaterThan(0, count($report));
self::assertGreaterThan(0, count($report[0]->usageByChart));
$expected = new UsageByEvent(new Event(580293, "largeStadiumEvent", false), 143);
self::assertEquals([$expected], $report[0]->usageByChart[0]->usageByEvent);
}

public function testUsageReportForEventInMonth()
{
$this->skipTestIfDemoCompanySecretKeyNotSet();
$client = $this->createSeatsioClient($this->demoCompanySecretKey());

$report = $client->usageReports->detailsForEventInMonth(580293, new Month(2021, 11));

self::assertGreaterThan(0, count($report));
$expected = new UsageForObjectV1('102-9-14', 0, null, 1, 1);
self::assertEquals($expected, $report[0]);
}

private function skipTestIfDemoCompanySecretKeyNotSet(): void
{
if (!$this->isDemoCompanySecretKeySet()) {
$this->markTestSkipped("DEMO_COMPANY_SECRET_KEY environment variable not set");
}
}
}
10 changes: 10 additions & 0 deletions tests/SeatsioClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,14 @@ protected function waitForStatusChanges(Event $event, $numStatusChanges)
}
}
}

protected function demoCompanySecretKey()
{
return getenv("DEMO_COMPANY_SECRET_KEY");
}

protected function isDemoCompanySecretKeySet()
{
return getenv("DEMO_COMPANY_SECRET_KEY") !== false;
}
}

0 comments on commit 40946ad

Please sign in to comment.