Files
librenms-librenms/src/Client.php
Walter Dal Mut 63b8bb4b89 Fixes minor violations
* Removed unsed `use` statemment
 * Moved helper http url composer to `GuzzleAdapter` (responsibility)
 * Removed unused `clearTimePrecision` method
 * Updated composer
2015-06-12 07:57:26 +02:00

73 lines
1.9 KiB
PHP

<?php
namespace InfluxDB;
use InfluxDb\Adapter\QueryableInterface;
/**
* Client to manage request at InfluxDB
*/
class Client
{
private $adapter;
public function __construct(Adapter\AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
public function getAdapter()
{
return $this->adapter;
}
public function mark($name, array $values = [])
{
$data = $name;
if (!is_array($name)) {
$data =[];
$data['points'][0]['measurement'] = $name;
$data['points'][0]['fields'] = $values;
}
return $this->getAdapter()->send($data);
}
public function query($query)
{
if (!($this->getAdapter() instanceOf QueryableInterface)) {
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
}
$return = $this->getAdapter()->query($query);
return $return;
}
public function getDatabases()
{
if (!($this->getAdapter() instanceOf QueryableInterface)) {
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
}
return $this->getAdapter()->query("show databases");
}
public function createDatabase($name)
{
if (!($this->getAdapter() instanceOf QueryableInterface)) {
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
}
return $this->getAdapter()->query("create database \"{$name}\"");
}
public function deleteDatabase($name)
{
if (!($this->getAdapter() instanceOf QueryableInterface)) {
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
}
return $this->getAdapter()->query("drop database \"{$name}\"");
}
}