Create Client.php

This commit is contained in:
Tony Roy 2021-03-10 17:40:13 -04:00 committed by GitHub
commit 836e18a284
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

93
src/Client.php Normal file
View file

@ -0,0 +1,93 @@
<?php
namespace wickedsoft\NetBox;
use wickedsoft\NetBox\HttpClient\HttpClient;
class Client
{
/** @var array */
protected $classes = [
'attachments' => 'Attachments',
'creditinvoices' => 'CreditInvoices',
'creditors' => 'Creditors',
'debtors' => 'Debtors',
'domains' => 'Domains',
'groups' => 'Groups',
'handles' => 'Handles',
'hosting' => 'Hosting',
'invoices' => 'Invoices',
'orders' => 'Orders',
'pricequotes' => 'PriceQuotes',
'products' => 'Products',
'services' => 'Services',
'ssl' => 'Ssl',
'tickets' => 'Tickets',
'vps' => 'Vps',
];
/** @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;
}
}