diff --git a/src/BaseClientInterface.php b/src/BaseClientInterface.php new file mode 100644 index 0000000..62f320c --- /dev/null +++ b/src/BaseClientInterface.php @@ -0,0 +1,16 @@ +uri = Uri::fromParts([ 'scheme' => 'https', @@ -32,9 +34,16 @@ public function __construct($username, $password) 'query' => sprintf('s_login=%s&s_pw=%s', $username, $password) ]); - $this->httpClient = new HTTPClient(); + if (null === $httpClient) { + $httpClient = new HTTPClient(); + } + + $this->httpClient = $httpClient; } + /** + * @inheritdoc + */ public function call($method, array $properties = []): ResponseInterface { $query = sprintf( @@ -44,7 +53,11 @@ public function call($method, array $properties = []): ResponseInterface http_build_query($properties) ); - $body = $this->doCall(new Request('get', $this->uri->withQuery($query))); + try { + $body = $this->doCall(new Request('get', $this->uri->withQuery($query))); + } catch (GuzzleException $guzzleException) { + throw new ApiException('An error occured during API call', 0, $guzzleException); + } $this->validateResponse($body); @@ -59,6 +72,7 @@ public function call($method, array $properties = []): ResponseInterface /** * @param RequestInterface $request + * @throws GuzzleException * @return string */ protected function doCall(RequestInterface $request): string diff --git a/src/ClientFacade.php b/src/ClientFacade.php index a43adb0..ccdc6f3 100644 --- a/src/ClientFacade.php +++ b/src/ClientFacade.php @@ -6,11 +6,10 @@ use HadesArchitect\UnitedDomains\Exception\InvalidParameterException; use HadesArchitect\UnitedDomains\Exception\ServerException; -class ClientFacade extends TraceableClient +class ClientFacade extends TraceableClient implements ClientInterface { /** - * @param string $domain - * @return bool + * @inheritdoc */ public function isDomainFree(string $domain): bool { @@ -26,9 +25,7 @@ public function isDomainFree(string $domain): bool } /** - * @param string $zone - * @param string $soamname - * @param string $soarname + * @inheritdoc */ public function CreateDNSZone(string $zone, string $soamname = '', string $soarname = ''): void { @@ -43,7 +40,7 @@ public function CreateDNSZone(string $zone, string $soamname = '', string $soarn } /** - * @param string $zone + * @inheritdoc */ public function DeleteDNSZone(string $zone): void { @@ -51,12 +48,7 @@ public function DeleteDNSZone(string $zone): void } /** - * @param string $zone - * @param string $name - * @param string $type - * @param string $data - * @param int $ttl - * @param string $class + * @inheritdoc */ public function addRecord(string $zone, string $name, string $type, string $data, int $ttl = 3600, string $class = 'IN') { @@ -70,9 +62,7 @@ public function addRecord(string $zone, string $name, string $type, string $data } /** - * @param string $zone - * @param array $records - * @throws InvalidParameterException + * @inheritdoc */ public function addRecords(string $zone, array $records) { @@ -100,11 +90,7 @@ public function addRecords(string $zone, array $records) } /** - * @param string $zone - * @param string $name - * @param string $type - * @param string|bool $data - * @param string $class + * @inheritdoc */ public function deleteRecord(string $zone, string $name, string $type, $data = false, string $class = 'IN'): void { @@ -134,8 +120,7 @@ function ($record) use ($name) { } /** - * @param string $zone - * @return array + * @inheritdoc */ public function getRecords(string $zone) { @@ -143,10 +128,7 @@ public function getRecords(string $zone) } /** - * @param string $zone - * @param string $type - * - * @return array + * @inheritdoc */ public function findRecordsByType(string $zone, string $type) { @@ -171,11 +153,11 @@ function ($record) { preg_match_all("/(\S+)\s(\d+)\s(\S+)\s(\S+)\s(.*)/", $record, $matches); return [ - 'name' => $matches[1][0], - 'ttl' => (int)$matches[2][0], + 'name' => $matches[1][0], + 'ttl' => (int)$matches[2][0], 'class' => $matches[3][0], - 'type' => $matches[4][0], - 'data' => $matches[5][0] + 'type' => $matches[4][0], + 'data' => $matches[5][0] ]; }, $this->call('QueryDNSZoneRRList', ['dnszone' => $zone])->getProperty('rr') diff --git a/src/ClientInterface.php b/src/ClientInterface.php new file mode 100644 index 0000000..7a6c238 --- /dev/null +++ b/src/ClientInterface.php @@ -0,0 +1,66 @@ +