2021-03-10 18:40:36 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace wickedsoft\NetBox\Api;
|
|
|
|
|
|
|
|
|
|
use wickedsoft\NetBox\Client;
|
|
|
|
|
|
|
|
|
|
abstract class AbstractApi implements ApiInterface
|
|
|
|
|
{
|
|
|
|
|
/** @var \wickedsoft\NetBox\Client */
|
|
|
|
|
public $client;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AbstractApi constructor.
|
|
|
|
|
* @param \wickedsoft\NetBox\Client $client
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(Client $client)
|
|
|
|
|
{
|
|
|
|
|
$this->client = $client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $parameters
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
|
|
|
*/
|
2021-03-11 23:01:10 -04:00
|
|
|
protected function get($path, $parameters)
|
2021-03-10 18:40:36 -04:00
|
|
|
{
|
2021-03-11 23:01:10 -04:00
|
|
|
return $this->client->getHttpClient()->get($path, array_merge([
|
2021-03-10 18:40:36 -04:00
|
|
|
'api_key' => $this->client->getHttpClient()->getOptions()['key']
|
|
|
|
|
], $parameters));
|
|
|
|
|
}
|
2021-03-11 23:01:10 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $parameters
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
|
|
|
*/
|
|
|
|
|
protected function post($path, $parameters)
|
|
|
|
|
{
|
|
|
|
|
return $this->client->getHttpClient()->post($path, array_merge([
|
|
|
|
|
'api_key' => $this->client->getHttpClient()->getOptions()['key']
|
|
|
|
|
], $parameters));
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 10:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @param array $parameters
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
|
|
|
*/
|
2021-03-11 23:01:10 -04:00
|
|
|
protected function put($path, $parameters)
|
2021-03-11 10:10:18 -04:00
|
|
|
{
|
2021-03-11 23:01:10 -04:00
|
|
|
return $this->client->getHttpClient()->put($path, array_merge([
|
2021-03-11 10:10:18 -04:00
|
|
|
'api_key' => $this->client->getHttpClient()->getOptions()['key']
|
|
|
|
|
], $parameters));
|
|
|
|
|
}
|
2021-03-11 23:01:10 -04:00
|
|
|
|
2021-03-11 10:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @param array $parameters
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
|
|
|
*/
|
2021-03-11 23:01:10 -04:00
|
|
|
protected function delete($path, $parameters)
|
2021-03-11 10:10:18 -04:00
|
|
|
{
|
2021-03-11 23:01:10 -04:00
|
|
|
return $this->client->getHttpClient()->delete($path, array_merge([
|
2021-03-11 10:10:18 -04:00
|
|
|
'api_key' => $this->client->getHttpClient()->getOptions()['key']
|
|
|
|
|
], $parameters));
|
|
|
|
|
}
|
2021-03-10 18:40:36 -04:00
|
|
|
}
|