Skip to content

Commit

Permalink
Merge pull request #17 from seatsio/add-chart-reports-by-category
Browse files Browse the repository at this point in the history
Add chart reports by category
  • Loading branch information
bverbeken authored Mar 27, 2019
2 parents b05d1a9 + 0dba60b commit bbeb150
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
34 changes: 25 additions & 9 deletions src/Reports/ChartReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,45 @@ 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);
return $this->getChartReport('byLabel', $chartKey);
}

private static function reportUrl($reportType, $eventKey)
/**
* @param $chartKey string
* @return array
*/
public function byCategoryKey($chartKey)
{
return \GuzzleHttp\uri_template('/reports/charts/{key}/{reportType}', array("key" => $eventKey, "reportType" => $reportType));
return $this->getChartReport('byCategoryKey', $chartKey);
}

/**
* @param $json mixed
* @param $chartKey string
* @return array
*/
public function byCategoryLabel($chartKey)
{
return $this->getChartReport('byCategoryLabel', $chartKey);
}

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

private function getChartReport($reportType, $chartKey)
{
$res = $this->client->get(self::reportUrl($reportType, $chartKey));
$json = \GuzzleHttp\json_decode($res->getBody());
return $this->mapMultiValuedReport($json);
}

private static function mapMultiValuedReport($json)
{
$mapper = SeatsioJsonMapper::create();
Expand All @@ -49,5 +66,4 @@ private static function mapMultiValuedReport($json)
return $result;
}


}
21 changes: 20 additions & 1 deletion tests/ChartReports/ChartReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,23 @@ public function testByLabel()
self::assertCount(1, $report["A-2"]);
}

}

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

$report = $this->seatsioClient->chartReports->byCategoryKey($chartKey);
self::assertCount(17, $report["9"]);
self::assertCount(17, $report["10"]);
}

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

$report = $this->seatsioClient->chartReports->byCategoryLabel($chartKey);
self::assertCount(17, $report["Cat1"]);
self::assertCount(17, $report["Cat2"]);
}

}

0 comments on commit bbeb150

Please sign in to comment.