2021-03-10 17:40:13 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace wickedsoft\NetBox;
|
|
|
|
|
|
|
|
|
|
use wickedsoft\NetBox\HttpClient\HttpClient;
|
|
|
|
|
|
|
|
|
|
class Client
|
|
|
|
|
{
|
|
|
|
|
/** @var array */
|
|
|
|
|
protected $classes = [
|
2021-03-11 21:18:06 -04:00
|
|
|
'ip' => 'Ip',
|
|
|
|
|
/*'providers' => 'Providers',
|
2021-03-10 18:20:45 -04:00
|
|
|
'circuits' => 'Circuits',
|
|
|
|
|
'sites' => 'Sites',
|
|
|
|
|
'racks' => 'Racks',
|
|
|
|
|
'devices' => 'Devices',
|
|
|
|
|
'prefixes' => 'Prefixes',
|
|
|
|
|
'cables' => 'Cables',
|
|
|
|
|
'interfaces' => 'Interfaces',
|
|
|
|
|
'rirs' => 'Rirs',
|
|
|
|
|
'vlans' => 'Vlans',
|
|
|
|
|
'vrfs' => 'Vrfs',
|
|
|
|
|
'secrets' => 'Secrets',
|
|
|
|
|
'tenants' => 'Tenants',
|
|
|
|
|
'users' => 'Users',
|
2021-03-11 21:18:06 -04:00
|
|
|
'clusters' => 'Clusters',*/
|
2021-03-10 18:20:45 -04:00
|
|
|
|
2021-03-10 17:40:13 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** @var \wickedsoft\NetBox\HttpClient */
|
|
|
|
|
protected $httpClient;
|
|
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
|
protected $options = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $method
|
|
|
|
|
* @param $args
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function __call($method, $args)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->api($method);
|
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
|
throw new \BadMethodCallException(sprintf('Undefined method called:"%s"', $method));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $name
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function api($name)
|
|
|
|
|
{
|
|
|
|
|
if (!isset($this->classes[$name])) {
|
|
|
|
|
throw new \InvalidArgumentException(sprintf('Undefined method called:"%s"', $name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$class = '\\wickedsoft\\NetBox\\Api\\' . $this->classes[$name];
|
|
|
|
|
|
|
|
|
|
return new $class($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return HttpClient
|
|
|
|
|
*/
|
|
|
|
|
public function getHttpClient()
|
|
|
|
|
{
|
|
|
|
|
if (!isset($this->httpClient)) {
|
|
|
|
|
$this->httpClient = new HttpClient();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->httpClient->setOptions($this->getOptions());
|
|
|
|
|
|
|
|
|
|
return $this->httpClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getOptions()
|
|
|
|
|
{
|
|
|
|
|
return $this->options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $options
|
|
|
|
|
*/
|
|
|
|
|
public function setOptions($options)
|
|
|
|
|
{
|
|
|
|
|
$this->options = $options;
|
|
|
|
|
}
|
|
|
|
|
}
|