64 lines
2.5 KiB
PHP
64 lines
2.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace DigiComp\HetznerDnsApi\Endpoint;
|
||
|
|
||
|
class CreatePrimaryServer extends \DigiComp\HetznerDnsApi\Runtime\Client\BaseEndpoint implements \DigiComp\HetznerDnsApi\Runtime\Client\Endpoint
|
||
|
{
|
||
|
/**
|
||
|
* Creates a new primary server.
|
||
|
*
|
||
|
* @param null|\DigiComp\HetznerDnsApi\Model\PrimaryServer $requestBody
|
||
|
*/
|
||
|
public function __construct(?\DigiComp\HetznerDnsApi\Model\PrimaryServer $requestBody = null)
|
||
|
{
|
||
|
$this->body = $requestBody;
|
||
|
}
|
||
|
use \DigiComp\HetznerDnsApi\Runtime\Client\EndpointTrait;
|
||
|
public function getMethod() : string
|
||
|
{
|
||
|
return 'POST';
|
||
|
}
|
||
|
public function getUri() : string
|
||
|
{
|
||
|
return '/primary_servers';
|
||
|
}
|
||
|
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null) : array
|
||
|
{
|
||
|
if ($this->body instanceof \DigiComp\HetznerDnsApi\Model\PrimaryServer) {
|
||
|
return array(array('Content-Type' => array('application/json')), $serializer->serialize($this->body, 'json'));
|
||
|
}
|
||
|
return array(array(), null);
|
||
|
}
|
||
|
public function getExtraHeaders() : array
|
||
|
{
|
||
|
return array('Accept' => array('application/json'));
|
||
|
}
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*
|
||
|
* @throws \DigiComp\HetznerDnsApi\Exception\CreatePrimaryServerUnauthorizedException
|
||
|
* @throws \DigiComp\HetznerDnsApi\Exception\CreatePrimaryServerNotAcceptableException
|
||
|
* @throws \DigiComp\HetznerDnsApi\Exception\CreatePrimaryServerUnprocessableEntityException
|
||
|
*
|
||
|
* @return null|\DigiComp\HetznerDnsApi\Model\PrimaryServersPostResponse201
|
||
|
*/
|
||
|
protected function transformResponseBody(string $body, int $status, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
|
||
|
{
|
||
|
if (is_null($contentType) === false && (201 === $status && mb_strpos($contentType, 'application/json') !== false)) {
|
||
|
return $serializer->deserialize($body, 'DigiComp\\HetznerDnsApi\\Model\\PrimaryServersPostResponse201', 'json');
|
||
|
}
|
||
|
if (401 === $status) {
|
||
|
throw new \DigiComp\HetznerDnsApi\Exception\CreatePrimaryServerUnauthorizedException();
|
||
|
}
|
||
|
if (406 === $status) {
|
||
|
throw new \DigiComp\HetznerDnsApi\Exception\CreatePrimaryServerNotAcceptableException();
|
||
|
}
|
||
|
if (422 === $status) {
|
||
|
throw new \DigiComp\HetznerDnsApi\Exception\CreatePrimaryServerUnprocessableEntityException();
|
||
|
}
|
||
|
}
|
||
|
public function getAuthenticationScopes() : array
|
||
|
{
|
||
|
return array('Auth-API-Token');
|
||
|
}
|
||
|
}
|