Merge pull request #1 from hvt/timeprecision-post

Added support to use timePrecision in POSTs (inserts) too
This commit is contained in:
César D. Rodas 2014-02-12 13:42:03 -02:00
commit cb2d802d83
4 changed files with 13 additions and 13 deletions

View File

@ -64,7 +64,7 @@ class BaseHTTP
$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]);
$url = "http://{$this->host}:{$this->port}/{$this->base}{$url}";
@ -116,18 +116,18 @@ class BaseHTTP
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);
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, [
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($body),

View File

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

View File

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