refactor: connector abstraction

This commit is contained in:
Vincent
2024-08-23 13:38:16 +02:00
parent 700e531e22
commit 2f841f0127
5 changed files with 20 additions and 7 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Service\Connector;
abstract class AbstractConnector implements ConnectorInterface
{
protected array $authData;
public function authenticate(array $authData)
{
$this->authData = $authData;
}
}

View File

@@ -7,7 +7,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
interface ConnectorInterface interface ConnectorInterface
{ {
public function __construct(array $authData, HttpClientInterface $client); public function authenticate(array $authData);
public function orderDomain(Domain $domain, bool $dryRun): void; public function orderDomain(Domain $domain, bool $dryRun): void;

View File

@@ -12,11 +12,11 @@ use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
readonly class GandiConnector implements ConnectorInterface class GandiConnector extends AbstractConnector
{ {
private const BASE_URL = 'https://api.gandi.net/v5'; private const BASE_URL = 'https://api.gandi.net/v5';
public function __construct(private array $authData, private HttpClientInterface $client) public function __construct(private HttpClientInterface $client)
{ {
} }

View File

@@ -5,13 +5,13 @@ namespace App\Service\Connector;
use App\Entity\Domain; use App\Entity\Domain;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
readonly class NamecheapConnector implements ConnectorInterface class NamecheapConnector extends AbstractConnector
{ {
public const BASE_URL = 'https://api.namecheap.com/xml.response'; public const BASE_URL = 'https://api.namecheap.com/xml.response';
public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response'; public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response';
public function __construct(private array $authData, private HttpClientInterface $client) public function __construct(private HttpClientInterface $client)
{ {
} }

View File

@@ -8,7 +8,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
readonly class OvhConnector implements ConnectorInterface class OvhConnector extends AbstractConnector
{ {
public const REQUIRED_ROUTES = [ public const REQUIRED_ROUTES = [
[ [
@@ -33,7 +33,7 @@ readonly class OvhConnector implements ConnectorInterface
], ],
]; ];
public function __construct(private array $authData, private HttpClientInterface $client) public function __construct(private HttpClientInterface $client)
{ {
} }