From ed1ca8220f49656c58634f40f08a6589c5f8d874 Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Tue, 26 Mar 2019 13:56:26 +0100 Subject: [PATCH 1/2] added byCategoryKey --- src/Reports/ChartReports.php | 7 +++++++ tests/ChartReports/ChartReportTest.php | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Reports/ChartReports.php b/src/Reports/ChartReports.php index 5abb5d8..0ab2659 100644 --- a/src/Reports/ChartReports.php +++ b/src/Reports/ChartReports.php @@ -35,6 +35,13 @@ private static function reportUrl($reportType, $eventKey) return \GuzzleHttp\uri_template('/reports/charts/{key}/{reportType}', array("key" => $eventKey, "reportType" => $reportType)); } + public function byCategoryKey($chartKey) + { + $res = $this->client->get(self::reportUrl('byCategoryKey', $chartKey)); + $json = \GuzzleHttp\json_decode($res->getBody()); + return $this->mapMultiValuedReport($json); + } + /** * @param $json mixed * @return array diff --git a/tests/ChartReports/ChartReportTest.php b/tests/ChartReports/ChartReportTest.php index 88ab35f..63c91e9 100644 --- a/tests/ChartReports/ChartReportTest.php +++ b/tests/ChartReports/ChartReportTest.php @@ -43,4 +43,14 @@ public function testByLabel() self::assertCount(1, $report["A-2"]); } -} \ No newline at end of file + + public function testByCategoryKey() + { + $chartKey = $this->createTestChart(); + + $report = $this->seatsioClient->chartReports->byCategoryKey($chartKey); + self::assertCount(17, $report["9"]); + self::assertCount(17, $report["10"]); + } + +} From 0dba60b8f28ab7bbc093b1f2815a0caa3d292dd8 Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Tue, 26 Mar 2019 14:01:29 +0100 Subject: [PATCH 2/2] added byCategoryKey and byCategoryLabel --- src/Reports/ChartReports.php | 33 ++++++++++++++++---------- tests/ChartReports/ChartReportTest.php | 9 +++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Reports/ChartReports.php b/src/Reports/ChartReports.php index 0ab2659..fa7030e 100644 --- a/src/Reports/ChartReports.php +++ b/src/Reports/ChartReports.php @@ -17,17 +17,31 @@ 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); + } + + /** + * @param $chartKey string + * @return array + */ + public function byCategoryKey($chartKey) + { + return $this->getChartReport('byCategoryKey', $chartKey); + } + + /** + * @param $chartKey string + * @return array + */ + public function byCategoryLabel($chartKey) + { + return $this->getChartReport('byCategoryLabel', $chartKey); } private static function reportUrl($reportType, $eventKey) @@ -35,17 +49,13 @@ private static function reportUrl($reportType, $eventKey) return \GuzzleHttp\uri_template('/reports/charts/{key}/{reportType}', array("key" => $eventKey, "reportType" => $reportType)); } - public function byCategoryKey($chartKey) + private function getChartReport($reportType, $chartKey) { - $res = $this->client->get(self::reportUrl('byCategoryKey', $chartKey)); + $res = $this->client->get(self::reportUrl($reportType, $chartKey)); $json = \GuzzleHttp\json_decode($res->getBody()); return $this->mapMultiValuedReport($json); } - /** - * @param $json mixed - * @return array - */ private static function mapMultiValuedReport($json) { $mapper = SeatsioJsonMapper::create(); @@ -56,5 +66,4 @@ private static function mapMultiValuedReport($json) return $result; } - } diff --git a/tests/ChartReports/ChartReportTest.php b/tests/ChartReports/ChartReportTest.php index 63c91e9..b9e8ad5 100644 --- a/tests/ChartReports/ChartReportTest.php +++ b/tests/ChartReports/ChartReportTest.php @@ -53,4 +53,13 @@ public function testByCategoryKey() 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"]); + } + }