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}";
@ -77,7 +77,7 @@ class BaseHTTP
protected function execCurl($ch, $json = false)
{
$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);
curl_close($ch);
if ($status[0] != 2) {
@ -115,19 +115,19 @@ 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)

View File

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