Added support to use timePrecision in POSTs (inserts) too

This commit is contained in:
Harm van Tilborg 2013-12-02 12:09:33 +01:00
parent 6b05c2166c
commit e95ca5c715
4 changed files with 13 additions and 13 deletions

View File

@ -64,7 +64,7 @@ class BaseHTTP
$c->children[] = $this; $c->children[] = $this;
} }
protected function getCurl($url, Array $args = []) protected function getCurl($url, array $args = [])
{ {
$args = array_merge($args, ['u' => $this->user, 'p' => $this->pass]); $args = array_merge($args, ['u' => $this->user, 'p' => $this->pass]);
$url = "http://{$this->host}:{$this->port}/{$this->base}{$url}"; $url = "http://{$this->host}:{$this->port}/{$this->base}{$url}";
@ -77,7 +77,7 @@ class BaseHTTP
protected function execCurl($ch, $json = false) protected function execCurl($ch, $json = false)
{ {
$response = curl_exec ($ch); $response = curl_exec ($ch);
$status = (string)curl_getinfo($ch, CURLINFO_HTTP_CODE); $status = (string)curl_getinfo($ch, CURLINFO_HTTP_CODE);
//$type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); //$type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch); curl_close($ch);
if ($status[0] != 2) { if ($status[0] != 2) {
@ -115,19 +115,19 @@ class BaseHTTP
} }
return $this; return $this;
} }
throw new \InvalidArgumentException("Expecting m,s or u"); throw new \InvalidArgumentException("Expecting s, m or u as time precision");
} }
protected function get($url, Array $args = []) protected function get($url, array $args = [])
{ {
$ch = $this->getCurl($url, $args); $ch = $this->getCurl($url, $args);
return $this->execCurl($ch, true); return $this->execCurl($ch, true);
} }
protected function post($url, Array $body) protected function post($url, array $body, array $args = [])
{ {
$ch = $this->getCurl($url); $ch = $this->getCurl($url, $args);
curl_setopt_array($ch, [ curl_setopt_array($ch, [
CURLOPT_POST => 1, CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($body), CURLOPT_POSTFIELDS => json_encode($body),

View File

@ -41,7 +41,7 @@ use ArrayIterator;
class Cursor extends ArrayIterator class Cursor extends ArrayIterator
{ {
public function __construct(Array $resultset) public function __construct(array $resultset)
{ {
$rows = []; $rows = [];
foreach ($resultset as $set) { foreach ($resultset as $set) {

View File

@ -60,7 +60,7 @@ class DB extends BaseHTTP
return $this->client->deleteDatabase($this->name); return $this->client->deleteDatabase($this->name);
} }
public function insert($name, Array $data) public function insert($name, array $data)
{ {
$points = []; $points = [];
$first = current($data); $first = current($data);
@ -72,7 +72,7 @@ class DB extends BaseHTTP
$points[] = array_values($value); $points[] = array_values($value);
} }
$body = compact('name', 'columns', 'points'); $body = compact('name', 'columns', 'points');
return $this->post('series', [$body]); return $this->post('series', [$body], ['time_precision' => $this->timePrecision]);
} }
public function first($sql) public function first($sql)

View File

@ -63,8 +63,8 @@ class DBTest extends \phpunit_framework_testcase
$this->assertEquals('m', $db->getTimePrecision()); $this->assertEquals('m', $db->getTimePrecision());
} }
/** /**
* @expectedException InvalidArgumentException * @expectedException InvalidArgumentException
*/ */
public function testInvalidTimePrecision() public function testInvalidTimePrecision()
{ {
@ -118,5 +118,5 @@ class DBTest extends \phpunit_framework_testcase
} }
$db->drop(); $db->drop();
} }
} }