Add Support for PATCH method

For now implementation is done in Prefixes only, more to come.
This commit is contained in:
Christian Bönning 2022-06-01 14:46:47 +02:00
commit 9a5bb016bc
3 changed files with 41 additions and 0 deletions

View file

@ -52,6 +52,17 @@ abstract class AbstractApi implements ApiInterface
return $this->client->getHttpClient()->put($path, $parameters);
}
/**
* @param $path
* @param array $parameters
* @return array
* @throws GuzzleException
*/
protected function patch($path, array $parameters): array
{
return $this->client->getHttpClient()->patch($path, $parameters);
}
/**
* @param $path
* @param array $parameters

View file

@ -39,6 +39,17 @@ class Prefixes extends AbstractApi
return $this->put("/ipam/prefixes/" . $id . "/", $params);
}
/**
* @param int $id
* @param array $params
* @return array
* @throws GuzzleException
*/
public function update(int $id, array $params = []): array
{
return $this->patch("/ipam/prefixes/" . $id . "/", $params);
}
/**
* @param array $params
* @return mixed

View file

@ -107,6 +107,25 @@ class HttpClient implements HttpClientInterface
return json_decode($response->getBody()->getContents(), true);
}
/**
* @param string $path
* @param array $body
* @return array
* @throws GuzzleException
*/
public function patch(string $path = "", array $body = []): array
{
$response = $this->getClient()->request(
'PATCH',
getenv('NETBOX_API') . $path,
[
'json' => $body
]
);
return json_decode($response->getBody()->getContents(), true);
}
/**
* @param string $path
* @param array $body