ResultSet - implementing getPoints

This commit is contained in:
Daniel Martinez
2015-06-17 16:03:21 +02:00
parent 0986f43bdd
commit d6dc5d5062
3 changed files with 107 additions and 10 deletions

View File

@@ -5,7 +5,11 @@
namespace Leaseweb\InfluxDB;
/**
* Class ResultSet
*
* @package Leaseweb\InfluxDB
*/
class ResultSet
{
/**
@@ -13,13 +17,32 @@ class ResultSet
*/
protected $raw = '';
protected $parsedResults = array();
/**
* @param $raw
*
* @param bool $throwExceptions
* @throws \InvalidArgumentException
*/
public function __construct($raw, $throwExceptions = true)
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();
}
}

View File

@@ -1,12 +1,27 @@
<?php
namespace Leaseweb\InfluxDB\Test;
use Leaseweb\InfluxDB\ResultSet;
class ResultSetTest extends \PHPUnit_Framework_TestCase
{
public function testResultSetFromRaw()
/** @var ResultSet $resultSet*/
protected $resultSet;
public function setUp()
{
$resultJsonExample = file_get_contents(dirname(__FILE__) . '/result.example.json');
$this->resultSet = new ResultSet($resultJsonExample);
}
public function testGetPointsFromMeasurementName()
{
$measurementName = 'cpu_load_short';
$points = $this->resultSet->getPoints($measurementName);
$this->assertTrue(
false
is_array($points)
);
}
}

View File

@@ -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
]
]
}
]
}
]
}