Skip to content

Commit

Permalink
Merge pull request #11 from seatsio/add-chart-reports
Browse files Browse the repository at this point in the history
Add chart reports
  • Loading branch information
bverbeken authored Oct 4, 2018
2 parents 69d61ff + 32c6e84 commit 65f8a5b
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.idea
/vendor/*
/composer.phar
*.iml
*.iml
.DS_store

36 changes: 36 additions & 0 deletions src/Reports/ChartReportItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Seatsio\Reports;


class ChartReportItem
{
/**
* @var string
*/
public $label;
/**
* @var string
*/
public $categoryLabel;
/**
* @var string
*/
public $categoryKey;
/**
* @var string
*/
public $entrance;
/**
* @var string
*/
public $objectType;
/**
* @var string
*/
public $section;
/**
* @var int
*/
public $capacity;
}
53 changes: 53 additions & 0 deletions src/Reports/ChartReports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Seatsio\Reports;

use Seatsio\SeatsioJsonMapper;

class ChartReports
{

/**
* @var \GuzzleHttp\Client
*/
private $client;

public function __construct($client)
{
$this->client = $client;
}


/**
* @param $chartKey string
* @param $label string
* @return array
*/
public function byLabel($chartKey)
{
$res = $this->client->get(self::reportUrl('byLabel', $chartKey));
$json = \GuzzleHttp\json_decode($res->getBody());
return $this->mapMultiValuedReport($json);
}

private static function reportUrl($reportType, $eventKey)
{
return \GuzzleHttp\uri_template('/reports/charts/{key}/{reportType}', array("key" => $eventKey, "reportType" => $reportType));
}

/**
* @param $json mixed
* @return array
*/
private static function mapMultiValuedReport($json)
{
$mapper = SeatsioJsonMapper::create();
$result = [];
foreach ($json as $status => $reportItems) {
$result[$status] = $mapper->mapArray($reportItems, array(), ChartReportItem::class);
}
return $result;
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Seatsio\EventReports;
namespace Seatsio\Reports;


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

namespace Seatsio\EventReports;
namespace Seatsio\Reports;

use Seatsio\SeatsioJsonMapper;

Expand Down
9 changes: 8 additions & 1 deletion src/SeatsioClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use Psr\Http\Message\ResponseInterface;
use Seatsio\Accounts\Accounts;
use Seatsio\Charts\Charts;
use Seatsio\EventReports\EventReports;
use Seatsio\Reports\EventReports;
use Seatsio\Reports\ChartReports;
use Seatsio\Events\Events;
use Seatsio\HoldTokens\HoldTokens;
use Seatsio\Subaccounts\Subaccounts;
Expand All @@ -31,6 +32,11 @@ class SeatsioClient
*/
public $eventReports;

/**
* @var ChartReports
*/
public $chartReports;

/**
* @var Accounts
*/
Expand Down Expand Up @@ -60,6 +66,7 @@ public function __construct($secretKey, $baseUrl = 'https://api.seatsio.net/')
$this->charts = new Charts($client);
$this->events = new Events($client);
$this->eventReports = new EventReports($client);
$this->chartReports = new ChartReports($client);
$this->accounts = new Accounts($client);
$this->subaccounts = new Subaccounts($client);
$this->holdTokens = new HoldTokens($client);
Expand Down
45 changes: 45 additions & 0 deletions tests/ChartReports/ChartReportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Seatsio\ChartReports;

use Seatsio\SeatsioClientTest;

class ChartReportsTest extends SeatsioClientTest
{

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

$report = $this->seatsioClient->chartReports->byLabel($chartKey);

$reportItem = $report["A-1"][0];
self::assertEquals("A-1", $reportItem->label);
self::assertEquals("Cat1", $reportItem->categoryLabel);
self::assertEquals(9, $reportItem->categoryKey);
self::assertEquals("seat", $reportItem->objectType);
self::assertNull($reportItem->section);
self::assertNull($reportItem->entrance);
}

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

$report = $this->seatsioClient->chartReports->byLabel($chartKey);

$reportItem = $report["GA1"][0];
self::assertEquals(100, $reportItem->capacity);
self::assertEquals("generalAdmission", $reportItem->objectType);
}

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

$report = $this->seatsioClient->chartReports->byLabel($chartKey);
self::assertCount(1, $report["A-1"]);
self::assertCount(1, $report["A-2"]);
}

}

0 comments on commit 65f8a5b

Please sign in to comment.