diff --git a/src/Leaseweb/InfluxDB/ResultSet.php b/src/Leaseweb/InfluxDB/ResultSet.php index 9311314e97..7cde9dd164 100644 --- a/src/Leaseweb/InfluxDB/ResultSet.php +++ b/src/Leaseweb/InfluxDB/ResultSet.php @@ -5,7 +5,11 @@ namespace Leaseweb\InfluxDB; - +/** + * Class ResultSet + * + * @package Leaseweb\InfluxDB + */ class ResultSet { /** @@ -13,13 +17,32 @@ class ResultSet */ protected $raw = ''; - /** - * @param $raw - * - * @param bool $throwExceptions - */ - public function __construct($raw, $throwExceptions = true) - { + protected $parsedResults = array(); + /** + * @param $raw + * + * @throws \InvalidArgumentException + */ + public function __construct($raw) + { + $this->raw = $raw; + + $this->parsedResults = json_decode($raw, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new \InvalidArgumentException("Invalid JSON"); + } + } + + /** + * @param $metricName + * @param array $tags + * + * @return array $points + */ + public function getPoints($metricName = '', $tags = array()) + { + return array(); } } \ No newline at end of file diff --git a/tests/unit/ResultSetTest.php b/tests/unit/ResultSetTest.php index 2634a01ff7..1f6016fddc 100644 --- a/tests/unit/ResultSetTest.php +++ b/tests/unit/ResultSetTest.php @@ -1,12 +1,27 @@ resultSet = new ResultSet($resultJsonExample); + } + + public function testGetPointsFromMeasurementName() + { + $measurementName = 'cpu_load_short'; + + $points = $this->resultSet->getPoints($measurementName); + $this->assertTrue( - false + is_array($points) ); } } \ No newline at end of file diff --git a/tests/unit/result.example.json b/tests/unit/result.example.json new file mode 100644 index 0000000000..948d396621 --- /dev/null +++ b/tests/unit/result.example.json @@ -0,0 +1,59 @@ +{ + "results": [ + { + "series": [ + { + "measurement": "cpu_load_short", + "tags": { + "host": "server01", + "region": "us-west" + }, + "columns": [ + "time", + "value" + ], + "values": [ + [ + "2015-01-29T21:51:28.968422294Z", + 0.64 + ] + ] + }, + { + "measurement": "cpu_load_short", + "tags": { + "host": "server02", + "region": "us-west" + }, + "columns": [ + "time", + "value" + ], + "values": [ + [ + "2015-01-29T21:51:28.968422294Z", + 0.65 + ] + ] + }, + { + "measurement": "other_serie", + "tags": { + "host": "server01", + "region": "us-west" + }, + "columns": [ + "time", + "value" + ], + "values": [ + [ + "2015-01-29T21:51:28.968422294Z", + 0.66 + ] + ] + } + ] + } + ] +} \ No newline at end of file