From 30039a4356a0877818e369f1509812198fd6051f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Sat, 16 Oct 2021 12:01:05 +0200 Subject: [PATCH 01/13] Testing products API form Sylius version >=1.9, with new paths and upsert method --- src/Api/ProductsApi.php | 10 ++++++++-- src/Api/ProductsApiInterface.php | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Api/ProductsApi.php b/src/Api/ProductsApi.php index 8c07a32..a7782e9 100644 --- a/src/Api/ProductsApi.php +++ b/src/Api/ProductsApi.php @@ -12,6 +12,7 @@ namespace Diglin\Sylius\ApiClient\Api; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; @@ -21,8 +22,8 @@ class ProductsApi implements ProductsApiInterface { use ApiAwareTrait; - public const ENDPOINT_URI = 'api/v1/products/%s'; - public const ENDPOINTS_URI = 'api/v1/products'; + public const ENDPOINT_URI = 'api/v2/admin/products/%s'; + public const ENDPOINTS_URI = 'api/v2/admin/products'; public function __construct( ResourceClientInterface $resourceClient, @@ -50,6 +51,11 @@ public function create($code, array $data = []) return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } + public function upsert($code, array $data = []) + { + return $this->resourceClient->upsertResource(static::ENDPOINTS_URI, [$code], $data); + } + /** * {@inheritdoc} */ diff --git a/src/Api/ProductsApiInterface.php b/src/Api/ProductsApiInterface.php index 28db5da..e2f3c22 100644 --- a/src/Api/ProductsApiInterface.php +++ b/src/Api/ProductsApiInterface.php @@ -15,7 +15,8 @@ use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\UpsertableResourceInterface; -interface ProductsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface +interface ProductsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface, UpsertableResourceInterface { } From db28392cd7742de06d9e6499ae14b573cd26c42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Mon, 18 Oct 2021 16:28:11 +0200 Subject: [PATCH 02/13] Replaced the PATCH method by PUT method on resources upsert --- src/Client/ResourceClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client/ResourceClient.php b/src/Client/ResourceClient.php index b679de4..4de9fa6 100644 --- a/src/Client/ResourceClient.php +++ b/src/Client/ResourceClient.php @@ -138,7 +138,7 @@ public function upsertResource($uri, array $uriParameters = [], array $body = [] $uri = $this->uriGenerator->generate($uri, $uriParameters); $response = $this->httpClient->sendRequest( - 'PATCH', + 'PUT', $uri, ['Content-Type' => 'application/json'], json_encode($body) From 70d13a973b89eb98fff3109d47b9cf4497c6d4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Mon, 18 Oct 2021 21:34:29 +0200 Subject: [PATCH 03/13] Replaced the authentication URL --- src/Api/AuthenticationApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/AuthenticationApi.php b/src/Api/AuthenticationApi.php index 4534ead..c740089 100644 --- a/src/Api/AuthenticationApi.php +++ b/src/Api/AuthenticationApi.php @@ -23,7 +23,7 @@ */ class AuthenticationApi implements AuthenticationApiInterface { - public const TOKEN_URI = 'api/oauth/v2/token'; + public const TOKEN_URI = 'api/v2/admin/authentication-token'; /** @var HttpClient */ protected $httpClient; From 7808d6bf149b13c6a9bacdb978fa6f8f6927e94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Mon, 18 Oct 2021 22:19:33 +0200 Subject: [PATCH 04/13] Replaced the authentication methods Fixed upsert products API URL --- src/Api/AuthenticationApi.php | 5 +---- src/Api/ProductsApi.php | 2 +- src/Client/AuthenticatedHttpClient.php | 6 ++---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Api/AuthenticationApi.php b/src/Api/AuthenticationApi.php index c740089..8a3d14d 100644 --- a/src/Api/AuthenticationApi.php +++ b/src/Api/AuthenticationApi.php @@ -43,11 +43,8 @@ public function __construct(HttpClient $httpClient, UriGeneratorInterface $uriGe public function authenticateByPassword($clientId, $secret, $username, $password) { $requestBody = [ - 'grant_type' => 'password', - 'username' => $username, + 'email' => $username, 'password' => $password, - 'client_id' => $clientId, - 'client_secret' => $secret, ]; return $this->authenticate($requestBody); diff --git a/src/Api/ProductsApi.php b/src/Api/ProductsApi.php index a7782e9..d1f111f 100644 --- a/src/Api/ProductsApi.php +++ b/src/Api/ProductsApi.php @@ -53,7 +53,7 @@ public function create($code, array $data = []) public function upsert($code, array $data = []) { - return $this->resourceClient->upsertResource(static::ENDPOINTS_URI, [$code], $data); + return $this->resourceClient->upsertResource(static::ENDPOINT_URI, [$code], $data); } /** diff --git a/src/Client/AuthenticatedHttpClient.php b/src/Client/AuthenticatedHttpClient.php index 4be4d4e..ec55b71 100644 --- a/src/Client/AuthenticatedHttpClient.php +++ b/src/Client/AuthenticatedHttpClient.php @@ -67,8 +67,7 @@ public function sendRequest($httpMethod, $uri, array $headers = [], $body = null ); $this->authentication - ->setAccessToken($tokens['access_token']) - ->setRefreshToken($tokens['refresh_token']) + ->setAccessToken($tokens['token']) ; } @@ -83,8 +82,7 @@ public function sendRequest($httpMethod, $uri, array $headers = [], $body = null ); $this->authentication - ->setAccessToken($tokens['access_token']) - ->setRefreshToken($tokens['refresh_token']) + ->setAccessToken($tokens['token']) ; $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); From 65829b445e4c549a2ac6fef2d06552907dc2c2cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Tue, 26 Oct 2021 11:17:34 +0200 Subject: [PATCH 05/13] Refactored the authentication processes in order to handle Admin API and Shop API --- spec/Security/AuthenticationSpec.php | 2 - src/Api/Authentication/AdminApi.php | 48 +++++++ .../AuthenticationApiInterface.php | 22 +-- src/Api/Authentication/ShopApi.php | 48 +++++++ src/Api/AuthenticationApi.php | 85 ------------ src/Client/AuthenticatedHttpClient.php | 70 ++-------- src/Security/Authentication.php | 127 ++++-------------- 7 files changed, 135 insertions(+), 267 deletions(-) create mode 100644 src/Api/Authentication/AdminApi.php rename src/Api/{ => Authentication}/AuthenticationApiInterface.php (50%) create mode 100644 src/Api/Authentication/ShopApi.php delete mode 100644 src/Api/AuthenticationApi.php diff --git a/spec/Security/AuthenticationSpec.php b/spec/Security/AuthenticationSpec.php index 3e95081..bbc3d9a 100644 --- a/spec/Security/AuthenticationSpec.php +++ b/spec/Security/AuthenticationSpec.php @@ -11,8 +11,6 @@ public function it_is_initializable_from_a_password() $this->beConstructedThrough('fromPassword', ['client_id', 'secret', 'Julia', 'Julia_pwd']); $this->shouldHaveType('Diglin\Sylius\ApiClient\Security\Authentication'); - $this->getClientId()->shouldReturn('client_id'); - $this->getSecret()->shouldReturn('secret'); $this->getUsername()->shouldReturn('Julia'); $this->getPassword()->shouldReturn('Julia_pwd'); $this->getAccessToken()->shouldReturn(null); diff --git a/src/Api/Authentication/AdminApi.php b/src/Api/Authentication/AdminApi.php new file mode 100644 index 0000000..e253bac --- /dev/null +++ b/src/Api/Authentication/AdminApi.php @@ -0,0 +1,48 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient\Api\Authentication; + +use Diglin\Sylius\ApiClient\Client\HttpClient; +use Diglin\Sylius\ApiClient\Routing\UriGeneratorInterface; + +/** + * API implementation to manage the authentication. + * + * @author Alexandre Hocquard + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class AdminApi implements AuthenticationApiInterface +{ + public const TOKEN_URI = 'api/v2/admin/authentication-token'; + + public function __construct( + private HttpClient $httpClient, + private UriGeneratorInterface $uriGenerator + ) {} + + public function authenticateByPassword(string $username, string $password): array + { + $headers = [ + 'Content-Type' => 'application/json', + ]; + + $uri = $this->uriGenerator->generate(static::TOKEN_URI); + + $response = $this->httpClient->sendRequest('POST', $uri, $headers, json_encode([ + 'email' => $username, + 'password' => $password, + ])); + + return json_decode($response->getBody()->getContents(), true); + } +} diff --git a/src/Api/AuthenticationApiInterface.php b/src/Api/Authentication/AuthenticationApiInterface.php similarity index 50% rename from src/Api/AuthenticationApiInterface.php rename to src/Api/Authentication/AuthenticationApiInterface.php index f294cf4..e9341e8 100644 --- a/src/Api/AuthenticationApiInterface.php +++ b/src/Api/Authentication/AuthenticationApiInterface.php @@ -9,7 +9,7 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Authentication; /** * API to manage the authentication. @@ -23,23 +23,7 @@ interface AuthenticationApiInterface /** * Authenticates with the password grant type. * - * @param string $clientId - * @param string $secret - * @param string $username - * @param string $password - * - * @return array - */ - public function authenticateByPassword($clientId, $secret, $username, $password); - - /** - * Authenticates with the refresh token grant type. - * - * @param string $clientId - * @param string $secret - * @param string $refreshToken - * - * @return array + * @return array{token: string} */ - public function authenticateByRefreshToken($clientId, $secret, $refreshToken); + public function authenticateByPassword(string $username, string $password): array; } diff --git a/src/Api/Authentication/ShopApi.php b/src/Api/Authentication/ShopApi.php new file mode 100644 index 0000000..9b713d8 --- /dev/null +++ b/src/Api/Authentication/ShopApi.php @@ -0,0 +1,48 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient\Api\Authentication; + +use Diglin\Sylius\ApiClient\Client\HttpClient; +use Diglin\Sylius\ApiClient\Routing\UriGeneratorInterface; + +/** + * API implementation to manage the authentication. + * + * @author Alexandre Hocquard + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class ShopApi implements AuthenticationApiInterface +{ + public const TOKEN_URI = 'api/v2/shop/authentication-token'; + + public function __construct( + private HttpClient $httpClient, + private UriGeneratorInterface $uriGenerator + ) {} + + public function authenticateByPassword(string $username, string $password): array + { + $headers = [ + 'Content-Type' => 'application/json', + ]; + + $uri = $this->uriGenerator->generate(static::TOKEN_URI); + + $response = $this->httpClient->sendRequest('POST', $uri, $headers, json_encode([ + 'email' => $username, + 'password' => $password, + ])); + + return json_decode($response->getBody()->getContents(), true); + } +} diff --git a/src/Api/AuthenticationApi.php b/src/Api/AuthenticationApi.php deleted file mode 100644 index 8a3d14d..0000000 --- a/src/Api/AuthenticationApi.php +++ /dev/null @@ -1,85 +0,0 @@ - - * - * @category SyliusApiClient - * - * @copyright 2020 - Diglin (https://www.diglin.com) - */ - -namespace Diglin\Sylius\ApiClient\Api; - -use Diglin\Sylius\ApiClient\Client\HttpClient; -use Diglin\Sylius\ApiClient\Routing\UriGeneratorInterface; - -/** - * API implementation to manage the authentication. - * - * @author Alexandre Hocquard - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class AuthenticationApi implements AuthenticationApiInterface -{ - public const TOKEN_URI = 'api/v2/admin/authentication-token'; - - /** @var HttpClient */ - protected $httpClient; - - /** @var UriGeneratorInterface */ - protected $uriGenerator; - - public function __construct(HttpClient $httpClient, UriGeneratorInterface $uriGenerator) - { - $this->httpClient = $httpClient; - $this->uriGenerator = $uriGenerator; - } - - /** - * {@inheritdoc} - */ - public function authenticateByPassword($clientId, $secret, $username, $password) - { - $requestBody = [ - 'email' => $username, - 'password' => $password, - ]; - - return $this->authenticate($requestBody); - } - - /** - * {@inheritdoc} - */ - public function authenticateByRefreshToken($clientId, $secret, $refreshToken) - { - $requestBody = [ - 'grant_type' => 'refresh_token', - 'refresh_token' => $refreshToken, - ]; - - return $this->authenticate($requestBody); - } - - /** - * Authenticates the client by requesting the access token and the refresh token. - * - * @param array $requestBody body of the request to authenticate - * - * @return array returns the body of the response containing access token and refresh token - */ - protected function authenticate(array $requestBody) - { - $headers = [ - 'Content-Type' => 'application/json', - ]; - - $uri = $this->uriGenerator->generate(static::TOKEN_URI); - - $response = $this->httpClient->sendRequest('POST', $uri, $headers, json_encode($requestBody)); - - return json_decode($response->getBody()->getContents(), true); - } -} diff --git a/src/Client/AuthenticatedHttpClient.php b/src/Client/AuthenticatedHttpClient.php index ec55b71..26ed3f7 100644 --- a/src/Client/AuthenticatedHttpClient.php +++ b/src/Client/AuthenticatedHttpClient.php @@ -2,9 +2,10 @@ namespace Diglin\Sylius\ApiClient\Client; -use Diglin\Sylius\ApiClient\Api\AuthenticationApiInterface; +use Diglin\Sylius\ApiClient\Api; use Diglin\Sylius\ApiClient\Exception\UnauthorizedHttpException; use Diglin\Sylius\ApiClient\Security\Authentication; +use Psr\Log\LoggerInterface; /** * Http client to send an authenticated request. @@ -20,24 +21,11 @@ */ class AuthenticatedHttpClient implements HttpClientInterface { - /** @var HttpClient */ - protected $basicHttpClient; - - /** @var AuthenticationApiInterface */ - protected $authenticationApi; - - /** @var Authentication */ - protected $authentication; - public function __construct( - HttpClient $basicHttpClient, - AuthenticationApiInterface $authenticationApi, - Authentication $authentication - ) { - $this->basicHttpClient = $basicHttpClient; - $this->authenticationApi = $authenticationApi; - $this->authentication = $authentication; - } + private HttpClient $basicHttpClient, + private Api\Authentication\AuthenticationApiInterface $authenticationApi, + private Authentication $authentication, + ) {} /** * {@inheritdoc} @@ -45,48 +33,14 @@ public function __construct( public function sendRequest($httpMethod, $uri, array $headers = [], $body = null) { try { - $xauthtokenDetected = false; - foreach ((array) $this->authentication->getXauthtokenHeader() as $name => $value) { - $headers[$name] = $value; - $xauthtokenDetected = true; + if (!$this->authentication->hasAccessToken()) { + $this->authentication->authenticateByPassword($this->authenticationApi); } - if ($xauthtokenDetected) { - return $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); - } - } catch (UnauthorizedHttpException $e) { - // Do nothing and process to standard authentication - } - - if (null === $this->authentication->getAccessToken()) { - $tokens = $this->authenticationApi->authenticateByPassword( - $this->authentication->getClientId(), - $this->authentication->getSecret(), - $this->authentication->getUsername(), - $this->authentication->getPassword() - ); - - $this->authentication - ->setAccessToken($tokens['token']) - ; - } - - try { - $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); - $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); - } catch (UnauthorizedHttpException $e) { - $tokens = $this->authenticationApi->authenticateByRefreshToken( - $this->authentication->getClientId(), - $this->authentication->getSecret(), - $this->authentication->getRefreshToken() - ); - - $this->authentication - ->setAccessToken($tokens['token']) - ; - - $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); - $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $this->authentication->appendHeaders($headers), $body); + } catch (UnauthorizedHttpException) { + $this->authentication->authenticateByPassword($this->authenticationApi); + $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $this->authentication->appendHeaders($headers), $body); } return $response; diff --git a/src/Security/Authentication.php b/src/Security/Authentication.php index 6c4e386..1ac2733 100644 --- a/src/Security/Authentication.php +++ b/src/Security/Authentication.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Security; +use Diglin\Sylius\ApiClient\Api; + /** * Credential data to authenticate to the API. * @@ -11,137 +13,56 @@ */ class Authentication { - /** @var string */ - protected $clientId; - - /** @var string */ - protected $secret; - - /** @var string */ - protected $username; - - /** @var string */ - protected $password; + private ?string $username = null; + private ?string $password = null; + private ?string $accessToken = null; - /** @var string */ - protected $accessToken; - - /** @var string */ - protected $refreshToken; - - /** @var array */ - protected $xauthtokenHeader; - - /** - * @return Authentication - */ - public static function fromPassword(string $clientId, string $secret, string $username, string $password) + public static function fromPassword(string $username, string $password): self { $authentication = new static(); - $authentication->clientId = $clientId; - $authentication->secret = $secret; $authentication->username = $username; $authentication->password = $password; return $authentication; } - /** - * @return Authentication - */ - public static function fromToken(string $clientId, string $secret, string $accessToken, string $refreshToken) + public static function fromAccessToken(string $accessToken): self { $authentication = new static(); - $authentication->clientId = $clientId; - $authentication->secret = $secret; $authentication->accessToken = $accessToken; - $authentication->refreshToken = $refreshToken; return $authentication; } - public static function fromXAuthToken(array $fromXAuthToken) - { - $authentication = new static(); - $authentication->xauthtokenHeader = $fromXAuthToken; - - return $authentication; - } - - /** - * @return string - */ - public function getClientId() - { - return $this->clientId; - } - - /** - * @return string - */ - public function getSecret() - { - return $this->secret; - } - - /** - * @return string - */ - public function getUsername() - { - return $this->username; - } + public function authenticateByPassword( + Api\Authentication\AuthenticationApiInterface $api + ): self { + $result = $api->authenticateByPassword($this->username, $this->password); - /** - * @return string - */ - public function getPassword() - { - return $this->password; - } + $this->accessToken = $result['token']; - /** - * @return null|string - */ - public function getAccessToken() - { - return $this->accessToken; + return $this; } - /** - * @return null|string - */ - public function getRefreshToken() + public function appendHeaders(array $headers): array { - return $this->refreshToken; + return array_merge( + $headers, + [ + 'Authorization' => sprintf('Bearer %s', $this->accessToken), + ] + ); } - /** - * @param string $accessToken - * - * @return Authentication - */ - public function setAccessToken($accessToken) + public function hasAccessToken(): bool { - $this->accessToken = $accessToken; - - return $this; + return $this->accessToken !== null; } - /** - * @param string $refreshToken - * - * @return Authentication - */ - public function setRefreshToken($refreshToken) + public function clearAccessToken(): self { - $this->refreshToken = $refreshToken; + $this->accessToken = null; return $this; } - - public function getXauthtokenHeader(): ?array - { - return $this->xauthtokenHeader; - } } From dc1215445b90865b31f106c7689591d58b9e5269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Tue, 26 Oct 2021 23:33:39 +0200 Subject: [PATCH 06/13] Refactored the API endpoints and client --- composer.json | 8 +- .../{ => Legacy}/AuthenticationApiSpec.php | 6 +- spec/Client/AuthenticatedHttpClientSpec.php | 2 +- .../LegacyAuthenticatedHttpClientSpec.php | 162 +++++++++++ spec/Client/ResourceClientSpec.php | 2 +- spec/Pagination/PageFactorySpec.php | 17 +- spec/Routing/UriGeneratorSpec.php | 2 +- ...nSpec.php => LegacyAuthenticationSpec.php} | 6 +- ...entSpec.php => SyliusLegacyClientSpec.php} | 16 +- src/Api/Admin/AddressApi.php | 19 ++ src/Api/Admin/AddressApiInterface.php | 9 + src/Api/Admin/AdjustmentApi.php | 52 ++++ src/Api/Admin/AdjustmentApiInterface.php | 10 + src/Api/Admin/AdministratorApi.php | 67 +++++ src/Api/Admin/AdministratorApiInterface.php | 13 + src/Api/Admin/AvatarImageApi.php | 31 ++ src/Api/Admin/AvatarImageApiInterface.php | 11 + src/Api/Admin/CatalogPromotionApi.php | 61 ++++ .../Admin/CatalogPromotionApiInterface.php | 12 + .../Admin/CatalogPromotionTranslationApi.php | 19 ++ ...atalogPromotionTranslationApiInterface.php | 9 + src/Api/Admin/ChannelApi.php | 61 ++++ src/Api/Admin/ChannelApiInterface.php | 12 + src/Api/Admin/CountryApi.php | 61 ++++ src/Api/Admin/CountryApiInterface.php | 12 + src/Api/Admin/CurrencyApi.php | 61 ++++ src/Api/Admin/CurrencyApiInterface.php | 11 + src/Api/Admin/CustomerApi.php | 19 ++ src/Api/Admin/CustomerApiInterface.php | 9 + src/Api/Admin/CustomerGroupApi.php | 67 +++++ src/Api/Admin/CustomerGroupApiInterface.php | 13 + src/Api/Admin/ExchangeRateApi.php | 67 +++++ src/Api/Admin/ExchangeRateApiInterface.php | 13 + src/Api/Admin/LocaleApi.php | 55 ++++ src/Api/Admin/LocaleApiInterface.php | 11 + src/Api/Admin/OrderItemApi.php | 19 ++ src/Api/Admin/OrderItemApiInterface.php | 9 + src/Api/Admin/OrderItemUnitApi.php | 19 ++ src/Api/Admin/OrderItemUnitApiInterface.php | 9 + src/Api/Admin/ProvinceApi.php | 58 ++++ src/Api/Admin/ProvinceApiInterface.php | 11 + src/Api/Admin/ShopBillingDataApi.php | 52 ++++ src/Api/Admin/ShopBillingDataApiInterface.php | 10 + src/Api/ApiAwareInterface.php | 8 +- src/Api/ApiAwareTrait.php | 23 +- src/Api/Legacy/AuthenticationApi.php | 82 ++++++ src/Api/Legacy/AuthenticationApiInterface.php | 33 +++ src/Api/{ => Legacy}/CartsApi.php | 31 +- src/Api/{ => Legacy}/CartsApiInterface.php | 4 +- src/Api/{ => Legacy}/ChannelsApi.php | 31 +- src/Api/{ => Legacy}/ChannelsApiInterface.php | 4 +- src/Api/{ => Legacy}/CountriesApi.php | 31 +- .../{ => Legacy}/CountriesApiInterface.php | 4 +- src/Api/{ => Legacy}/CurrenciesApi.php | 31 +- .../{ => Legacy}/CurrenciesApiInterface.php | 4 +- src/Api/{ => Legacy}/CustomersApi.php | 36 +-- .../{ => Legacy}/CustomersApiInterface.php | 4 +- src/Api/{ => Legacy}/ExchangeRatesApi.php | 31 +- .../ExchangeRatesApiInterface.php | 4 +- src/Api/{ => Legacy}/LocalesApi.php | 31 +- src/Api/{ => Legacy}/LocalesApiInterface.php | 4 +- src/Api/{ => Legacy}/OrdersApi.php | 31 +- src/Api/{ => Legacy}/OrdersApiInterface.php | 4 +- src/Api/{ => Legacy}/PaymentMethodsApi.php | 21 +- .../PaymentMethodsApiInterface.php | 4 +- src/Api/{ => Legacy}/PaymentsApi.php | 21 +- src/Api/{ => Legacy}/PaymentsApiInterface.php | 4 +- .../ProductAssociationTypesApi.php | 31 +- .../ProductAssociationTypesApiInterface.php | 4 +- src/Api/{ => Legacy}/ProductAttributesApi.php | 31 +- .../ProductAttributesApiInterface.php | 4 +- src/Api/{ => Legacy}/ProductOptionsApi.php | 31 +- .../ProductOptionsApiInterface.php | 4 +- src/Api/{ => Legacy}/ProductReviewsApi.php | 28 +- .../ProductReviewsApiInterface.php | 4 +- src/Api/{ => Legacy}/ProductVariantsApi.php | 35 +-- .../ProductVariantsApiInterface.php | 4 +- src/Api/{ => Legacy}/ProductsApi.php | 34 +-- src/Api/{ => Legacy}/ProductsApiInterface.php | 4 +- src/Api/{ => Legacy}/PromotionCouponsApi.php | 35 +-- .../PromotionCouponsApiInterface.php | 4 +- src/Api/{ => Legacy}/PromotionsApi.php | 31 +- .../{ => Legacy}/PromotionsApiInterface.php | 4 +- src/Api/{ => Legacy}/ShipmentsApi.php | 31 +- .../{ => Legacy}/ShipmentsApiInterface.php | 4 +- .../{ => Legacy}/ShippingCategoriesApi.php | 21 +- .../ShippingCategoriesApiInterface.php | 4 +- src/Api/{ => Legacy}/TaxCategoriesApi.php | 31 +- .../TaxCategoriesApiInterface.php | 4 +- src/Api/{ => Legacy}/TaxRatesApi.php | 21 +- src/Api/{ => Legacy}/TaxRatesApiInterface.php | 4 +- src/Api/{ => Legacy}/TaxonsApi.php | 31 +- src/Api/{ => Legacy}/TaxonsApiInterface.php | 4 +- src/Api/{ => Legacy}/UsersApi.php | 31 +- src/Api/{ => Legacy}/UsersApiInterface.php | 4 +- src/Api/{ => Legacy}/ZonesApi.php | 31 +- src/Api/{ => Legacy}/ZonesApiInterface.php | 4 +- .../Operation/CreatableResourceInterface.php | 6 +- .../DeletableDoubleResourceInterface.php | 6 +- .../Operation/DeletableResourceInterface.php | 4 +- .../DownloadableResourceInterface.php | 4 +- .../GettableDoubleResourceInterface.php | 8 +- .../Operation/GettableResourceInterface.php | 6 +- .../ListableDoubleResourceInterface.php | 22 +- .../Operation/ListableResourceInterface.php | 8 +- .../Operation/UpsertableResourceInterface.php | 4 +- .../UpsertableResourceListInterface.php | 2 +- src/Api/Shop/AddressApi.php | 67 +++++ src/Api/Shop/AddressApiInterface.php | 13 + src/Api/Shop/AdjustmentApi.php | 52 ++++ src/Api/Shop/AdjustmentApiInterface.php | 10 + src/Api/Shop/ChannelApi.php | 19 ++ src/Api/Shop/ChannelApiInterface.php | 9 + src/Api/Shop/CountryApi.php | 49 ++++ src/Api/Shop/CountryApiInterface.php | 10 + src/Client/LegacyAuthenticatedHttpClient.php | 84 ++++++ src/Client/ResourceClient.php | 154 ++++++---- src/Client/ResourceClientInterface.php | 96 ++++--- src/ClientBuilderInterface.php | 21 ++ src/Routing/UriGenerator.php | 4 +- src/Routing/UriGeneratorInterface.php | 8 +- src/Security/LegacyAuthentication.php | 100 +++++++ src/SyliusAdminClient.php | 79 ++++++ src/SyliusAdminClientBuilder.php | 189 +++++++++++++ src/SyliusAdminClientBuilderInterface.php | 15 + src/SyliusAdminClientDecorator.php | 90 ++++++ src/SyliusAdminClientInterface.php | 26 ++ src/SyliusClient.php | 265 +----------------- src/SyliusClientBuilder.php | 262 +---------------- src/SyliusClientBuilderInterface.php | 45 +-- src/SyliusClientInterface.php | 94 +------ src/SyliusLegacyClient.php | 182 ++++++++++++ src/SyliusLegacyClientBuilderInterface.php | 27 ++ ...or.php => SyliusLegacyClientDecorator.php} | 6 +- src/SyliusLegacyClientFactory.php | 249 ++++++++++++++++ src/SyliusLegacyClientInterface.php | 68 +++++ src/SyliusShopClient.php | 38 +++ src/SyliusShopClientBuilder.php | 183 ++++++++++++ src/SyliusShopClientBuilderInterface.php | 15 + src/SyliusShopClientDecorator.php | 55 ++++ src/SyliusShopClientInterface.php | 13 + 141 files changed, 3501 insertions(+), 1353 deletions(-) rename spec/Api/{ => Legacy}/AuthenticationApiSpec.php (94%) create mode 100644 spec/Client/LegacyAuthenticatedHttpClientSpec.php rename spec/Security/{AuthenticationSpec.php => LegacyAuthenticationSpec.php} (91%) rename spec/{SyliusClientSpec.php => SyliusLegacyClientSpec.php} (93%) create mode 100644 src/Api/Admin/AddressApi.php create mode 100644 src/Api/Admin/AddressApiInterface.php create mode 100644 src/Api/Admin/AdjustmentApi.php create mode 100644 src/Api/Admin/AdjustmentApiInterface.php create mode 100644 src/Api/Admin/AdministratorApi.php create mode 100644 src/Api/Admin/AdministratorApiInterface.php create mode 100644 src/Api/Admin/AvatarImageApi.php create mode 100644 src/Api/Admin/AvatarImageApiInterface.php create mode 100644 src/Api/Admin/CatalogPromotionApi.php create mode 100644 src/Api/Admin/CatalogPromotionApiInterface.php create mode 100644 src/Api/Admin/CatalogPromotionTranslationApi.php create mode 100644 src/Api/Admin/CatalogPromotionTranslationApiInterface.php create mode 100644 src/Api/Admin/ChannelApi.php create mode 100644 src/Api/Admin/ChannelApiInterface.php create mode 100644 src/Api/Admin/CountryApi.php create mode 100644 src/Api/Admin/CountryApiInterface.php create mode 100644 src/Api/Admin/CurrencyApi.php create mode 100644 src/Api/Admin/CurrencyApiInterface.php create mode 100644 src/Api/Admin/CustomerApi.php create mode 100644 src/Api/Admin/CustomerApiInterface.php create mode 100644 src/Api/Admin/CustomerGroupApi.php create mode 100644 src/Api/Admin/CustomerGroupApiInterface.php create mode 100644 src/Api/Admin/ExchangeRateApi.php create mode 100644 src/Api/Admin/ExchangeRateApiInterface.php create mode 100644 src/Api/Admin/LocaleApi.php create mode 100644 src/Api/Admin/LocaleApiInterface.php create mode 100644 src/Api/Admin/OrderItemApi.php create mode 100644 src/Api/Admin/OrderItemApiInterface.php create mode 100644 src/Api/Admin/OrderItemUnitApi.php create mode 100644 src/Api/Admin/OrderItemUnitApiInterface.php create mode 100644 src/Api/Admin/ProvinceApi.php create mode 100644 src/Api/Admin/ProvinceApiInterface.php create mode 100644 src/Api/Admin/ShopBillingDataApi.php create mode 100644 src/Api/Admin/ShopBillingDataApiInterface.php create mode 100644 src/Api/Legacy/AuthenticationApi.php create mode 100644 src/Api/Legacy/AuthenticationApiInterface.php rename src/Api/{ => Legacy}/CartsApi.php (83%) rename src/Api/{ => Legacy}/CartsApiInterface.php (84%) rename src/Api/{ => Legacy}/ChannelsApi.php (83%) rename src/Api/{ => Legacy}/ChannelsApiInterface.php (84%) rename src/Api/{ => Legacy}/CountriesApi.php (83%) rename src/Api/{ => Legacy}/CountriesApiInterface.php (84%) rename src/Api/{ => Legacy}/CurrenciesApi.php (83%) rename src/Api/{ => Legacy}/CurrenciesApiInterface.php (84%) rename src/Api/{ => Legacy}/CustomersApi.php (80%) rename src/Api/{ => Legacy}/CustomersApiInterface.php (84%) rename src/Api/{ => Legacy}/ExchangeRatesApi.php (83%) rename src/Api/{ => Legacy}/ExchangeRatesApiInterface.php (84%) rename src/Api/{ => Legacy}/LocalesApi.php (83%) rename src/Api/{ => Legacy}/LocalesApiInterface.php (84%) rename src/Api/{ => Legacy}/OrdersApi.php (83%) rename src/Api/{ => Legacy}/OrdersApiInterface.php (84%) rename src/Api/{ => Legacy}/PaymentMethodsApi.php (85%) rename src/Api/{ => Legacy}/PaymentMethodsApiInterface.php (79%) rename src/Api/{ => Legacy}/PaymentsApi.php (85%) rename src/Api/{ => Legacy}/PaymentsApiInterface.php (79%) rename src/Api/{ => Legacy}/ProductAssociationTypesApi.php (83%) rename src/Api/{ => Legacy}/ProductAssociationTypesApiInterface.php (85%) rename src/Api/{ => Legacy}/ProductAttributesApi.php (83%) rename src/Api/{ => Legacy}/ProductAttributesApiInterface.php (84%) rename src/Api/{ => Legacy}/ProductOptionsApi.php (83%) rename src/Api/{ => Legacy}/ProductOptionsApiInterface.php (84%) rename src/Api/{ => Legacy}/ProductReviewsApi.php (83%) rename src/Api/{ => Legacy}/ProductReviewsApiInterface.php (85%) rename src/Api/{ => Legacy}/ProductVariantsApi.php (81%) rename src/Api/{ => Legacy}/ProductVariantsApiInterface.php (85%) rename src/Api/{ => Legacy}/ProductsApi.php (82%) rename src/Api/{ => Legacy}/ProductsApiInterface.php (86%) rename src/Api/{ => Legacy}/PromotionCouponsApi.php (81%) rename src/Api/{ => Legacy}/PromotionCouponsApiInterface.php (85%) rename src/Api/{ => Legacy}/PromotionsApi.php (83%) rename src/Api/{ => Legacy}/PromotionsApiInterface.php (84%) rename src/Api/{ => Legacy}/ShipmentsApi.php (83%) rename src/Api/{ => Legacy}/ShipmentsApiInterface.php (84%) rename src/Api/{ => Legacy}/ShippingCategoriesApi.php (85%) rename src/Api/{ => Legacy}/ShippingCategoriesApiInterface.php (79%) rename src/Api/{ => Legacy}/TaxCategoriesApi.php (83%) rename src/Api/{ => Legacy}/TaxCategoriesApiInterface.php (84%) rename src/Api/{ => Legacy}/TaxRatesApi.php (85%) rename src/Api/{ => Legacy}/TaxRatesApiInterface.php (79%) rename src/Api/{ => Legacy}/TaxonsApi.php (83%) rename src/Api/{ => Legacy}/TaxonsApiInterface.php (84%) rename src/Api/{ => Legacy}/UsersApi.php (83%) rename src/Api/{ => Legacy}/UsersApiInterface.php (84%) rename src/Api/{ => Legacy}/ZonesApi.php (83%) rename src/Api/{ => Legacy}/ZonesApiInterface.php (84%) create mode 100644 src/Api/Shop/AddressApi.php create mode 100644 src/Api/Shop/AddressApiInterface.php create mode 100644 src/Api/Shop/AdjustmentApi.php create mode 100644 src/Api/Shop/AdjustmentApiInterface.php create mode 100644 src/Api/Shop/ChannelApi.php create mode 100644 src/Api/Shop/ChannelApiInterface.php create mode 100644 src/Api/Shop/CountryApi.php create mode 100644 src/Api/Shop/CountryApiInterface.php create mode 100644 src/Client/LegacyAuthenticatedHttpClient.php create mode 100644 src/ClientBuilderInterface.php create mode 100644 src/Security/LegacyAuthentication.php create mode 100644 src/SyliusAdminClient.php create mode 100644 src/SyliusAdminClientBuilder.php create mode 100644 src/SyliusAdminClientBuilderInterface.php create mode 100644 src/SyliusAdminClientDecorator.php create mode 100644 src/SyliusAdminClientInterface.php create mode 100644 src/SyliusLegacyClient.php create mode 100644 src/SyliusLegacyClientBuilderInterface.php rename src/{SyliusClientDecorator.php => SyliusLegacyClientDecorator.php} (97%) create mode 100644 src/SyliusLegacyClientFactory.php create mode 100644 src/SyliusLegacyClientInterface.php create mode 100644 src/SyliusShopClient.php create mode 100644 src/SyliusShopClientBuilder.php create mode 100644 src/SyliusShopClientBuilderInterface.php create mode 100644 src/SyliusShopClientDecorator.php create mode 100644 src/SyliusShopClientInterface.php diff --git a/composer.json b/composer.json index cc72ce5..d2bbfb8 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ }, "autoload-dev": { "psr-4": { + "spec\\Diglin\\Sylius\\ApiClient\\": "spec/", "Diglin\\Sylius\\ApiClient\\tests\\": "tests/" } }, @@ -33,12 +34,13 @@ "php-http/message-factory": "^v1.0", "php-http/multipart-stream-builder": "^1.0", "php-http/client-implementation": "^1.0", - "symfony/expression-language": "^3.0|^4.0|^5.0" + "symfony/expression-language": "^3.0|^4.0|^5.0", + "webmozart/assert": "^1.10" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.14", - "phpunit/phpunit": "^5.7", - "phpspec/phpspec": "^5.0", + "phpunit/phpunit": "^9.0", + "phpspec/phpspec": "^7.1", "symfony/yaml": "^4.2", "donatj/mock-webserver": "^2.0", "php-http/guzzle6-adapter": "^2.0" diff --git a/spec/Api/AuthenticationApiSpec.php b/spec/Api/Legacy/AuthenticationApiSpec.php similarity index 94% rename from spec/Api/AuthenticationApiSpec.php rename to spec/Api/Legacy/AuthenticationApiSpec.php index d23b080..5a73d91 100644 --- a/spec/Api/AuthenticationApiSpec.php +++ b/spec/Api/Legacy/AuthenticationApiSpec.php @@ -1,9 +1,9 @@ beConstructedWith($httpClient, $authenticationApi, $authentication); + } + + public function it_is_initializable() + { + $this->shouldHaveType(LegacyAuthenticatedHttpClient::class); + $this->shouldImplement(HttpClientInterface::class); + } + + public function it_sends_an_authenticated_and_successful_request_when_access_token_is_defined( + $httpClient, + $authentication, + ResponseInterface $response + ) { + $authentication->getXauthtokenHeader()->willReturn(null); + $authentication->getAccessToken()->willReturn('bar'); + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer bar'], + '{"identifier": "foo"}' + )->willReturn($response); + + $this->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json'], + '{"identifier": "foo"}' + )->shouldReturn($response); + } + + public function it_sends_an_authenticated_and_successful_request_at_first_call( + $httpClient, + $authenticationApi, + $authentication, + ResponseInterface $response + ) { + $authentication->getXauthtokenHeader()->willReturn(null); + $authentication->getClientId()->willReturn('client_id'); + $authentication->getSecret()->willReturn('secret'); + $authentication->getUsername()->willReturn('julia'); + $authentication->getPassword()->willReturn('julia_pwd'); + $authentication->getAccessToken()->willReturn(null, 'foo'); + + $authenticationApi + ->authenticateByPassword('client_id', 'secret', 'julia', 'julia_pwd') + ->willReturn([ + 'access_token' => 'foo', + 'expires_in' => 3600, + 'token_type' => 'bearer', + 'scope' => null, + 'refresh_token' => 'bar', + ]) + ; + + $authentication + ->setAccessToken('foo') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $authentication + ->setRefreshToken('bar') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer foo'], + '{"identifier": "foo"}' + )->willReturn($response); + + $this->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json'], + '{"identifier": "foo"}' + )->shouldReturn($response); + } + + public function it_sends_an_authenticated_and_successful_request_when_access_token_expired( + $httpClient, + $authenticationApi, + $authentication, + ResponseInterface $response + ) { + $authentication->getXauthtokenHeader()->willReturn(null); + $authentication->getClientId()->willReturn('client_id'); + $authentication->getSecret()->willReturn('secret'); + $authentication->getUsername()->willReturn('julia'); + $authentication->getPassword()->willReturn('julia_pwd'); + $authentication->getAccessToken()->willReturn('foo', 'foo', 'baz'); + $authentication->getRefreshToken()->willReturn('bar'); + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer foo'], + '{"identifier": "foo"}' + )->willThrow(UnauthorizedHttpException::class); + + $authenticationApi + ->authenticateByRefreshToken('client_id', 'secret', 'bar') + ->willReturn([ + 'access_token' => 'baz', + 'expires_in' => 3600, + 'token_type' => 'bearer', + 'scope' => null, + 'refresh_token' => 'foz', + ]) + ; + + $authentication + ->setAccessToken('baz') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $authentication + ->setRefreshToken('foz') + ->shouldBeCalled() + ->willReturn($authentication) + ; + + $httpClient->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json', 'Authorization' => 'Bearer baz'], + '{"identifier": "foo"}' + )->willReturn($response); + + $this->sendRequest( + 'POST', + 'http://diglin.com/api/rest/v1/products/foo', + ['Content-Type' => 'application/json'], + '{"identifier": "foo"}' + ); + } +} diff --git a/spec/Client/ResourceClientSpec.php b/spec/Client/ResourceClientSpec.php index a738907..af5b7f4 100644 --- a/spec/Client/ResourceClientSpec.php +++ b/spec/Client/ResourceClientSpec.php @@ -105,7 +105,7 @@ public function it_returns_a_page_when_requesting_a_list_of_resources( ->willReturn(json_encode($resources)) ; - $this->getResources('api/rest/v1/categories', [], 10, ['foo' => 'bar'])->shouldReturn($resources); + $this->getResources('api/rest/v1/categories', [], 10, ['foo' => 'bar', 'with_count' => true])->shouldReturn($resources); } public function it_returns_a_list_of_resources_without_limit_and_count( diff --git a/spec/Pagination/PageFactorySpec.php b/spec/Pagination/PageFactorySpec.php index 2225c25..f218995 100644 --- a/spec/Pagination/PageFactorySpec.php +++ b/spec/Pagination/PageFactorySpec.php @@ -6,13 +6,14 @@ use Diglin\Sylius\ApiClient\Pagination\Page; use Diglin\Sylius\ApiClient\Pagination\PageFactory; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Routing\UriGeneratorInterface; use PhpSpec\ObjectBehavior; class PageFactorySpec extends ObjectBehavior { - public function let(HttpClientInterface $httpClient) + public function let(HttpClientInterface $httpClient, UriGeneratorInterface $uriGenerator) { - $this->beConstructedWith($httpClient); + $this->beConstructedWith($httpClient, $uriGenerator); } public function it_is_initializable() @@ -21,7 +22,7 @@ public function it_is_initializable() $this->shouldImplement(PageFactoryInterface::class); } - public function it_creates_a_page_with_all_links($httpClient) + public function it_creates_a_page_with_all_links($httpClient, $uriGenerator) { $data = [ '_links' => [ @@ -50,7 +51,7 @@ public function it_creates_a_page_with_all_links($httpClient) $this->createPage($data)->shouldReturnAnInstanceOf(Page::class); $this->createPage($data)->shouldBeLike( new Page( - new PageFactory($httpClient->getWrappedObject()), + new PageFactory($httpClient->getWrappedObject(), $uriGenerator->getWrappedObject()), $httpClient->getWrappedObject(), 'http://diglin.com/first', 'http://diglin.com/previous', @@ -64,7 +65,7 @@ public function it_creates_a_page_with_all_links($httpClient) ); } - public function it_creates_a_page_without_next_and_previous_links($httpClient) + public function it_creates_a_page_without_next_and_previous_links($httpClient, $uriGenerator) { $data = [ '_links' => [ @@ -87,7 +88,7 @@ public function it_creates_a_page_without_next_and_previous_links($httpClient) $this->createPage($data)->shouldReturnAnInstanceOf(Page::class); $this->createPage($data)->shouldBeLike( new Page( - new PageFactory($httpClient->getWrappedObject()), + new PageFactory($httpClient->getWrappedObject(), $uriGenerator->getWrappedObject()), $httpClient->getWrappedObject(), 'http://diglin.com/first', null, @@ -101,7 +102,7 @@ public function it_creates_a_page_without_next_and_previous_links($httpClient) ); } - public function it_creates_a_page_without_count($httpClient) + public function it_creates_a_page_without_count($httpClient, $uriGenerator) { $data = [ '_links' => [ @@ -129,7 +130,7 @@ public function it_creates_a_page_without_count($httpClient) $this->createPage($data)->shouldReturnAnInstanceOf(Page::class); $this->createPage($data)->shouldBeLike( new Page( - new PageFactory($httpClient->getWrappedObject()), + new PageFactory($httpClient->getWrappedObject(), $uriGenerator->getWrappedObject()), $httpClient->getWrappedObject(), 'http://diglin.com/first', 'http://diglin.com/previous', diff --git a/spec/Routing/UriGeneratorSpec.php b/spec/Routing/UriGeneratorSpec.php index 2a6a5d7..c87ba4a 100644 --- a/spec/Routing/UriGeneratorSpec.php +++ b/spec/Routing/UriGeneratorSpec.php @@ -85,7 +85,7 @@ public function it_generates_uri_having_search_parameter_encoded_in_json() $this ->generate('/api', [], $queryParameters) - ->shouldReturn(static::BASE_URI.'api?search=%7B%22categories%22%3A%5B%7B%22operator%22%3A%22IN%22%2C%22value%22%3A%22master%22%7D%5D%7D') + ->shouldReturn(static::BASE_URI.'api?search%5Bcategories%5D%5B0%5D%5Boperator%5D=IN&search%5Bcategories%5D%5B0%5D%5Bvalue%5D=master') ; } } diff --git a/spec/Security/AuthenticationSpec.php b/spec/Security/LegacyAuthenticationSpec.php similarity index 91% rename from spec/Security/AuthenticationSpec.php rename to spec/Security/LegacyAuthenticationSpec.php index bbc3d9a..6f57a6e 100644 --- a/spec/Security/AuthenticationSpec.php +++ b/spec/Security/LegacyAuthenticationSpec.php @@ -4,12 +4,12 @@ use PhpSpec\ObjectBehavior; -class AuthenticationSpec extends ObjectBehavior +class LegacyAuthenticationSpec extends ObjectBehavior { public function it_is_initializable_from_a_password() { $this->beConstructedThrough('fromPassword', ['client_id', 'secret', 'Julia', 'Julia_pwd']); - $this->shouldHaveType('Diglin\Sylius\ApiClient\Security\Authentication'); + $this->shouldHaveType('Diglin\Sylius\ApiClient\Security\LegacyAuthentication'); $this->getUsername()->shouldReturn('Julia'); $this->getPassword()->shouldReturn('Julia_pwd'); @@ -20,7 +20,7 @@ public function it_is_initializable_from_a_password() public function it_is_initializable_from_a_token() { $this->beConstructedThrough('fromToken', ['client_id', 'secret', 'token', 'refresh_token']); - $this->shouldHaveType('Diglin\Sylius\ApiClient\Security\Authentication'); + $this->shouldHaveType('Diglin\Sylius\ApiClient\Security\LegacyAuthentication'); $this->getClientId()->shouldReturn('client_id'); $this->getSecret()->shouldReturn('secret'); diff --git a/spec/SyliusClientSpec.php b/spec/SyliusLegacyClientSpec.php similarity index 93% rename from spec/SyliusClientSpec.php rename to spec/SyliusLegacyClientSpec.php index d84d5f6..72efffa 100644 --- a/spec/SyliusClientSpec.php +++ b/spec/SyliusLegacyClientSpec.php @@ -2,16 +2,16 @@ namespace spec\Diglin\Sylius\ApiClient; -use Diglin\Sylius\ApiClient\Api; -use Diglin\Sylius\ApiClient\Security\Authentication; -use Diglin\Sylius\ApiClient\SyliusClient; -use Diglin\Sylius\ApiClient\SyliusClientInterface; +use Diglin\Sylius\ApiClient\Api\Legacy as Api; +use Diglin\Sylius\ApiClient\Security\LegacyAuthentication; +use Diglin\Sylius\ApiClient\SyliusLegacyClient; +use Diglin\Sylius\ApiClient\SyliusLegacyClientInterface; use PhpSpec\ObjectBehavior; -class SyliusClientSpec extends ObjectBehavior +class SyliusLegacyClientSpec extends ObjectBehavior { public function let( - Authentication $authentication, + LegacyAuthentication $authentication, Api\CartsApiInterface $cartsApi, Api\ChannelsApiInterface $channelsApi, Api\CountriesApiInterface $countriesApi, @@ -70,8 +70,8 @@ public function let( public function it_is_initializable() { - $this->shouldImplement(SyliusClientInterface::class); - $this->shouldHaveType(SyliusClient::class); + $this->shouldImplement(SyliusLegacyClientInterface::class); + $this->shouldHaveType(SyliusLegacyClient::class); } public function it_gets_access_token($authentication) diff --git a/src/Api/Admin/AddressApi.php b/src/Api/Admin/AddressApi.php new file mode 100644 index 0000000..1602d17 --- /dev/null +++ b/src/Api/Admin/AddressApi.php @@ -0,0 +1,19 @@ +resourceClient->getResource('api/v2/admin/addresses/%d', [$code]); + } +} diff --git a/src/Api/Admin/AddressApiInterface.php b/src/Api/Admin/AddressApiInterface.php new file mode 100644 index 0000000..e190803 --- /dev/null +++ b/src/Api/Admin/AddressApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/adjustments/%d', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/admin/order-items/%s/adjustments', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/AdjustmentApiInterface.php b/src/Api/Admin/AdjustmentApiInterface.php new file mode 100644 index 0000000..cb04e34 --- /dev/null +++ b/src/Api/Admin/AdjustmentApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/admin/administrators/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/administrators', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/administrators'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/admin/administrators/%d', [$code], $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/admin/administrators/%d', [$code]); + } +} diff --git a/src/Api/Admin/AdministratorApiInterface.php b/src/Api/Admin/AdministratorApiInterface.php new file mode 100644 index 0000000..0ef12ce --- /dev/null +++ b/src/Api/Admin/AdministratorApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/avatar-images/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/avatar-images', [], $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/admin/avatar-images/%d', [$code]); + } +} diff --git a/src/Api/Admin/AvatarImageApiInterface.php b/src/Api/Admin/AvatarImageApiInterface.php new file mode 100644 index 0000000..36d3e8b --- /dev/null +++ b/src/Api/Admin/AvatarImageApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->getResource('api/v2/admin/catalog-promotions/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/catalog-promotions', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/catalog-promotions'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/admin/catalog-promotions/%d', [$code], $data); + } +} diff --git a/src/Api/Admin/CatalogPromotionApiInterface.php b/src/Api/Admin/CatalogPromotionApiInterface.php new file mode 100644 index 0000000..57ee805 --- /dev/null +++ b/src/Api/Admin/CatalogPromotionApiInterface.php @@ -0,0 +1,12 @@ +resourceClient->getResource('api/v2/admin/catalog-promotion-translations/%d', [$code]); + } +} diff --git a/src/Api/Admin/CatalogPromotionTranslationApiInterface.php b/src/Api/Admin/CatalogPromotionTranslationApiInterface.php new file mode 100644 index 0000000..2c06e32 --- /dev/null +++ b/src/Api/Admin/CatalogPromotionTranslationApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/channels/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/channels', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/channels'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/channels/%d', [$code]); + } +} diff --git a/src/Api/Admin/ChannelApiInterface.php b/src/Api/Admin/ChannelApiInterface.php new file mode 100644 index 0000000..3d75a81 --- /dev/null +++ b/src/Api/Admin/ChannelApiInterface.php @@ -0,0 +1,12 @@ +resourceClient->getResource('api/v2/admin/countries/%s', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/countries', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/countries', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/countries/%s', [$code]); + } +} diff --git a/src/Api/Admin/CountryApiInterface.php b/src/Api/Admin/CountryApiInterface.php new file mode 100644 index 0000000..566b2b7 --- /dev/null +++ b/src/Api/Admin/CountryApiInterface.php @@ -0,0 +1,12 @@ +resourceClient->getResource('api/v2/admin/currencies/%s', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/currencies', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/currencies', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/countries/%s', [$code]); + } +} diff --git a/src/Api/Admin/CurrencyApiInterface.php b/src/Api/Admin/CurrencyApiInterface.php new file mode 100644 index 0000000..3697b15 --- /dev/null +++ b/src/Api/Admin/CurrencyApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->getResource('api/v2/admin/customer/%d', [$code]); + } +} diff --git a/src/Api/Admin/CustomerApiInterface.php b/src/Api/Admin/CustomerApiInterface.php new file mode 100644 index 0000000..61fce63 --- /dev/null +++ b/src/Api/Admin/CustomerApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/customer-groups/%s', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/customer-groups', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/customer-groups', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/customer-groups/%s', [$code], $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/customer-groups/%s', [$code]); + } +} diff --git a/src/Api/Admin/CustomerGroupApiInterface.php b/src/Api/Admin/CustomerGroupApiInterface.php new file mode 100644 index 0000000..3a75ba6 --- /dev/null +++ b/src/Api/Admin/CustomerGroupApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/exchange-rates/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/exchange-rates', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/exchange-rates', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/admin/exchange-rates/%d', [$code], $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/admin/exchange-rates/%d', [$code]); + } +} diff --git a/src/Api/Admin/ExchangeRateApiInterface.php b/src/Api/Admin/ExchangeRateApiInterface.php new file mode 100644 index 0000000..e6bd2c1 --- /dev/null +++ b/src/Api/Admin/ExchangeRateApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/exchange-rates/%s', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/exchange-rates', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/exchange-rates', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/LocaleApiInterface.php b/src/Api/Admin/LocaleApiInterface.php new file mode 100644 index 0000000..f0f83ab --- /dev/null +++ b/src/Api/Admin/LocaleApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->getResource('api/v2/admin/order-items/%d', [$code]); + } +} diff --git a/src/Api/Admin/OrderItemApiInterface.php b/src/Api/Admin/OrderItemApiInterface.php new file mode 100644 index 0000000..5f90dc2 --- /dev/null +++ b/src/Api/Admin/OrderItemApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/order-item-units/%d', [$code]); + } +} diff --git a/src/Api/Admin/OrderItemUnitApiInterface.php b/src/Api/Admin/OrderItemUnitApiInterface.php new file mode 100644 index 0000000..2a3e669 --- /dev/null +++ b/src/Api/Admin/OrderItemUnitApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/provinces/%s', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/countries/%d/provinces', [$code], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + Assert::string($code); + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/provinces/%d', [$code], $data); + } +} diff --git a/src/Api/Admin/ProvinceApiInterface.php b/src/Api/Admin/ProvinceApiInterface.php new file mode 100644 index 0000000..1c73cd1 --- /dev/null +++ b/src/Api/Admin/ProvinceApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->getResource('api/v2/admin/shop-billing-datas/%d', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/admin/channels/%s/shop-billing-data', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/ShopBillingDataApiInterface.php b/src/Api/Admin/ShopBillingDataApiInterface.php new file mode 100644 index 0000000..62e2530 --- /dev/null +++ b/src/Api/Admin/ShopBillingDataApiInterface.php @@ -0,0 +1,10 @@ +resourceClient = $resourceClient; } - public function setPageFactory(PageFactoryInterface $pageFactory) + public function setPageFactory(PageFactoryInterface $pageFactory): void { $this->pageFactory = $pageFactory; } - public function setCursorFactory(ResourceCursorFactoryInterface $cursorFactory) + public function setCursorFactory(ResourceCursorFactoryInterface $cursorFactory): void { $this->cursorFactory = $cursorFactory; } - public function setFileSystem(FileSystemInterface $fileSystem) + public function setFileSystem(FileSystemInterface $fileSystem): void { $this->fileSystem = $fileSystem; } diff --git a/src/Api/Legacy/AuthenticationApi.php b/src/Api/Legacy/AuthenticationApi.php new file mode 100644 index 0000000..ae25e84 --- /dev/null +++ b/src/Api/Legacy/AuthenticationApi.php @@ -0,0 +1,82 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient\Api\Legacy; + +use Diglin\Sylius\ApiClient\Client\HttpClient; +use Diglin\Sylius\ApiClient\Routing\UriGeneratorInterface; + +/** + * API implementation to manage the authentication. + * + * @author Alexandre Hocquard + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @deprecated + */ +final class AuthenticationApi implements AuthenticationApiInterface +{ + public const TOKEN_URI = 'api/oauth/v2/token'; + + public function __construct( + private HttpClient $httpClient, + private UriGeneratorInterface $uriGenerator + ) {} + + /** + * {@inheritdoc} + */ + public function authenticateByPassword(string $clientId, string $secret, string $username, string $password): array + { + $requestBody = [ + 'grant_type' => 'password', + 'username' => $username, + 'password' => $password, + 'client_id' => $clientId, + 'client_secret' => $secret, + ]; + + return $this->authenticate($requestBody); + } + + /** + * {@inheritdoc} + */ + public function authenticateByRefreshToken(string $clientId, string $secret, string $refreshToken): array + { + $requestBody = [ + 'grant_type' => 'refresh_token', + 'refresh_token' => $refreshToken, + ]; + + return $this->authenticate($requestBody); + } + + /** + * Authenticates the client by requesting the access token and the refresh token. + * + * @param array $requestBody body of the request to authenticate + * + * @return array returns the body of the response containing access token and refresh token + */ + protected function authenticate(array $requestBody) + { + $headers = [ + 'Content-Type' => 'application/json', + ]; + + $uri = $this->uriGenerator->generate(static::TOKEN_URI); + + $response = $this->httpClient->sendRequest('POST', $uri, $headers, json_encode($requestBody)); + + return json_decode($response->getBody()->getContents(), true); + } +} diff --git a/src/Api/Legacy/AuthenticationApiInterface.php b/src/Api/Legacy/AuthenticationApiInterface.php new file mode 100644 index 0000000..8ee7f57 --- /dev/null +++ b/src/Api/Legacy/AuthenticationApiInterface.php @@ -0,0 +1,33 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient\Api\Legacy; + +/** + * API to manage the authentication. + * + * @author Alexandre Hocquard + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @deprecated + */ +interface AuthenticationApiInterface +{ + /** + * Authenticates with the password grant type. + */ + public function authenticateByPassword(string $clientId, string $secret, string $username, string $password): array; + + /** + * Authenticates with the refresh token grant type. + */ + public function authenticateByRefreshToken(string $clientId, string $secret, string $refreshToken): array; +} diff --git a/src/Api/CartsApi.php b/src/Api/Legacy/CartsApi.php similarity index 83% rename from src/Api/CartsApi.php rename to src/Api/Legacy/CartsApi.php index 8260dd2..7c6b02d 100644 --- a/src/Api/CartsApi.php +++ b/src/Api/Legacy/CartsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class CartsApi implements CartsApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/CartsApiInterface.php b/src/Api/Legacy/CartsApiInterface.php similarity index 84% rename from src/Api/CartsApiInterface.php rename to src/Api/Legacy/CartsApiInterface.php index a643fb0..30accd3 100644 --- a/src/Api/CartsApiInterface.php +++ b/src/Api/Legacy/CartsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface CartsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/ChannelsApi.php b/src/Api/Legacy/ChannelsApi.php similarity index 83% rename from src/Api/ChannelsApi.php rename to src/Api/Legacy/ChannelsApi.php index 65f3720..96fd9f0 100644 --- a/src/Api/ChannelsApi.php +++ b/src/Api/Legacy/ChannelsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ChannelsApi implements ChannelsApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ChannelsApiInterface.php b/src/Api/Legacy/ChannelsApiInterface.php similarity index 84% rename from src/Api/ChannelsApiInterface.php rename to src/Api/Legacy/ChannelsApiInterface.php index 34eab4c..75be301 100644 --- a/src/Api/ChannelsApiInterface.php +++ b/src/Api/Legacy/ChannelsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ChannelsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/CountriesApi.php b/src/Api/Legacy/CountriesApi.php similarity index 83% rename from src/Api/CountriesApi.php rename to src/Api/Legacy/CountriesApi.php index 8be4428..eb99998 100644 --- a/src/Api/CountriesApi.php +++ b/src/Api/Legacy/CountriesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class CountriesApi implements CountriesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/CountriesApiInterface.php b/src/Api/Legacy/CountriesApiInterface.php similarity index 84% rename from src/Api/CountriesApiInterface.php rename to src/Api/Legacy/CountriesApiInterface.php index c01ec73..60bb7e8 100644 --- a/src/Api/CountriesApiInterface.php +++ b/src/Api/Legacy/CountriesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface CountriesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/CurrenciesApi.php b/src/Api/Legacy/CurrenciesApi.php similarity index 83% rename from src/Api/CurrenciesApi.php rename to src/Api/Legacy/CurrenciesApi.php index f341338..d6656b1 100644 --- a/src/Api/CurrenciesApi.php +++ b/src/Api/Legacy/CurrenciesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class CurrenciesApi implements CurrenciesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/CurrenciesApiInterface.php b/src/Api/Legacy/CurrenciesApiInterface.php similarity index 84% rename from src/Api/CurrenciesApiInterface.php rename to src/Api/Legacy/CurrenciesApiInterface.php index 1cc4328..8cea98c 100644 --- a/src/Api/CurrenciesApiInterface.php +++ b/src/Api/Legacy/CurrenciesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface CurrenciesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/CustomersApi.php b/src/Api/Legacy/CustomersApi.php similarity index 80% rename from src/Api/CustomersApi.php rename to src/Api/Legacy/CustomersApi.php index 2a4b842..9fbb67b 100644 --- a/src/Api/CustomersApi.php +++ b/src/Api/Legacy/CustomersApi.php @@ -9,15 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; -use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class CustomersApi implements CustomersApiInterface { use ApiAwareTrait; @@ -35,57 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * @param int $code - * - * @throws HttpException if the request failed - * - * @return array - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/CustomersApiInterface.php b/src/Api/Legacy/CustomersApiInterface.php similarity index 84% rename from src/Api/CustomersApiInterface.php rename to src/Api/Legacy/CustomersApiInterface.php index 51c118d..fa78417 100644 --- a/src/Api/CustomersApiInterface.php +++ b/src/Api/Legacy/CustomersApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface CustomersApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/ExchangeRatesApi.php b/src/Api/Legacy/ExchangeRatesApi.php similarity index 83% rename from src/Api/ExchangeRatesApi.php rename to src/Api/Legacy/ExchangeRatesApi.php index 3761eaa..e34f413 100644 --- a/src/Api/ExchangeRatesApi.php +++ b/src/Api/Legacy/ExchangeRatesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ExchangeRatesApi implements ExchangeRatesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ExchangeRatesApiInterface.php b/src/Api/Legacy/ExchangeRatesApiInterface.php similarity index 84% rename from src/Api/ExchangeRatesApiInterface.php rename to src/Api/Legacy/ExchangeRatesApiInterface.php index c6983de..3580e2e 100644 --- a/src/Api/ExchangeRatesApiInterface.php +++ b/src/Api/Legacy/ExchangeRatesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ExchangeRatesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/LocalesApi.php b/src/Api/Legacy/LocalesApi.php similarity index 83% rename from src/Api/LocalesApi.php rename to src/Api/Legacy/LocalesApi.php index 97c756d..5d33092 100644 --- a/src/Api/LocalesApi.php +++ b/src/Api/Legacy/LocalesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class LocalesApi implements LocalesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/LocalesApiInterface.php b/src/Api/Legacy/LocalesApiInterface.php similarity index 84% rename from src/Api/LocalesApiInterface.php rename to src/Api/Legacy/LocalesApiInterface.php index f5103c8..3e1c27e 100644 --- a/src/Api/LocalesApiInterface.php +++ b/src/Api/Legacy/LocalesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface LocalesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/OrdersApi.php b/src/Api/Legacy/OrdersApi.php similarity index 83% rename from src/Api/OrdersApi.php rename to src/Api/Legacy/OrdersApi.php index fb9c5e1..1fdfc42 100644 --- a/src/Api/OrdersApi.php +++ b/src/Api/Legacy/OrdersApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class OrdersApi implements OrdersApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/OrdersApiInterface.php b/src/Api/Legacy/OrdersApiInterface.php similarity index 84% rename from src/Api/OrdersApiInterface.php rename to src/Api/Legacy/OrdersApiInterface.php index 512edbd..657a87c 100644 --- a/src/Api/OrdersApiInterface.php +++ b/src/Api/Legacy/OrdersApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface OrdersApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/PaymentMethodsApi.php b/src/Api/Legacy/PaymentMethodsApi.php similarity index 85% rename from src/Api/PaymentMethodsApi.php rename to src/Api/Legacy/PaymentMethodsApi.php index 1e73129..ecdb5bf 100644 --- a/src/Api/PaymentMethodsApi.php +++ b/src/Api/Legacy/PaymentMethodsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class PaymentMethodsApi implements PaymentMethodsApiInterface { use ApiAwareTrait; @@ -34,37 +38,28 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/PaymentMethodsApiInterface.php b/src/Api/Legacy/PaymentMethodsApiInterface.php similarity index 79% rename from src/Api/PaymentMethodsApiInterface.php rename to src/Api/Legacy/PaymentMethodsApiInterface.php index d5daea2..0a9dc66 100644 --- a/src/Api/PaymentMethodsApiInterface.php +++ b/src/Api/Legacy/PaymentMethodsApiInterface.php @@ -9,11 +9,13 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface PaymentMethodsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/PaymentsApi.php b/src/Api/Legacy/PaymentsApi.php similarity index 85% rename from src/Api/PaymentsApi.php rename to src/Api/Legacy/PaymentsApi.php index 4b68728..33c0394 100644 --- a/src/Api/PaymentsApi.php +++ b/src/Api/Legacy/PaymentsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class PaymentsApi implements PaymentsApiInterface { use ApiAwareTrait; @@ -34,37 +38,28 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/PaymentsApiInterface.php b/src/Api/Legacy/PaymentsApiInterface.php similarity index 79% rename from src/Api/PaymentsApiInterface.php rename to src/Api/Legacy/PaymentsApiInterface.php index 2ae4362..5c44e7b 100644 --- a/src/Api/PaymentsApiInterface.php +++ b/src/Api/Legacy/PaymentsApiInterface.php @@ -9,11 +9,13 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface PaymentsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/ProductAssociationTypesApi.php b/src/Api/Legacy/ProductAssociationTypesApi.php similarity index 83% rename from src/Api/ProductAssociationTypesApi.php rename to src/Api/Legacy/ProductAssociationTypesApi.php index ee39d6c..a7d0398 100644 --- a/src/Api/ProductAssociationTypesApi.php +++ b/src/Api/Legacy/ProductAssociationTypesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ProductAssociationTypesApi implements ProductAssociationTypesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ProductAssociationTypesApiInterface.php b/src/Api/Legacy/ProductAssociationTypesApiInterface.php similarity index 85% rename from src/Api/ProductAssociationTypesApiInterface.php rename to src/Api/Legacy/ProductAssociationTypesApiInterface.php index 5471ecc..1fe35ca 100644 --- a/src/Api/ProductAssociationTypesApiInterface.php +++ b/src/Api/Legacy/ProductAssociationTypesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ProductAssociationTypesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, CreatableResourceInterface, DeletableResourceInterface { } diff --git a/src/Api/ProductAttributesApi.php b/src/Api/Legacy/ProductAttributesApi.php similarity index 83% rename from src/Api/ProductAttributesApi.php rename to src/Api/Legacy/ProductAttributesApi.php index c7b3472..72c2d44 100644 --- a/src/Api/ProductAttributesApi.php +++ b/src/Api/Legacy/ProductAttributesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ProductAttributesApi implements ProductAttributesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ProductAttributesApiInterface.php b/src/Api/Legacy/ProductAttributesApiInterface.php similarity index 84% rename from src/Api/ProductAttributesApiInterface.php rename to src/Api/Legacy/ProductAttributesApiInterface.php index 4cb8ff2..05229bf 100644 --- a/src/Api/ProductAttributesApiInterface.php +++ b/src/Api/Legacy/ProductAttributesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ProductAttributesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, CreatableResourceInterface, DeletableResourceInterface { } diff --git a/src/Api/ProductOptionsApi.php b/src/Api/Legacy/ProductOptionsApi.php similarity index 83% rename from src/Api/ProductOptionsApi.php rename to src/Api/Legacy/ProductOptionsApi.php index 7d5e351..28b13bc 100644 --- a/src/Api/ProductOptionsApi.php +++ b/src/Api/Legacy/ProductOptionsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ProductOptionsApi implements ProductOptionsApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ProductOptionsApiInterface.php b/src/Api/Legacy/ProductOptionsApiInterface.php similarity index 84% rename from src/Api/ProductOptionsApiInterface.php rename to src/Api/Legacy/ProductOptionsApiInterface.php index ecda171..6640345 100644 --- a/src/Api/ProductOptionsApiInterface.php +++ b/src/Api/Legacy/ProductOptionsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ProductOptionsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, CreatableResourceInterface, DeletableResourceInterface { } diff --git a/src/Api/ProductReviewsApi.php b/src/Api/Legacy/ProductReviewsApi.php similarity index 83% rename from src/Api/ProductReviewsApi.php rename to src/Api/Legacy/ProductReviewsApi.php index e959ca0..34d7e70 100644 --- a/src/Api/ProductReviewsApi.php +++ b/src/Api/Legacy/ProductReviewsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ProductReviewsApi implements ProductReviewsApiInterface { use ApiAwareTrait; @@ -34,52 +38,40 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - public function get($productCode, $id) + public function get($productCode, $id): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$productCode, $id]); } - /** - * {@inheritdoc} - */ - public function create($productCode, array $data = []) + public function create($productCode, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$productCode], $data); } - /** - * {@inheritdoc} - */ - public function delete($productCode, $id) + public function delete($productCode, $id): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$productCode, $id]); } - /** - * {@inheritdoc} - */ public function all( string $productCode, $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($productCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( string $productCode, $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$productCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ProductReviewsApiInterface.php b/src/Api/Legacy/ProductReviewsApiInterface.php similarity index 85% rename from src/Api/ProductReviewsApiInterface.php rename to src/Api/Legacy/ProductReviewsApiInterface.php index d2c6466..f12f3d0 100644 --- a/src/Api/ProductReviewsApiInterface.php +++ b/src/Api/Legacy/ProductReviewsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableDoubleResourceInterface; +/** @deprecated */ interface ProductReviewsApiInterface extends ApiAwareInterface, CreatableResourceInterface, GettableDoubleResourceInterface, ListableDoubleResourceInterface, DeletableDoubleResourceInterface { } diff --git a/src/Api/ProductVariantsApi.php b/src/Api/Legacy/ProductVariantsApi.php similarity index 81% rename from src/Api/ProductVariantsApi.php rename to src/Api/Legacy/ProductVariantsApi.php index 88cdfab..d2cbaf4 100644 --- a/src/Api/ProductVariantsApi.php +++ b/src/Api/Legacy/ProductVariantsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ProductVariantsApi implements ProductVariantsApiInterface { use ApiAwareTrait; @@ -34,55 +38,40 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($productCode, $variantCode) + public function get($productCode, $variantCode): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$productCode, $variantCode]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($productCode, $variantCode) + public function delete($productCode, $variantCode): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$productCode, $variantCode]); } - /** - * {@inheritdoc} - */ public function all( - string $productCode, + $productCode, $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($productCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( - string $productCode, + $productCode, $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$productCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ProductVariantsApiInterface.php b/src/Api/Legacy/ProductVariantsApiInterface.php similarity index 85% rename from src/Api/ProductVariantsApiInterface.php rename to src/Api/Legacy/ProductVariantsApiInterface.php index 927e0ed..9dc6cbd 100644 --- a/src/Api/ProductVariantsApiInterface.php +++ b/src/Api/Legacy/ProductVariantsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableDoubleResourceInterface; +/** @deprecated */ interface ProductVariantsApiInterface extends ApiAwareInterface, CreatableResourceInterface, GettableDoubleResourceInterface, ListableDoubleResourceInterface, DeletableDoubleResourceInterface { } diff --git a/src/Api/ProductsApi.php b/src/Api/Legacy/ProductsApi.php similarity index 82% rename from src/Api/ProductsApi.php rename to src/Api/Legacy/ProductsApi.php index d1f111f..0358164 100644 --- a/src/Api/ProductsApi.php +++ b/src/Api/Legacy/ProductsApi.php @@ -9,15 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; -use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ProductsApi implements ProductsApiInterface { use ApiAwareTrait; @@ -35,58 +38,43 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - public function upsert($code, array $data = []) + public function upsert($code, array $data = []): int { return $this->resourceClient->upsertResource(static::ENDPOINT_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ProductsApiInterface.php b/src/Api/Legacy/ProductsApiInterface.php similarity index 86% rename from src/Api/ProductsApiInterface.php rename to src/Api/Legacy/ProductsApiInterface.php index e2f3c22..37a2752 100644 --- a/src/Api/ProductsApiInterface.php +++ b/src/Api/Legacy/ProductsApiInterface.php @@ -9,14 +9,16 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\UpsertableResourceInterface; +/** @deprecated */ interface ProductsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface, UpsertableResourceInterface { } diff --git a/src/Api/PromotionCouponsApi.php b/src/Api/Legacy/PromotionCouponsApi.php similarity index 81% rename from src/Api/PromotionCouponsApi.php rename to src/Api/Legacy/PromotionCouponsApi.php index 65bb341..965d840 100644 --- a/src/Api/PromotionCouponsApi.php +++ b/src/Api/Legacy/PromotionCouponsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class PromotionCouponsApi implements PromotionCouponsApiInterface { use ApiAwareTrait; @@ -34,55 +38,40 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($promotionCode, $couponCode) + public function get($promotionCode, $couponCode): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$promotionCode, $couponCode]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($promotionCode, $couponCode) + public function delete($promotionCode, $couponCode): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$promotionCode, $couponCode]); } - /** - * {@inheritdoc} - */ public function all( - string $promotionCode, + $promotionCode, $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($promotionCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( - string $promotionCode, + $promotionCode, $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$promotionCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/PromotionCouponsApiInterface.php b/src/Api/Legacy/PromotionCouponsApiInterface.php similarity index 85% rename from src/Api/PromotionCouponsApiInterface.php rename to src/Api/Legacy/PromotionCouponsApiInterface.php index 78cac06..ad47410 100644 --- a/src/Api/PromotionCouponsApiInterface.php +++ b/src/Api/Legacy/PromotionCouponsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableDoubleResourceInterface; +/** @deprecated */ interface PromotionCouponsApiInterface extends ApiAwareInterface, GettableDoubleResourceInterface, ListableDoubleResourceInterface, DeletableDoubleResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/PromotionsApi.php b/src/Api/Legacy/PromotionsApi.php similarity index 83% rename from src/Api/PromotionsApi.php rename to src/Api/Legacy/PromotionsApi.php index ed1e895..f79b3d5 100644 --- a/src/Api/PromotionsApi.php +++ b/src/Api/Legacy/PromotionsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class PromotionsApi implements PromotionsApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/PromotionsApiInterface.php b/src/Api/Legacy/PromotionsApiInterface.php similarity index 84% rename from src/Api/PromotionsApiInterface.php rename to src/Api/Legacy/PromotionsApiInterface.php index 9c4e8d3..87e02b6 100644 --- a/src/Api/PromotionsApiInterface.php +++ b/src/Api/Legacy/PromotionsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface PromotionsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/ShipmentsApi.php b/src/Api/Legacy/ShipmentsApi.php similarity index 83% rename from src/Api/ShipmentsApi.php rename to src/Api/Legacy/ShipmentsApi.php index d8540e5..c9d9a60 100644 --- a/src/Api/ShipmentsApi.php +++ b/src/Api/Legacy/ShipmentsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ShipmentsApi implements ShipmentsApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ShipmentsApiInterface.php b/src/Api/Legacy/ShipmentsApiInterface.php similarity index 84% rename from src/Api/ShipmentsApiInterface.php rename to src/Api/Legacy/ShipmentsApiInterface.php index d22448e..7b794c5 100644 --- a/src/Api/ShipmentsApiInterface.php +++ b/src/Api/Legacy/ShipmentsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ShipmentsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/ShippingCategoriesApi.php b/src/Api/Legacy/ShippingCategoriesApi.php similarity index 85% rename from src/Api/ShippingCategoriesApi.php rename to src/Api/Legacy/ShippingCategoriesApi.php index 59b1d97..b4a5314 100644 --- a/src/Api/ShippingCategoriesApi.php +++ b/src/Api/Legacy/ShippingCategoriesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ShippingCategoriesApi implements ShippingCategoriesApiInterface { use ApiAwareTrait; @@ -34,37 +38,28 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ShippingCategoriesApiInterface.php b/src/Api/Legacy/ShippingCategoriesApiInterface.php similarity index 79% rename from src/Api/ShippingCategoriesApiInterface.php rename to src/Api/Legacy/ShippingCategoriesApiInterface.php index 283f348..3919b8a 100644 --- a/src/Api/ShippingCategoriesApiInterface.php +++ b/src/Api/Legacy/ShippingCategoriesApiInterface.php @@ -9,11 +9,13 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ShippingCategoriesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/TaxCategoriesApi.php b/src/Api/Legacy/TaxCategoriesApi.php similarity index 83% rename from src/Api/TaxCategoriesApi.php rename to src/Api/Legacy/TaxCategoriesApi.php index bb3136b..53d7064 100644 --- a/src/Api/TaxCategoriesApi.php +++ b/src/Api/Legacy/TaxCategoriesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class TaxCategoriesApi implements TaxCategoriesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/TaxCategoriesApiInterface.php b/src/Api/Legacy/TaxCategoriesApiInterface.php similarity index 84% rename from src/Api/TaxCategoriesApiInterface.php rename to src/Api/Legacy/TaxCategoriesApiInterface.php index 731aa98..b7bf319 100644 --- a/src/Api/TaxCategoriesApiInterface.php +++ b/src/Api/Legacy/TaxCategoriesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface TaxCategoriesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/TaxRatesApi.php b/src/Api/Legacy/TaxRatesApi.php similarity index 85% rename from src/Api/TaxRatesApi.php rename to src/Api/Legacy/TaxRatesApi.php index 41a062b..2ce4868 100644 --- a/src/Api/TaxRatesApi.php +++ b/src/Api/Legacy/TaxRatesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class TaxRatesApi implements TaxRatesApiInterface { use ApiAwareTrait; @@ -34,37 +38,28 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/TaxRatesApiInterface.php b/src/Api/Legacy/TaxRatesApiInterface.php similarity index 79% rename from src/Api/TaxRatesApiInterface.php rename to src/Api/Legacy/TaxRatesApiInterface.php index 50be7df..3df09f5 100644 --- a/src/Api/TaxRatesApiInterface.php +++ b/src/Api/Legacy/TaxRatesApiInterface.php @@ -9,11 +9,13 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface TaxRatesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/TaxonsApi.php b/src/Api/Legacy/TaxonsApi.php similarity index 83% rename from src/Api/TaxonsApi.php rename to src/Api/Legacy/TaxonsApi.php index 5b9e3e0..f6807d4 100644 --- a/src/Api/TaxonsApi.php +++ b/src/Api/Legacy/TaxonsApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class TaxonsApi implements TaxonsApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/TaxonsApiInterface.php b/src/Api/Legacy/TaxonsApiInterface.php similarity index 84% rename from src/Api/TaxonsApiInterface.php rename to src/Api/Legacy/TaxonsApiInterface.php index dd7b16b..38282ac 100644 --- a/src/Api/TaxonsApiInterface.php +++ b/src/Api/Legacy/TaxonsApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface TaxonsApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/UsersApi.php b/src/Api/Legacy/UsersApi.php similarity index 83% rename from src/Api/UsersApi.php rename to src/Api/Legacy/UsersApi.php index 681fbe0..8974d79 100644 --- a/src/Api/UsersApi.php +++ b/src/Api/Legacy/UsersApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class UsersApi implements UsersApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/UsersApiInterface.php b/src/Api/Legacy/UsersApiInterface.php similarity index 84% rename from src/Api/UsersApiInterface.php rename to src/Api/Legacy/UsersApiInterface.php index 558fff3..bf5297b 100644 --- a/src/Api/UsersApiInterface.php +++ b/src/Api/Legacy/UsersApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface UsersApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/ZonesApi.php b/src/Api/Legacy/ZonesApi.php similarity index 83% rename from src/Api/ZonesApi.php rename to src/Api/Legacy/ZonesApi.php index eeb82ab..55d67ac 100644 --- a/src/Api/ZonesApi.php +++ b/src/Api/Legacy/ZonesApi.php @@ -9,14 +9,18 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareTrait; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +/** @deprecated */ class ZonesApi implements ZonesApiInterface { use ApiAwareTrait; @@ -34,53 +38,38 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - /** - * {@inheritdoc} - */ - public function get($code) + public function get($code): array { return $this->resourceClient->getResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ - public function create($code, array $data = []) + public function create($code, array $data = []): int { return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - /** - * {@inheritdoc} - */ - public function delete($code) + public function delete($code): int { return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$code]); } - /** - * {@inheritdoc} - */ public function all( $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): ResourceCursorInterface { $firstPage = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } - /** - * {@inheritdoc} - */ public function listPerPage( $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): PageInterface { $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); diff --git a/src/Api/ZonesApiInterface.php b/src/Api/Legacy/ZonesApiInterface.php similarity index 84% rename from src/Api/ZonesApiInterface.php rename to src/Api/Legacy/ZonesApiInterface.php index 9100e5e..bd938c1 100644 --- a/src/Api/ZonesApiInterface.php +++ b/src/Api/Legacy/ZonesApiInterface.php @@ -9,13 +9,15 @@ * @copyright 2020 - Diglin (https://www.diglin.com) */ -namespace Diglin\Sylius\ApiClient\Api; +namespace Diglin\Sylius\ApiClient\Api\Legacy; +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +/** @deprecated */ interface ZonesApiInterface extends ApiAwareInterface, GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/Operation/CreatableResourceInterface.php b/src/Api/Operation/CreatableResourceInterface.php index d9366eb..20011c0 100644 --- a/src/Api/Operation/CreatableResourceInterface.php +++ b/src/Api/Operation/CreatableResourceInterface.php @@ -17,13 +17,13 @@ interface CreatableResourceInterface /** * Creates a resource. * - * @param string $code code of the resource to create - * @param array $data data of the resource to create + * @param string|int $code code of the resource to create + * @param array $data data of the resource to create * * @throws HttpException if the request failed * @throws InvalidArgumentException if the parameter "code" is defined in the data parameter * * @return int status code 201 indicating that the resource has been well created */ - public function create($code, array $data = []); + public function create($code, array $data = []): int; } diff --git a/src/Api/Operation/DeletableDoubleResourceInterface.php b/src/Api/Operation/DeletableDoubleResourceInterface.php index 632b41f..4af5a0a 100644 --- a/src/Api/Operation/DeletableDoubleResourceInterface.php +++ b/src/Api/Operation/DeletableDoubleResourceInterface.php @@ -9,12 +9,12 @@ interface DeletableDoubleResourceInterface /** * Deletes a resource. * - * @param mixed $code code of the parent resource - * @param mixed $id code or id of the resource to get + * @param string|int $code code of the parent resource + * @param string|int $id code or id of the resource to get * * @throws HttpException * * @return int status code 204 indicating that the resource has been well deleted */ - public function delete($code, $id); + public function delete($code, string|int $id): int; } diff --git a/src/Api/Operation/DeletableResourceInterface.php b/src/Api/Operation/DeletableResourceInterface.php index d514138..6bfabaa 100644 --- a/src/Api/Operation/DeletableResourceInterface.php +++ b/src/Api/Operation/DeletableResourceInterface.php @@ -16,11 +16,11 @@ interface DeletableResourceInterface /** * Deletes a resource. * - * @param mixed $code code or id of the resource to delete + * @param string|int $code code or id of the resource to delete * * @throws HttpException * * @return int status code 204 indicating that the resource has been well deleted */ - public function delete($code); + public function delete($code): int; } diff --git a/src/Api/Operation/DownloadableResourceInterface.php b/src/Api/Operation/DownloadableResourceInterface.php index a21a548..d1c059d 100644 --- a/src/Api/Operation/DownloadableResourceInterface.php +++ b/src/Api/Operation/DownloadableResourceInterface.php @@ -17,11 +17,11 @@ interface DownloadableResourceInterface /** * Downloads a resource by its code. * - * @param string $code Code of the resource + * @param string|int $code Code of the resource * * @throws HttpException * * @return StreamInterface */ - public function download($code); + public function download($code): StreamInterface; } diff --git a/src/Api/Operation/GettableDoubleResourceInterface.php b/src/Api/Operation/GettableDoubleResourceInterface.php index bd3523c..594a98f 100644 --- a/src/Api/Operation/GettableDoubleResourceInterface.php +++ b/src/Api/Operation/GettableDoubleResourceInterface.php @@ -9,12 +9,10 @@ interface GettableDoubleResourceInterface /** * Gets a resource by its code. * - * @param mixed $code code of the parent resource - * @param mixed $id code or id of the resource to get + * @param string|int $code code of the parent resource + * @param string|int $id code or id of the resource to get * * @throws HttpException if the request failed - * - * @return array */ - public function get($code, $id); + public function get($code, $id): array; } diff --git a/src/Api/Operation/GettableResourceInterface.php b/src/Api/Operation/GettableResourceInterface.php index decf67c..39ae6d6 100644 --- a/src/Api/Operation/GettableResourceInterface.php +++ b/src/Api/Operation/GettableResourceInterface.php @@ -16,11 +16,9 @@ interface GettableResourceInterface /** * Gets a resource by its code. * - * @param string $code Code of the resource + * @param string|int $code Code of the resource * * @throws HttpException if the request failed - * - * @return array */ - public function get($code); + public function get($code): array; } diff --git a/src/Api/Operation/ListableDoubleResourceInterface.php b/src/Api/Operation/ListableDoubleResourceInterface.php index 377103a..2e6ad52 100644 --- a/src/Api/Operation/ListableDoubleResourceInterface.php +++ b/src/Api/Operation/ListableDoubleResourceInterface.php @@ -14,7 +14,7 @@ interface ListableDoubleResourceInterface * Gets a list of resources by returning the first page. * Consequently, this method does not return all the resources. * - * @param mixed $code code of the parent resource + * @param string|int $code code of the parent resource * @param int $limit The maximum number of resources to return. * Do note that the server has a maximum limit allowed. * @param array $queryParameters additional query parameters to pass in the request @@ -24,28 +24,28 @@ interface ListableDoubleResourceInterface * @return PageInterface */ public function listPerPage( - string $code, - $limit = 10, + $code, + int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): PageInterface; /** * Gets a cursor to iterate over a list of resources. * - * @param mixed $code code of the parent resource - * @param int $pageSize The size of the page returned by the server. - * Do note that the server has a maximum limit allowed. - * @param array $queryParameters Additional query parameters to pass in the request + * @param string|int $code code of the parent resource + * @param int $pageSize The size of the page returned by the server. + * Do note that the server has a maximum limit allowed. + * @param array $queryParameters Additional query parameters to pass in the request * * @return ResourceCursorInterface */ public function all( - string $code, - $pageSize = 10, + $code, + int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): ResourceCursorInterface; } diff --git a/src/Api/Operation/ListableResourceInterface.php b/src/Api/Operation/ListableResourceInterface.php index 692b346..481b188 100644 --- a/src/Api/Operation/ListableResourceInterface.php +++ b/src/Api/Operation/ListableResourceInterface.php @@ -30,11 +30,11 @@ interface ListableResourceInterface * @return PageInterface */ public function listPerPage( - $limit = 10, + int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): PageInterface; /** * Gets a cursor to iterate over a list of resources. @@ -46,9 +46,9 @@ public function listPerPage( * @return ResourceCursorInterface */ public function all( - $pageSize = 10, + int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ); + ): ResourceCursorInterface; } diff --git a/src/Api/Operation/UpsertableResourceInterface.php b/src/Api/Operation/UpsertableResourceInterface.php index 13d9956..5ebe4ef 100644 --- a/src/Api/Operation/UpsertableResourceInterface.php +++ b/src/Api/Operation/UpsertableResourceInterface.php @@ -16,7 +16,7 @@ interface UpsertableResourceInterface /** * Creates a resource if it does not exist yet, otherwise updates partially the resource. * - * @param string $code code of the resource to create or update + * @param string|int $code code of the resource to create or update * @param array $data data of the resource to create or update * * @throws HttpException if the request failed @@ -24,5 +24,5 @@ interface UpsertableResourceInterface * @return int Status code 201 indicating that the resource has been well created. * Status code 204 indicating that the resource has been well updated. */ - public function upsert($code, array $data = []); + public function upsert($code, array $data = []): int; } diff --git a/src/Api/Operation/UpsertableResourceListInterface.php b/src/Api/Operation/UpsertableResourceListInterface.php index ec69ecf..464b118 100644 --- a/src/Api/Operation/UpsertableResourceListInterface.php +++ b/src/Api/Operation/UpsertableResourceListInterface.php @@ -23,5 +23,5 @@ interface UpsertableResourceListInterface * * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted resource */ - public function upsertList($resources); + public function upsertList(array|StreamInterface $resources): \Traversable; } diff --git a/src/Api/Shop/AddressApi.php b/src/Api/Shop/AddressApi.php new file mode 100644 index 0000000..ac45ea5 --- /dev/null +++ b/src/Api/Shop/AddressApi.php @@ -0,0 +1,67 @@ +resourceClient->getResource('api/v2/shop/addresses/%s'); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/addresses'); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/addresses', [], $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/shop/addresses/%d', [$code], $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/shop/addresses/%d', [$code]); + } +} diff --git a/src/Api/Shop/AddressApiInterface.php b/src/Api/Shop/AddressApiInterface.php new file mode 100644 index 0000000..a385157 --- /dev/null +++ b/src/Api/Shop/AddressApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/shop/adjustments/%d'); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/shop/orders/%s/adjustments', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Shop/AdjustmentApiInterface.php b/src/Api/Shop/AdjustmentApiInterface.php new file mode 100644 index 0000000..7f72e92 --- /dev/null +++ b/src/Api/Shop/AdjustmentApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/shop/channels/%d'); + } +} diff --git a/src/Api/Shop/ChannelApiInterface.php b/src/Api/Shop/ChannelApiInterface.php new file mode 100644 index 0000000..5d30953 --- /dev/null +++ b/src/Api/Shop/ChannelApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/shop/countries/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/countries', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Shop/CountryApiInterface.php b/src/Api/Shop/CountryApiInterface.php new file mode 100644 index 0000000..7cd19cd --- /dev/null +++ b/src/Api/Shop/CountryApiInterface.php @@ -0,0 +1,10 @@ + + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class LegacyAuthenticatedHttpClient implements HttpClientInterface +{ + public function __construct( + private HttpClient $basicHttpClient, + private Api\Legacy\AuthenticationApiInterface $authenticationApi, + private LegacyAuthentication $authentication, + ) {} + + /** + * {@inheritdoc} + */ + public function sendRequest($httpMethod, $uri, array $headers = [], $body = null) + { + try { + $xauthtokenDetected = false; + foreach ((array) $this->authentication->getXauthtokenHeader() as $name => $value) { + $headers[$name] = $value; + $xauthtokenDetected = true; + } + + if ($xauthtokenDetected) { + return $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + } + } catch (UnauthorizedHttpException $e) { + // Do nothing and process to standard authentication + } + + if (null === $this->authentication->getAccessToken()) { + $tokens = $this->authenticationApi->authenticateByPassword( + $this->authentication->getClientId(), + $this->authentication->getSecret(), + $this->authentication->getUsername(), + $this->authentication->getPassword() + ); + + $this->authentication + ->setAccessToken($tokens['access_token']) + ->setRefreshToken($tokens['refresh_token']) + ; + } + + try { + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + } catch (UnauthorizedHttpException $e) { + $tokens = $this->authenticationApi->authenticateByRefreshToken( + $this->authentication->getClientId(), + $this->authentication->getSecret(), + $this->authentication->getRefreshToken() + ); + + $this->authentication + ->setAccessToken($tokens['access_token']) + ->setRefreshToken($tokens['refresh_token']) + ; + + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + } + + return $response; + } +} diff --git a/src/Client/ResourceClient.php b/src/Client/ResourceClient.php index 4de9fa6..15ff37a 100644 --- a/src/Client/ResourceClient.php +++ b/src/Client/ResourceClient.php @@ -7,7 +7,9 @@ use Diglin\Sylius\ApiClient\Routing\UriGeneratorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; use Diglin\Sylius\ApiClient\Stream\MultipartStreamBuilderFactory; +use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponse; use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponseFactory; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; /** @@ -19,41 +21,21 @@ */ class ResourceClient implements ResourceClientInterface { - /** @var HttpClientInterface */ - protected $httpClient; - - /** @var UriGeneratorInterface */ - protected $uriGenerator; - - /** @var MultipartStreamBuilderFactory */ - protected $multipartStreamBuilderFactory; - - /** @var UpsertResourceListResponseFactory */ - protected $upsertListResponseFactory; - public function __construct( - HttpClientInterface $httpClient, - UriGeneratorInterface $uriGenerator, - MultipartStreamBuilderFactory $multipartStreamBuilderFactory, - UpsertResourceListResponseFactory $upsertListResponseFactory - ) { - $this->httpClient = $httpClient; - $this->uriGenerator = $uriGenerator; - $this->multipartStreamBuilderFactory = $multipartStreamBuilderFactory; - $this->upsertListResponseFactory = $upsertListResponseFactory; - } + private HttpClientInterface $httpClient, + private UriGeneratorInterface $uriGenerator, + private MultipartStreamBuilderFactory $multipartStreamBuilderFactory, + private UpsertResourceListResponseFactory $upsertListResponseFactory + ) {} - /** - * {@inheritdoc} - */ public function getResources( - $uri, + string|\Stringable $uri, array $uriParameters = [], $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ) { + ): iterable { if (array_key_exists('limit', $queryParameters)) { throw new InvalidArgumentException('The parameter "limit" should not be defined in the additional query parameters'); } @@ -73,25 +55,22 @@ public function getResources( return $this->getResource($uri, $uriParameters, $queryParameters); } - /** - * {@inheritdoc} - */ public function getResource( - $uri, + string|\Stringable $uri, array $uriParameters = [], array $queryParameters = [] - ) { + ): array { $uri = $this->uriGenerator->generate($uri, $uriParameters, $queryParameters); $response = $this->httpClient->sendRequest('GET', $uri, ['Accept' => '*/*']); return json_decode($response->getBody()->getContents(), true); } - /** - * {@inheritdoc} - */ - public function createResource($uri, array $uriParameters = [], array $body = []) - { + public function createResource( + string|\Stringable$uri, + array $uriParameters = [], + array $body = [] + ): int { unset($body['_links']); $uri = $this->uriGenerator->generate($uri, $uriParameters); @@ -105,11 +84,11 @@ public function createResource($uri, array $uriParameters = [], array $body = [] return $response->getStatusCode(); } - /** - * {@inheritdoc} - */ - public function createMultipartResource($uri, array $uriParameters = [], array $requestParts = []) - { + public function createMultipartResource( + string|\Stringable $uri, + array $uriParameters = [], + array $requestParts = [] + ): ResponseInterface { $streamBuilder = $this->multipartStreamBuilderFactory->create(); foreach ($requestParts as $requestPart) { @@ -129,11 +108,11 @@ public function createMultipartResource($uri, array $uriParameters = [], array $ return $this->httpClient->sendRequest('POST', $uri, $headers, $multipartStream); } - /** - * {@inheritdoc} - */ - public function upsertResource($uri, array $uriParameters = [], array $body = []) - { + public function upsertResource( + string|\Stringable $uri, + array $uriParameters = [], + array $body = [] + ): int { unset($body['_links']); $uri = $this->uriGenerator->generate($uri, $uriParameters); @@ -147,11 +126,64 @@ public function upsertResource($uri, array $uriParameters = [], array $body = [] return $response->getStatusCode(); } - /** - * {@inheritdoc} - */ - public function upsertResourceList($uri, array $uriParameters = [], $resources = []) - { + public function upsertResourceList( + string|\Stringable $uri, + array $uriParameters = [], + array|StreamInterface $resources = [] + ): UpsertResourceListResponse { + if (!is_array($resources) && !$resources instanceof StreamInterface) { + throw new InvalidArgumentException('The parameter "resources" must be an array or an instance of StreamInterface.'); + } + + if (is_array($resources)) { + $body = ''; + $isFirstLine = true; + foreach ($resources as $resource) { + if (!is_array($resource)) { + throw new InvalidArgumentException('The parameter "resources" must be an array of array.'); + } + unset($resource['_links']); + $body .= ($isFirstLine ? '' : PHP_EOL).json_encode($resource); + $isFirstLine = false; + } + } else { + $body = $resources; + } + + $uri = $this->uriGenerator->generate($uri, $uriParameters); + $response = $this->httpClient->sendRequest( + 'PATCH', + $uri, + ['Content-Type' => 'application/json'], + $body + ); + + return $this->upsertListResponseFactory->create($response->getBody()); + } + + public function patchResource( + string|\Stringable $uri, + array $uriParameters = [], + array $body = [] + ): int { + unset($body['_links']); + + $uri = $this->uriGenerator->generate($uri, $uriParameters); + $response = $this->httpClient->sendRequest( + 'PATCH', + $uri, + ['Content-Type' => 'application/json'], + json_encode($body) + ); + + return $response->getStatusCode(); + } + + public function patchResourceList( + string|\Stringable $uri, + array $uriParameters = [], + array|StreamInterface $resources = [] + ): PatchResourceListResponse { if (!is_array($resources) && !$resources instanceof StreamInterface) { throw new InvalidArgumentException('The parameter "resources" must be an array or an instance of StreamInterface.'); } @@ -182,11 +214,10 @@ public function upsertResourceList($uri, array $uriParameters = [], $resources = return $this->upsertListResponseFactory->create($response->getBody()); } - /** - * {@inheritdoc} - */ - public function deleteResource($uri, array $uriParameters = []) - { + public function deleteResource( + string|\Stringable $uri, + array $uriParameters = [] + ): int { $uri = $this->uriGenerator->generate($uri, $uriParameters); $response = $this->httpClient->sendRequest('DELETE', $uri); @@ -194,11 +225,10 @@ public function deleteResource($uri, array $uriParameters = []) return $response->getStatusCode(); } - /** - * {@inheritdoc} - */ - public function getStreamedResource($uri, array $uriParameters = []) - { + public function getStreamedResource( + string|\Stringable $uri, + array $uriParameters = [] + ): StreamInterface { $uri = $this->uriGenerator->generate($uri, $uriParameters); $response = $this->httpClient->sendRequest('GET', $uri, ['Accept' => '*/*']); diff --git a/src/Client/ResourceClientInterface.php b/src/Client/ResourceClientInterface.php index 6d149cc..f92e719 100644 --- a/src/Client/ResourceClientInterface.php +++ b/src/Client/ResourceClientInterface.php @@ -6,6 +6,7 @@ use Diglin\Sylius\ApiClient\Exception\InvalidArgumentException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -21,75 +22,75 @@ interface ResourceClientInterface /** * Gets a resource. * - * @param string $uri URI of the resource - * @param array $uriParameters URI parameters of the resource - * @param array $queryParameters Query parameters of the request + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $queryParameters Query parameters of the request * * @throws HttpException if the request failed * * @return array */ - public function getResource($uri, array $uriParameters = [], array $queryParameters = []); + public function getResource(string|\Stringable $uri, array $uriParameters = [], array $queryParameters = []): array; /** * Gets a list of resources. * - * @param string $uri URI of the resource - * @param array $uriParameters URI parameters of the resource - * @param int $limit The maximum number of resources to return. - * Do note that the server has a default value if you don't specify anything. - * The server has a maximum limit allowed as well. - * @param array $queryParameters Additional query parameters of the request + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param int $limit The maximum number of resources to return. + * Do note that the server has a default value if you don't specify anything. + * The server has a maximum limit allowed as well. + * @param array $queryParameters Additional query parameters of the request * - * @return array + * @return list */ - public function getResources($uri, array $uriParameters = [], $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null); + public function getResources(string|\Stringable $uri, array $uriParameters = [], $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null): iterable; /** * Creates a resource. * - * @param string $uri URI of the resource - * @param array $uriParameters URI parameters of the resource - * @param array $body Body of the request + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $body Body of the request * * @throws HttpException if the request failed * * @return int status code 201 indicating that the resource has been well created */ - public function createResource($uri, array $uriParameters = [], array $body = []); + public function createResource(string|\Stringable $uri, array $uriParameters = [], array $body = []): int; /** * Creates a resource using a multipart request. * - * @param string $uri URI of the resource - * @param array $uriParameters URI parameters of the resources - * @param array $requestParts Parts of the request. Each part is defined with "name", "contents", and "options" + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resources + * @param array $requestParts Parts of the request. Each part is defined with "name", "contents", and "options" * * @throws InvalidArgumentException if a given request part is invalid * @throws HttpException if the request failed * * @return ResponseInterface the response of the creation request */ - public function createMultipartResource($uri, array $uriParameters = [], array $requestParts = []); + public function createMultipartResource(string|\Stringable $uri, array $uriParameters = [], array $requestParts = []): ResponseInterface; /** * Creates a resource if it does not exist yet, otherwise updates partially the resource. * - * @param string $uri URI of the resource - * @param array $uriParameters URI parameters of the resource - * @param array $body Body of the request + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $body Body of the request * * @throws HttpException if the request failed * * @return int Status code 201 indicating that the resource has been well created. * Status code 204 indicating that the resource has been well updated. */ - public function upsertResource($uri, array $uriParameters = [], array $body = []); + public function upsertResource(string|\Stringable $uri, array $uriParameters = [], array $body = []): int; /** * Updates or creates several resources. * - * @param string $uri URI of the resource + * @param string|\Stringable $uri URI of the resource * @param array $uriParameters URI parameters of the resource * @param array|StreamInterface $resources array of resources to create or update. * You can pass your own StreamInterface implementation as well. @@ -97,31 +98,60 @@ public function upsertResource($uri, array $uriParameters = [], array $body = [] * @throws HttpException if the request failed * @throws InvalidArgumentException if the resources or any part thereof are invalid * - * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted resource + * @return UpsertResourceListResponse returns an iterable object, each entry corresponding to the response of the upserted resource + */ + public function upsertResourceList(string|\Stringable $uri, array $uriParameters = [], array|StreamInterface $resources = []): UpsertResourceListResponse; + + /** + * Updates partially the resource. + * + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $body Body of the request + * + * @throws HttpException if the request failed + * + * @return int Status code 201 indicating that the resource has been well created. + * Status code 204 indicating that the resource has been well updated. */ - public function upsertResourceList($uri, array $uriParameters = [], $resources = []); + public function patchResource(string|\Stringable $uri, array $uriParameters = [], array $body = []): int; + + /** + * Updates partially several resources. + * + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array|StreamInterface $resources array of resources to create or update. + * You can pass your own StreamInterface implementation as well. + * + * @throws HttpException if the request failed + * @throws InvalidArgumentException if the resources or any part thereof are invalid + * + * @return PatchResourceListResponse returns an iterable object, each entry corresponding to the response of the upserted resource + */ + public function patchResourceList(string|\Stringable $uri, array $uriParameters = [], array|StreamInterface $resources = []): PatchResourceListResponse; /** * Deletes a resource. * - * @param string $uri URI of the resource to delete - * @param array $uriParameters URI parameters of the resource + * @param string|\Stringable $uri URI of the resource to delete + * @param array $uriParameters URI parameters of the resource * * @throws HttpException If the request failed * * @return int Status code 204 indicating that the resource has been well deleted */ - public function deleteResource($uri, array $uriParameters = []); + public function deleteResource(string|\Stringable $uri, array $uriParameters = []): int; /** * Gets a streamed resource. * - * @param string $uri URI of the resource - * @param array $uriParameters URI parameters of the resource + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource * * @throws HttpException If the request failed * * @return StreamInterface */ - public function getStreamedResource($uri, array $uriParameters = []); + public function getStreamedResource(string|\Stringable $uri, array $uriParameters = []): StreamInterface; } diff --git a/src/ClientBuilderInterface.php b/src/ClientBuilderInterface.php new file mode 100644 index 0000000..d7839d2 --- /dev/null +++ b/src/ClientBuilderInterface.php @@ -0,0 +1,21 @@ +encodeUriParameters($uriParameters); - $uri = $this->baseUri.'/'.vsprintf(ltrim($path, '/'), $uriParameters); + $uri = $this->baseUri.'/'.sprintf(ltrim((string) $path, '/'), ...$uriParameters); $queryParameters = $this->booleanQueryParametersAsString($queryParameters); diff --git a/src/Routing/UriGeneratorInterface.php b/src/Routing/UriGeneratorInterface.php index e90627b..f846eee 100644 --- a/src/Routing/UriGeneratorInterface.php +++ b/src/Routing/UriGeneratorInterface.php @@ -16,11 +16,11 @@ interface UriGeneratorInterface /** * Generate an uri from a path, by adding host and port. * - * @param string $path Path of the endpoint - * @param array $uriParameters List of the parameters to generate the endpoint - * @param array $queryParameters List of the query parameters added to the endpoint + * @param string|\Stringable $path Path of the endpoint + * @param array $uriParameters List of the parameters to generate the endpoint + * @param array $queryParameters List of the query parameters added to the endpoint * * @return UriInterface */ - public function generate($path, array $uriParameters = [], array $queryParameters = []); + public function generate(string|\Stringable $path, array $uriParameters = [], array $queryParameters = []); } diff --git a/src/Security/LegacyAuthentication.php b/src/Security/LegacyAuthentication.php new file mode 100644 index 0000000..ce85cde --- /dev/null +++ b/src/Security/LegacyAuthentication.php @@ -0,0 +1,100 @@ + + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class LegacyAuthentication +{ + private ?string $clientId = null; + private ?string $secret = null; + private ?string $username = null; + private ?string $password = null; + private ?string $accessToken = null; + private ?string $refreshToken = null; + private ?array $xauthtokenHeader = null; + + public static function fromPassword(string $clientId, string $secret, string $username, string $password): self + { + $authentication = new static(); + $authentication->clientId = $clientId; + $authentication->secret = $secret; + $authentication->username = $username; + $authentication->password = $password; + + return $authentication; + } + + public static function fromToken(string $clientId, string $secret, string $accessToken, string $refreshToken): self + { + $authentication = new static(); + $authentication->clientId = $clientId; + $authentication->secret = $secret; + $authentication->accessToken = $accessToken; + $authentication->refreshToken = $refreshToken; + + return $authentication; + } + + public static function fromXAuthToken(array $fromXAuthToken): self + { + $authentication = new static(); + $authentication->xauthtokenHeader = $fromXAuthToken; + + return $authentication; + } + + public function getClientId(): ?string + { + return $this->clientId; + } + + public function getSecret(): ?string + { + return $this->secret; + } + + public function getUsername(): ?string + { + return $this->username; + } + + public function getPassword(): ?string + { + return $this->password; + } + + public function getAccessToken(): ?string + { + return $this->accessToken; + } + + public function getRefreshToken(): ?string + { + return $this->refreshToken; + } + + public function setAccessToken(string $accessToken): self + { + $this->accessToken = $accessToken; + + return $this; + } + + public function setRefreshToken(string $refreshToken): self + { + $this->refreshToken = $refreshToken; + + return $this; + } + + public function getXauthtokenHeader(): ?array + { + return $this->xauthtokenHeader; + } +} diff --git a/src/SyliusAdminClient.php b/src/SyliusAdminClient.php new file mode 100644 index 0000000..c73a9a3 --- /dev/null +++ b/src/SyliusAdminClient.php @@ -0,0 +1,79 @@ +addressApi; + } + + public function getAdjustmentApi(): Api\Admin\AdjustmentApiInterface + { + return $this->adjustmentApi; + } + + public function getAdministratorApi(): Api\Admin\AdministratorApiInterface + { + return $this->administratorApi; + } + + public function getAvatarImageApi(): Api\Admin\AvatarImageApiInterface + { + return $this->avatarImageApi; + } + + public function getCatalogPromotionTranslationApi(): Api\Admin\CatalogPromotionTranslationApiInterface + { + return $this->catalogPromotionTranslationApi; + } + + public function getCatalogPromotionApi(): Api\Admin\CatalogPromotionApiInterface + { + return $this->catalogPromotionApi; + } + + public function getChannelApi(): Api\Admin\ChannelApiInterface + { + return $this->channelApi; + } + + public function getShopBillingDataApi(): Api\Admin\ShopBillingDataApiInterface + { + return $this->shopBillingDataApi; + } + + public function getCountryApi(): Api\Admin\CountryApiInterface + { + return $this->countryApi; + } + + public function getProvinceApi(): Api\Admin\ProvinceApiInterface + { + return $this->provinceApi; + } + + public function getCurrencyApi(): Api\Admin\CurrencyApiInterface + { + return $this->currencyApi; + } +} diff --git a/src/SyliusAdminClientBuilder.php b/src/SyliusAdminClientBuilder.php new file mode 100644 index 0000000..b78725c --- /dev/null +++ b/src/SyliusAdminClientBuilder.php @@ -0,0 +1,189 @@ + */ + private array $apiRegistry = []; + /** @var array */ + private array $defaultHeaders = []; + + public function __construct(Api\ApiAwareInterface ...$apis) + { + array_map(fn (Api\ApiAwareInterface $api) => $this->addApi($api), $apis); + } + + public function addApi(Api\ApiAwareInterface $api): self + { + $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; + + return $this; + } + + public function setBaseUri(string $baseUri): self + { + $this->baseUri = $baseUri; + + return $this; + } + + public function setDefaultHeaders(array $headers): self + { + $this->defaultHeaders = $headers; + + return $this; + } + + /** + * Allows to directly set a client instead of using HttpClientDiscovery::find(). + */ + public function setHttpClient(Client $httpClient): self + { + $this->httpClient = $httpClient; + + return $this; + } + + /** + * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). + */ + public function setRequestFactory(RequestFactoryInterface $requestFactory): self + { + $this->requestFactory = $requestFactory; + + return $this; + } + + /** + * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). + */ + public function setStreamFactory(StreamFactoryInterface $streamFactory): self + { + $this->streamFactory = $streamFactory; + + return $this; + } + + /** + * Build the Sylius client authenticated by user name and password. + */ + public function buildAuthenticatedByPassword( + string $username, + string $password + ): SyliusAdminClientInterface { + $authentication = Authentication::fromPassword($username, $password); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by token. + */ + public function buildAuthenticatedByToken( + string $token, + ): SyliusAdminClientInterface { + $authentication = Authentication::fromAccessToken($token); + + return $this->buildAuthenticatedClient($authentication); + } + + private function buildAuthenticatedClient(Authentication $authentication): SyliusAdminClientInterface + { + $uriGenerator = new UriGenerator($this->baseUri); + $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); + + $authenticationApi = new Api\Authentication\AdminApi($httpClient, $uriGenerator); + $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); + $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + + $resourceClient = new ResourceClient( + $authenticatedHttpClient, + $uriGenerator, + $multipartStreamBuilderFactory, + $upsertListResponseFactory + ); + + $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); + $cursorFactory = new ResourceCursorFactory(); + $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); + + $client = new SyliusAdminClientDecorator( + new SyliusAdminClient( + $authentication, + new Api\Admin\AddressApi($resourceClient), + new Api\Admin\AdjustmentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\AdministratorApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\AvatarImageApi($resourceClient), + new Api\Admin\CatalogPromotionTranslationApi($resourceClient), + new Api\Admin\CatalogPromotionApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ChannelApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ShopBillingDataApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\CountryApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProvinceApi($resourceClient, $pageFactory, $cursorFactory), + ) + ); + + foreach ($this->apiRegistry as $key => $api) { + $api->setResourceClient($resourceClient); + $api->setPageFactory($pageFactory); + $api->setCursorFactory($cursorFactory); + $api->setFileSystem($fileSystem); + + $client->addApi($key, $api); + } + + return $client; + } + + private function getHttpClient(): Client + { + if (null === $this->httpClient) { + $this->httpClient = HttpClientDiscovery::find(); + } + + return $this->httpClient; + } + + private function getRequestFactory(): RequestFactoryInterface + { + if (null === $this->requestFactory) { + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + } + + return $this->requestFactory; + } + + private function getStreamFactory(): StreamFactoryInterface + { + if (null === $this->streamFactory) { + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + + return $this->streamFactory; + } +} diff --git a/src/SyliusAdminClientBuilderInterface.php b/src/SyliusAdminClientBuilderInterface.php new file mode 100644 index 0000000..eb58372 --- /dev/null +++ b/src/SyliusAdminClientBuilderInterface.php @@ -0,0 +1,15 @@ + */ + private array $apiRegistry = []; + + public function __construct( + private SyliusAdminClientInterface $decoratedClient + ) {} + + public function __call($name, $arguments) + { + $property = lcfirst(substr($name, 3)); + if ('get' === substr($name, 0, 3) && isset($this->apiRegistry[$property])) { + return $this->apiRegistry[$property]; + } + + return $this->decoratedClient->{$name}($arguments); + } + + public function addApi(string $key, Api\ApiAwareInterface $api) + { + $this->apiRegistry[$key] = $api; + } + + public function get(string $name): ?Api\ApiAwareInterface + { + return $this->apiRegistry[$name] ?? null; + } + + public function getAddressApi(): Api\Admin\AddressApiInterface + { + return $this->decoratedClient->getAddressApi(); + } + + public function getAdjustmentApi(): Api\Admin\AdjustmentApiInterface + { + return $this->decoratedClient->getAdjustmentApi(); + } + + public function getAdministratorApi(): Api\Admin\AdministratorApiInterface + { + return $this->decoratedClient->getAdministratorApi(); + } + + public function getAvatarImageApi(): Api\Admin\AvatarImageApiInterface + { + return $this->decoratedClient->getAvatarImageApi(); + } + + public function getCatalogPromotionTranslationApi(): Api\Admin\CatalogPromotionTranslationApiInterface + { + return $this->decoratedClient->getCatalogPromotionTranslationApi(); + } + + public function getCatalogPromotionApi(): Api\Admin\CatalogPromotionApiInterface + { + return $this->decoratedClient->getCatalogPromotionApi(); + } + + public function getChannelApi(): Api\Admin\ChannelApiInterface + { + return $this->decoratedClient->getChannelApi(); + } + + public function getShopBillingDataApi(): Api\Admin\ShopBillingDataApiInterface + { + return $this->decoratedClient->getShopBillingDataApi(); + } + + public function getCountryApi(): Api\Admin\CountryApiInterface + { + return $this->decoratedClient->getCountryApi(); + } + + public function getProvinceApi(): Api\Admin\ProvinceApiInterface + { + return $this->decoratedClient->getProvinceApi(); + } + + public function getCurrencyApi(): Api\Admin\CurrencyApiInterface + { + return $this->decoratedClient->getCurrencyApi(); + } +} diff --git a/src/SyliusAdminClientInterface.php b/src/SyliusAdminClientInterface.php new file mode 100644 index 0000000..f2593d6 --- /dev/null +++ b/src/SyliusAdminClientInterface.php @@ -0,0 +1,26 @@ + - * - * @category SyliusApiClient - * - * @copyright 2020 - Diglin (https://www.diglin.com) - */ - -namespace Diglin\Sylius\ApiClient; - -use Diglin\Sylius\ApiClient\Api; -use Diglin\Sylius\ApiClient\Security\Authentication; - -class SyliusClient implements SyliusClientInterface -{ - /** @var Authentication */ - private $authentication; - - /** @var Api\ChannelsApiInterface */ - private $channelsApi; - /** @var Api\UsersApiInterface */ - private $usersApi; - /** @var Api\CustomersApiInterface */ - private $customersApi; - /** @var Api\ProductsApiInterface */ - private $productsApi; - /** @var Api\CartsApiInterface */ - private $cartsApi; - /** @var Api\OrdersApiInterface */ - private $ordersApi; - /** @var Api\PaymentsApiInterface */ - private $paymentsApi; - /** @var Api\ShipmentsApiInterface */ - private $shipmentsApi; - /** @var Api\ShippingCategoriesApiInterface */ - private $shippingCategoriesApi; - /** @var Api\LocalesApiInterface */ - private $localesApi; - /** @var Api\CurrenciesApiInterface */ - private $currenciesApi; - /** @var Api\CountriesApiInterface */ - private $countriesApi; - /** @var Api\ExchangeRatesApiInterface */ - private $exchangeRatesApi; - /** @var Api\PaymentMethodsApiInterface */ - private $paymentMethodsApi; - /** @var Api\ProductAttributesApiInterface */ - private $productAttributesApi; - /** @var Api\ProductAssociationTypesApiInterface */ - private $productAssociationTypesApi; - /** @var Api\ProductOptionsApiInterface */ - private $productOptionsApi; - /** @var Api\ProductReviewsApiInterface */ - private $productReviewsApi; - /** @var Api\ProductVariantsApiInterface */ - private $productVariantsApi; - /** @var Api\PromotionsApiInterface */ - private $promotionsApi; - /** @var Api\PromotionCouponsApiInterface */ - private $promotionCouponsApi; - /** @var Api\TaxCategoriesApiInterface */ - private $taxCategoriesApi; - /** @var Api\TaxRatesApiInterface */ - private $taxRatesApi; - /** @var Api\TaxonsApiInterface */ - private $taxonsApi; - /** @var Api\ZonesApiInterface */ - private $zonesApi; - - public function __construct( - Authentication $authentication, - Api\CartsApiInterface $cartsApi, - Api\ChannelsApiInterface $channelsApi, - Api\CountriesApiInterface $countriesApi, - Api\CurrenciesApiInterface $currenciesApi, - Api\CustomersApiInterface $customersApi, - Api\ExchangeRatesApiInterface $exchangeRatesApi, - Api\LocalesApiInterface $localesApi, - Api\OrdersApiInterface $ordersApi, - Api\PaymentMethodsApiInterface $paymentMethodApi, - Api\PaymentsApiInterface $paymentsApi, - Api\ProductsApiInterface $productsApi, - Api\ProductAttributesApiInterface $productAttributesApi, - Api\ProductAssociationTypesApiInterface $productAssociationTypesApi, - Api\ProductOptionsApiInterface $productOptionsApi, - Api\ProductReviewsApiInterface $productReviewsApi, - Api\ProductVariantsApiInterface $productVariantsApi, - Api\PromotionsApiInterface $promotionsApi, - Api\PromotionCouponsApiInterface $promotionCouponsApi, - Api\ShipmentsApiInterface $shipmentsApi, - Api\ShippingCategoriesApiInterface $shippingCategoriesApi, - Api\TaxCategoriesApiInterface $taxCategoriesApi, - Api\TaxRatesApiInterface $taxRatesApi, - Api\TaxonsApiInterface $taxonsApi, - Api\UsersApiInterface $usersApi, - Api\ZonesApiInterface $zonesApi - ) { - $this->authentication = $authentication; - $this->channelsApi = $channelsApi; - $this->usersApi = $usersApi; - $this->customersApi = $customersApi; - $this->productsApi = $productsApi; - $this->cartsApi = $cartsApi; - $this->ordersApi = $ordersApi; - $this->paymentsApi = $paymentsApi; - $this->shipmentsApi = $shipmentsApi; - $this->shippingCategoriesApi = $shippingCategoriesApi; - $this->localesApi = $localesApi; - $this->currenciesApi = $currenciesApi; - $this->countriesApi = $countriesApi; - $this->exchangeRatesApi = $exchangeRatesApi; - $this->paymentMethodsApi = $paymentMethodApi; - $this->productAttributesApi = $productAttributesApi; - $this->productAssociationTypesApi = $productAssociationTypesApi; - $this->productOptionsApi = $productOptionsApi; - $this->productReviewsApi = $productReviewsApi; - $this->productVariantsApi = $productVariantsApi; - $this->promotionsApi = $promotionsApi; - $this->promotionCouponsApi = $promotionCouponsApi; - $this->taxCategoriesApi = $taxCategoriesApi; - $this->taxRatesApi = $taxRatesApi; - $this->taxonsApi = $taxonsApi; - $this->zonesApi = $zonesApi; - } - - public function getZonesApi(): Api\ZonesApiInterface - { - return $this->zonesApi; - } - - public function getTaxonsApi(): Api\TaxonsApiInterface - { - return $this->taxonsApi; - } - - public function getTaxRatesApi(): Api\TaxRatesApiInterface - { - return $this->taxRatesApi; - } - - public function getTaxCategoriesApi(): Api\TaxCategoriesApiInterface - { - return $this->taxCategoriesApi; - } - - public function getPromotionCouponsApi(): Api\PromotionCouponsApiInterface - { - return $this->promotionCouponsApi; - } - - public function getPromotionsApi(): Api\PromotionsApiInterface - { - return $this->promotionsApi; - } - - public function getProductVariantsApi(): Api\ProductVariantsApiInterface - { - return $this->productVariantsApi; - } - - public function getProductReviewsApi(): Api\ProductReviewsApiInterface - { - return $this->productReviewsApi; - } - - public function getProductOptionsApi(): Api\ProductOptionsApiInterface - { - return $this->productOptionsApi; - } - public function getProductAssociationTypesApi(): Api\ProductAssociationTypesApiInterface - { - return $this->productAssociationTypesApi; - } +declare(strict_types=1); - public function getProductAttributesApi(): Api\ProductAttributesApiInterface - { - return $this->productAttributesApi; - } +use Diglin\Sylius\ApiClient; - public function getShippingCategoriesApi(): Api\ShippingCategoriesApi - { - return $this->shippingCategoriesApi; - } +trigger_deprecation('diglin/sylius-api-php-client', '2.0', 'The "%s" class is deprecated, use "%s" instead.', 'Diglin\\Sylius\\ApiClient\\SyliusClient', ApiClient\SyliusLegacyClient::class); - public function getLocalesApi(): Api\LocalesApiInterface - { - return $this->localesApi; - } - - public function getCurrenciesApi(): Api\CurrenciesApiInterface - { - return $this->currenciesApi; - } - - public function getCountriesApi(): Api\CountriesApiInterface - { - return $this->countriesApi; - } - - public function getExchangeRatesApi(): Api\ExchangeRatesApiInterface - { - return $this->exchangeRatesApi; - } - - public function getPaymentMethodsApi(): Api\PaymentMethodsApiInterface - { - return $this->paymentMethodsApi; - } - - public function getUsersApi(): Api\UsersApiInterface - { - return $this->usersApi; - } - - public function getCustomersApi(): Api\CustomersApiInterface - { - return $this->customersApi; - } - - public function getProductsApi(): Api\ProductsApiInterface - { - return $this->productsApi; - } - - public function getCartsApi(): Api\CartsApiInterface - { - return $this->cartsApi; - } - - public function getOrdersApi(): Api\OrdersApiInterface - { - return $this->ordersApi; - } - - public function getPaymentsApi(): Api\PaymentsApiInterface - { - return $this->paymentsApi; - } - - public function getShipmentsApi(): Api\ShipmentsApiInterface - { - return $this->shipmentsApi; - } - - public function getToken(): ?string - { - return $this->authentication->getAccessToken(); - } - - public function getRefreshToken(): ?string - { - return $this->authentication->getRefreshToken(); - } - - public function getChannelsApi(): Api\ChannelsApiInterface - { - return $this->channelsApi; - } -} +/** + * @deprecated since diglin/sylius-api-php-client 2.0, use Diglin\Sylius\ApiClient\ApiClient\SyliusLegacyClient instead. + */ +class_alias(ApiClient\SyliusLegacyClient::class, 'Diglin\\Sylius\\ApiClient\\SyliusClient'); diff --git a/src/SyliusClientBuilder.php b/src/SyliusClientBuilder.php index 6577b11..bd40e8f 100644 --- a/src/SyliusClientBuilder.php +++ b/src/SyliusClientBuilder.php @@ -1,262 +1,12 @@ - * - * @category SyliusApiClient - * - * @copyright 2020 - Diglin (https://www.diglin.com) - */ -namespace Diglin\Sylius\ApiClient; +declare(strict_types=1); + +use Diglin\Sylius\ApiClient; -use Diglin\Sylius\ApiClient\Api; -use Diglin\Sylius\ApiClient\Client\AuthenticatedHttpClient; -use Diglin\Sylius\ApiClient\Client\HttpClient; -use Diglin\Sylius\ApiClient\Client\ResourceClient; -use Diglin\Sylius\ApiClient\FileSystem\FileSystemInterface; -use Diglin\Sylius\ApiClient\FileSystem\LocalFileSystem; -use Diglin\Sylius\ApiClient\Pagination\PageFactory; -use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactory; -use Diglin\Sylius\ApiClient\Routing\UriGenerator; -use Diglin\Sylius\ApiClient\Security\Authentication; -use Diglin\Sylius\ApiClient\Stream\MultipartStreamBuilderFactory; -use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponseFactory; -use Http\Client\HttpClient as Client; -use Http\Discovery\HttpClientDiscovery; -use Http\Discovery\Psr17FactoryDiscovery; -use Http\Message\RequestFactory; -use Http\Message\StreamFactory; -use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\StreamFactoryInterface; +trigger_deprecation('diglin/sylius-api-php-client', '2.0', 'The "%s" class is deprecated, use "%s" instead.', 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilder', ApiClient\SyliusLegacyClientFactory::class); /** - * Builder of the class SyliusClient. - * This builder is in charge to instantiate and inject the dependencies. - * - * @author Alexandre Hocquard - * @author Sylvain Rayé - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @deprecated since diglin/sylius-api-php-client 2.0, use Diglin\Sylius\ApiClient\ApiClient\SyliusLegacyClientBuilder instead. */ -class SyliusClientBuilder implements SyliusClientBuilderInterface -{ - /** @var string */ - protected $baseUri; - - /** @var Client */ - protected $httpClient; - - /** @var RequestFactory */ - protected $requestFactory; - - /** @var StreamFactory */ - protected $streamFactory; - - /** @var FileSystemInterface */ - protected $fileSystem; - - /** @var Api\ApiAwareInterface[] */ - protected $apiRegistry = []; - - /** @var array */ - protected $defaultHeaders = []; - - public function __construct(?Api\ApiAwareInterface ...$apis) - { - foreach ($apis as $api) { - $this->addApi($api); - } - } - - /** - * @return array - */ - protected function setUp(Authentication $authentication) - { - $uriGenerator = new UriGenerator($this->baseUri); - $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); - - $authenticationApi = new Api\AuthenticationApi($httpClient, $uriGenerator); - $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); - $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); - $upsertListResponseFactory = new UpsertResourceListResponseFactory(); - - $resourceClient = new ResourceClient( - $authenticatedHttpClient, - $uriGenerator, - $multipartStreamBuilderFactory, - $upsertListResponseFactory - ); - - $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); - $cursorFactory = new ResourceCursorFactory(); - $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); - - return [$resourceClient, $pageFactory, $cursorFactory, $fileSystem]; - } - - public function addApi(Api\ApiAwareInterface $api): self - { - $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; - - return $this; - } - - public function setBaseUri(string $baseUri): SyliusClientBuilderInterface - { - $this->baseUri = $baseUri; - - return $this; - } - - public function setDefaultHeaders(array $headers): SyliusClientBuilderInterface - { - $this->defaultHeaders = $headers; - - return $this; - } - - /** - * Allows to directly set a client instead of using HttpClientDiscovery::find(). - */ - public function setHttpClient(Client $httpClient): SyliusClientBuilderInterface - { - $this->httpClient = $httpClient; - - return $this; - } - - /** - * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). - */ - public function setRequestFactory(RequestFactory $requestFactory): SyliusClientBuilderInterface - { - $this->requestFactory = $requestFactory; - - return $this; - } - - /** - * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). - */ - public function setStreamFactory(StreamFactory $streamFactory): SyliusClientBuilderInterface - { - $this->streamFactory = $streamFactory; - - return $this; - } - - /** - * Build the Sylius client authenticated by user name and password. - */ - public function buildAuthenticatedByPassword( - string $clientId, - string $secret, - string $username, - string $password - ): SyliusClientInterface { - $authentication = Authentication::fromPassword($clientId, $secret, $username, $password); - - return $this->buildAuthenticatedClient($authentication); - } - - /** - * Build the Sylius client authenticated by token. - */ - public function buildAuthenticatedByToken( - string $clientId, - string $secret, - string $token, - string $refreshToken - ): SyliusClientInterface { - $authentication = Authentication::fromToken($clientId, $secret, $token, $refreshToken); - - return $this->buildAuthenticatedClient($authentication); - } - - /** - * Build the Sylius client authenticated by HTTP header. - */ - public function buildAuthenticatedByHeader(array $xAuthToken): SyliusClientInterface - { - $authentication = Authentication::fromXAuthToken($xAuthToken); - - return $this->buildAuthenticatedClient($authentication); - } - - private function buildAuthenticatedClient(Authentication $authentication): SyliusClientInterface - { - [$resourceClient, $pageFactory, $cursorFactory, $fileSystem] = $this->setUp($authentication); - - $client = new SyliusClientDecorator( - new SyliusClient( - $authentication, - new Api\CartsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ChannelsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\CountriesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\CurrenciesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\CustomersApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ExchangeRatesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\LocalesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\OrdersApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PaymentMethodsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PaymentsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductAttributesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductAssociationTypesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductOptionsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductReviewsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ProductVariantsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PromotionsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\PromotionCouponsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ShipmentsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ShippingCategoriesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\TaxCategoriesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\TaxRatesApi($resourceClient, $pageFactory, $cursorFactory), - new Api\TaxonsApi($resourceClient, $pageFactory, $cursorFactory), - new Api\UsersApi($resourceClient, $pageFactory, $cursorFactory), - new Api\ZonesApi($resourceClient, $pageFactory, $cursorFactory) - ) - ); - - foreach ($this->apiRegistry as $key => $api) { - $api->setResourceClient($resourceClient); - $api->setPageFactory($pageFactory); - $api->setCursorFactory($cursorFactory); - $api->setFileSystem($fileSystem); - - $client->addApi($key, $api); - } - - return $client; - } - - private function getHttpClient(): Client - { - if (null === $this->httpClient) { - $this->httpClient = HttpClientDiscovery::find(); - } - - return $this->httpClient; - } - - private function getRequestFactory(): RequestFactoryInterface - { - if (null === $this->requestFactory) { - $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); - } - - return $this->requestFactory; - } - - private function getStreamFactory(): StreamFactoryInterface - { - if (null === $this->streamFactory) { - $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); - } - - return $this->streamFactory; - } -} +class_alias(ApiClient\SyliusLegacyClientFactory::class, 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilder'); diff --git a/src/SyliusClientBuilderInterface.php b/src/SyliusClientBuilderInterface.php index ce62942..b75d0d1 100644 --- a/src/SyliusClientBuilderInterface.php +++ b/src/SyliusClientBuilderInterface.php @@ -1,43 +1,12 @@ - * @category FWG OroCRM - * @copyright 2020 - Diglin (https://www.diglin.com) - */ - -namespace Diglin\Sylius\ApiClient; - -use Http\Client\HttpClient as Client; -use Http\Message\RequestFactory; -use Http\Message\StreamFactory; - -interface SyliusClientBuilderInterface -{ - public function setBaseUri(string $baseUri): self; - public function setDefaultHeaders(array $headers): self; +declare(strict_types=1); - public function setHttpClient(Client $httpClient): self; +use Diglin\Sylius\ApiClient; - public function setRequestFactory(RequestFactory $requestFactory): self; +trigger_deprecation('diglin/sylius-api-php-client', '2.0', 'The "%s" interface is deprecated, use "%s" instead.', 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilderInterface', ApiClient\SyliusLegacyClientInterface::class); - public function setStreamFactory(StreamFactory $streamFactory): self; - - public function buildAuthenticatedByPassword( - string $clientId, - string $secret, - string $username, - string $password - ): SyliusClientInterface; - - public function buildAuthenticatedByToken( - string $clientId, - string $secret, - string $token, - string $refreshToken - ): SyliusClientInterface; - - public function buildAuthenticatedByHeader(array $xAuthToken): SyliusClientInterface; -} +/** + * @deprecated since diglin/sylius-api-php-client 2.0, use Diglin\Sylius\ApiClient\ApiClient\SyliusLegacyClientBuilderInterface instead. + */ +class_alias(ApiClient\SyliusLegacyClientBuilderInterface::class, 'Diglin\\Sylius\\ApiClient\\SyliusClientBuilderInterface'); diff --git a/src/SyliusClientInterface.php b/src/SyliusClientInterface.php index 68581ab..de9b9ab 100644 --- a/src/SyliusClientInterface.php +++ b/src/SyliusClientInterface.php @@ -1,92 +1,12 @@ + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient; + +use Diglin\Sylius\ApiClient\Api\Legacy as Api; +use Diglin\Sylius\ApiClient\Security\LegacyAuthentication; + +class SyliusLegacyClient implements SyliusLegacyClientInterface +{ + public function __construct( + private LegacyAuthentication $authentication, + private Api\CartsApiInterface $cartsApi, + private Api\ChannelsApiInterface $channelsApi, + private Api\CountriesApiInterface $countriesApi, + private Api\CurrenciesApiInterface $currenciesApi, + private Api\CustomersApiInterface $customersApi, + private Api\ExchangeRatesApiInterface $exchangeRatesApi, + private Api\LocalesApiInterface $localesApi, + private Api\OrdersApiInterface $ordersApi, + private Api\PaymentMethodsApiInterface $paymentMethodsApi, + private Api\PaymentsApiInterface $paymentsApi, + private Api\ProductsApiInterface $productsApi, + private Api\ProductAttributesApiInterface $productAttributesApi, + private Api\ProductAssociationTypesApiInterface $productAssociationTypesApi, + private Api\ProductOptionsApiInterface $productOptionsApi, + private Api\ProductReviewsApiInterface $productReviewsApi, + private Api\ProductVariantsApiInterface $productVariantsApi, + private Api\PromotionsApiInterface $promotionsApi, + private Api\PromotionCouponsApiInterface $promotionCouponsApi, + private Api\ShipmentsApiInterface $shipmentsApi, + private Api\ShippingCategoriesApiInterface $shippingCategoriesApi, + private Api\TaxCategoriesApiInterface $taxCategoriesApi, + private Api\TaxRatesApiInterface $taxRatesApi, + private Api\TaxonsApiInterface $taxonsApi, + private Api\UsersApiInterface $usersApi, + private Api\ZonesApiInterface $zonesApi + ) {} + + public function getZonesApi(): Api\ZonesApiInterface + { + return $this->zonesApi; + } + + public function getTaxonsApi(): Api\TaxonsApiInterface + { + return $this->taxonsApi; + } + + public function getTaxRatesApi(): Api\TaxRatesApiInterface + { + return $this->taxRatesApi; + } + + public function getTaxCategoriesApi(): Api\TaxCategoriesApiInterface + { + return $this->taxCategoriesApi; + } + + public function getPromotionCouponsApi(): Api\PromotionCouponsApiInterface + { + return $this->promotionCouponsApi; + } + + public function getPromotionsApi(): Api\PromotionsApiInterface + { + return $this->promotionsApi; + } + + public function getProductVariantsApi(): Api\ProductVariantsApiInterface + { + return $this->productVariantsApi; + } + + public function getProductReviewsApi(): Api\ProductReviewsApiInterface + { + return $this->productReviewsApi; + } + + public function getProductOptionsApi(): Api\ProductOptionsApiInterface + { + return $this->productOptionsApi; + } + + public function getProductAssociationTypesApi(): Api\ProductAssociationTypesApiInterface + { + return $this->productAssociationTypesApi; + } + + public function getProductAttributesApi(): Api\ProductAttributesApiInterface + { + return $this->productAttributesApi; + } + + public function getShippingCategoriesApi(): Api\ShippingCategoriesApiInterface + { + return $this->shippingCategoriesApi; + } + + public function getLocalesApi(): Api\LocalesApiInterface + { + return $this->localesApi; + } + + public function getCurrenciesApi(): Api\CurrenciesApiInterface + { + return $this->currenciesApi; + } + + public function getCountriesApi(): Api\CountriesApiInterface + { + return $this->countriesApi; + } + + public function getExchangeRatesApi(): Api\ExchangeRatesApiInterface + { + return $this->exchangeRatesApi; + } + + public function getPaymentMethodsApi(): Api\PaymentMethodsApiInterface + { + return $this->paymentMethodsApi; + } + + public function getUsersApi(): Api\UsersApiInterface + { + return $this->usersApi; + } + + public function getCustomersApi(): Api\CustomersApiInterface + { + return $this->customersApi; + } + + public function getProductsApi(): Api\ProductsApiInterface + { + return $this->productsApi; + } + + public function getCartsApi(): Api\CartsApiInterface + { + return $this->cartsApi; + } + + public function getOrdersApi(): Api\OrdersApiInterface + { + return $this->ordersApi; + } + + public function getPaymentsApi(): Api\PaymentsApiInterface + { + return $this->paymentsApi; + } + + public function getShipmentsApi(): Api\ShipmentsApiInterface + { + return $this->shipmentsApi; + } + + public function getChannelsApi(): Api\ChannelsApiInterface + { + return $this->channelsApi; + } + + public function getToken(): ?string + { + return $this->authentication->getAccessToken(); + } + + public function getRefreshToken(): ?string + { + return $this->authentication->getRefreshToken(); + } +} diff --git a/src/SyliusLegacyClientBuilderInterface.php b/src/SyliusLegacyClientBuilderInterface.php new file mode 100644 index 0000000..855bf21 --- /dev/null +++ b/src/SyliusLegacyClientBuilderInterface.php @@ -0,0 +1,27 @@ +decoratedClient = $decoratedClient; } diff --git a/src/SyliusLegacyClientFactory.php b/src/SyliusLegacyClientFactory.php new file mode 100644 index 0000000..18e3df1 --- /dev/null +++ b/src/SyliusLegacyClientFactory.php @@ -0,0 +1,249 @@ + + * + * @category SyliusApiClient + * + * @copyright 2020 - Diglin (https://www.diglin.com) + */ + +namespace Diglin\Sylius\ApiClient; + +use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; +use Diglin\Sylius\ApiClient\Api\Legacy as Api; +use Diglin\Sylius\ApiClient\Client\AuthenticatedHttpClient; +use Diglin\Sylius\ApiClient\Client\HttpClient; +use Diglin\Sylius\ApiClient\Client\ResourceClient; +use Diglin\Sylius\ApiClient\FileSystem\FileSystemInterface; +use Diglin\Sylius\ApiClient\FileSystem\LocalFileSystem; +use Diglin\Sylius\ApiClient\Pagination\PageFactory; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactory; +use Diglin\Sylius\ApiClient\Routing\UriGenerator; +use Diglin\Sylius\ApiClient\Security\LegacyAuthentication; +use Diglin\Sylius\ApiClient\Stream\MultipartStreamBuilderFactory; +use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponseFactory; +use Http\Client\HttpClient as Client; +use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; + +/** + * Builder of the class SyliusClient. + * This builder is in charge to instantiate and inject the dependencies. + * + * @author Alexandre Hocquard + * @author Sylvain Rayé + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class SyliusLegacyClientFactory implements SyliusLegacyClientBuilderInterface +{ + private ?string $baseUri; + private Client $httpClient; + private RequestFactoryInterface $requestFactory; + private StreamFactoryInterface $streamFactory; + private FileSystemInterface $fileSystem; + /** @var list */ + private array $apiRegistry = []; + private array $defaultHeaders = []; + + public function __construct(?ApiAwareInterface ...$apis) + { + foreach ($apis as $api) { + $this->addApi($api); + } + } + + /** + * @return array + */ + protected function setUp(LegacyAuthentication $authentication) + { + $uriGenerator = new UriGenerator($this->baseUri); + $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); + + $authenticationApi = new Api\AuthenticationApi($httpClient, $uriGenerator); + $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); + $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + + $resourceClient = new ResourceClient( + $authenticatedHttpClient, + $uriGenerator, + $multipartStreamBuilderFactory, + $upsertListResponseFactory + ); + + $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); + $cursorFactory = new ResourceCursorFactory(); + $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); + + return [$resourceClient, $pageFactory, $cursorFactory, $fileSystem]; + } + + public function addApi(ApiAwareInterface $api) + { + $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; + } + + public function setBaseUri(string $baseUri): self + { + $this->baseUri = $baseUri; + + return $this; + } + + public function setDefaultHeaders(array $headers): self + { + $this->defaultHeaders = $headers; + + return $this; + } + + /** + * Allows to directly set a client instead of using HttpClientDiscovery::find(). + */ + public function setHttpClient(Client $httpClient): self + { + $this->httpClient = $httpClient; + + return $this; + } + + /** + * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). + */ + public function setRequestFactory(RequestFactoryInterface $requestFactory): self + { + $this->requestFactory = $requestFactory; + + return $this; + } + + /** + * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). + */ + public function setStreamFactory(StreamFactoryInterface $streamFactory): self + { + $this->streamFactory = $streamFactory; + + return $this; + } + + /** + * Build the Sylius client authenticated by user name and password. + */ + public function buildAuthenticatedByPassword( + string $clientId, + string $secret, + string $username, + string $password, + ): SyliusLegacyClientInterface { + $authentication = LegacyAuthentication::fromPassword($clientId, $secret, $username, $password); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by token. + */ + public function buildAuthenticatedByToken( + string $clientId, + string $secret, + string $token, + string $refreshToken, + ): SyliusLegacyClientInterface { + $authentication = LegacyAuthentication::fromToken($clientId, $secret, $token, $refreshToken); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by HTTP header. + */ + public function buildAuthenticatedByHeader( + array $xAuthToken, + ): SyliusLegacyClientInterface { + $authentication = LegacyAuthentication::fromXAuthToken($xAuthToken); + + return $this->buildAuthenticatedClient($authentication); + } + + private function buildAuthenticatedClient( + LegacyAuthentication $authentication + ): SyliusLegacyClientInterface { + [$resourceClient, $pageFactory, $cursorFactory, $fileSystem] = $this->setUp($authentication); + + $client = new SyliusLegacyClientDecorator( + new SyliusLegacyClient( + $authentication, + new Api\CartsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ChannelsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\CountriesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\CurrenciesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\CustomersApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ExchangeRatesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\LocalesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\OrdersApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PaymentMethodsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PaymentsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductAttributesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductAssociationTypesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductOptionsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductReviewsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ProductVariantsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PromotionsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\PromotionCouponsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ShipmentsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ShippingCategoriesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\TaxCategoriesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\TaxRatesApi($resourceClient, $pageFactory, $cursorFactory), + new Api\TaxonsApi($resourceClient, $pageFactory, $cursorFactory), + new Api\UsersApi($resourceClient, $pageFactory, $cursorFactory), + new Api\ZonesApi($resourceClient, $pageFactory, $cursorFactory) + ) + ); + + foreach ($this->apiRegistry as $key => $api) { + $api->setResourceClient($resourceClient); + $api->setPageFactory($pageFactory); + $api->setCursorFactory($cursorFactory); + $api->setFileSystem($fileSystem); + + $client->addApi($key, $api); + } + + return $client; + } + + private function getHttpClient(): Client + { + if (null === $this->httpClient) { + $this->httpClient = HttpClientDiscovery::find(); + } + + return $this->httpClient; + } + + private function getRequestFactory(): RequestFactoryInterface + { + if (null === $this->requestFactory) { + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + } + + return $this->requestFactory; + } + + private function getStreamFactory(): StreamFactoryInterface + { + if (null === $this->streamFactory) { + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + + return $this->streamFactory; + } +} diff --git a/src/SyliusLegacyClientInterface.php b/src/SyliusLegacyClientInterface.php new file mode 100644 index 0000000..769e558 --- /dev/null +++ b/src/SyliusLegacyClientInterface.php @@ -0,0 +1,68 @@ +addressApi; + } + + public function getAdjustmentApi(): Api\Shop\AdjustmentApiInterface + { + return $this->adjustmentApi; + } + + public function getChannelApi(): Api\Shop\ChannelApiInterface + { + return $this->channelApi; + } + + public function getCountryApi(): Api\Shop\CountryApiInterface + { + return $this->countryApi; + } +} diff --git a/src/SyliusShopClientBuilder.php b/src/SyliusShopClientBuilder.php new file mode 100644 index 0000000..9d42712 --- /dev/null +++ b/src/SyliusShopClientBuilder.php @@ -0,0 +1,183 @@ + */ + private array $apiRegistry = []; + /** @var array */ + private array $defaultHeaders = []; + + public function __construct(Api\ApiAwareInterface ...$apis) + { + array_map(fn (Api\ApiAwareInterface $api) => $this->addApi($api), $apis); + } + + public function addApi(Api\ApiAwareInterface $api): self + { + $this->apiRegistry[(new \ReflectionClass($api))->getShortName()] = $api; + + return $this; + } + + public function setBaseUri(string $baseUri): self + { + $this->baseUri = $baseUri; + + return $this; + } + + public function setDefaultHeaders(array $headers): self + { + $this->defaultHeaders = $headers; + + return $this; + } + + /** + * Allows to directly set a client instead of using HttpClientDiscovery::find(). + */ + public function setHttpClient(Client $httpClient): self + { + $this->httpClient = $httpClient; + + return $this; + } + + /** + * Allows to directly set a request factory instead of using MessageFactoryDiscovery::find(). + */ + public function setRequestFactory(RequestFactoryInterface $requestFactory): self + { + $this->requestFactory = $requestFactory; + + return $this; + } + + /** + * Allows to directly set a stream factory instead of using StreamFactoryDiscovery::find(). + */ + public function setStreamFactory(StreamFactoryInterface $streamFactory): self + { + $this->streamFactory = $streamFactory; + + return $this; + } + + /** + * Build the Sylius client authenticated by user name and password. + */ + public function buildAuthenticatedByPassword( + string $username, + string $password + ): SyliusShopClientInterface { + $authentication = Authentication::fromPassword($username, $password); + + return $this->buildAuthenticatedClient($authentication); + } + + /** + * Build the Sylius client authenticated by token. + */ + public function buildAuthenticatedByToken( + string $token, + ): SyliusShopClientInterface { + $authentication = Authentication::fromAccessToken($token); + + return $this->buildAuthenticatedClient($authentication); + } + + private function buildAuthenticatedClient(Authentication $authentication): SyliusShopClientInterface + { + $uriGenerator = new UriGenerator($this->baseUri); + $httpClient = new HttpClient($this->getHttpClient(), $this->getRequestFactory(), $this->getStreamFactory(), $this->defaultHeaders); + + $authenticationApi = new Api\Authentication\AdminApi($httpClient, $uriGenerator); + $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); + $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); + $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + + $resourceClient = new ResourceClient( + $authenticatedHttpClient, + $uriGenerator, + $multipartStreamBuilderFactory, + $upsertListResponseFactory + ); + + $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); + $cursorFactory = new ResourceCursorFactory(); + $fileSystem = null !== $this->fileSystem ? $this->fileSystem : new LocalFileSystem(); + + $client = new SyliusShopClientDecorator( + new SyliusShopClient( + $authentication, + new Api\Shop\AddressApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\AdjustmentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ChannelApi($resourceClient), + new Api\Shop\CountryApi($resourceClient, $pageFactory, $cursorFactory), + ) + ); + + foreach ($this->apiRegistry as $key => $api) { + $api->setResourceClient($resourceClient); + $api->setPageFactory($pageFactory); + $api->setCursorFactory($cursorFactory); + $api->setFileSystem($fileSystem); + + $client->addApi($key, $api); + } + + return $client; + } + + private function getHttpClient(): Client + { + if (null === $this->httpClient) { + $this->httpClient = HttpClientDiscovery::find(); + } + + return $this->httpClient; + } + + private function getRequestFactory(): RequestFactoryInterface + { + if (null === $this->requestFactory) { + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + } + + return $this->requestFactory; + } + + private function getStreamFactory(): StreamFactoryInterface + { + if (null === $this->streamFactory) { + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + + return $this->streamFactory; + } +} diff --git a/src/SyliusShopClientBuilderInterface.php b/src/SyliusShopClientBuilderInterface.php new file mode 100644 index 0000000..974ff8a --- /dev/null +++ b/src/SyliusShopClientBuilderInterface.php @@ -0,0 +1,15 @@ + */ + private array $apiRegistry = []; + + public function __construct( + private SyliusShopClientInterface $decoratedClient + ) {} + + public function __call($name, $arguments) + { + $property = lcfirst(substr($name, 3)); + if ('get' === substr($name, 0, 3) && isset($this->apiRegistry[$property])) { + return $this->apiRegistry[$property]; + } + + return $this->decoratedClient->{$name}($arguments); + } + + public function addApi(string $key, Api\ApiAwareInterface $api) + { + $this->apiRegistry[$key] = $api; + } + + public function get(string $name): ?Api\ApiAwareInterface + { + return $this->apiRegistry[$name] ?? null; + } + + public function getAddressApi(): Api\Shop\AddressApiInterface + { + return $this->decoratedClient->getAddressApi(); + } + + public function getAdjustmentApi(): Api\Shop\AdjustmentApiInterface + { + return $this->decoratedClient->getAdjustmentApi(); + } + + public function getChannelApi(): Api\Shop\ChannelApiInterface + { + return $this->decoratedClient->getChannelApi(); + } + + public function getCountryApi(): Api\Shop\CountryApiInterface + { + return $this->decoratedClient->getCountryApi(); + } +} diff --git a/src/SyliusShopClientInterface.php b/src/SyliusShopClientInterface.php new file mode 100644 index 0000000..76303ac --- /dev/null +++ b/src/SyliusShopClientInterface.php @@ -0,0 +1,13 @@ + Date: Wed, 10 Nov 2021 23:24:49 +0100 Subject: [PATCH 07/13] Added more Admin API endpoints support --- README.md | 63 +++++- composer.json | 6 +- src/Api/Admin/OrderApi.php | 79 +++++++ src/Api/Admin/OrderApiInterface.php | 52 +++++ src/Api/Admin/PaymentApi.php | 55 +++++ src/Api/Admin/PaymentApiInterface.php | 19 ++ src/Api/Admin/PaymentMethodApi.php | 19 ++ src/Api/Admin/PaymentMethodApiInterface.php | 9 + src/Api/Admin/ProductApi.php | 67 ++++++ src/Api/Admin/ProductApiInterface.php | 13 ++ src/Api/Admin/ProductAssociationTypeApi.php | 67 ++++++ .../ProductAssociationTypeApiInterface.php | 13 ++ .../ProductAssociationTypeTranslationApi.php | 19 ++ ...AssociationTypeTranslationApiInterface.php | 9 + src/Api/Admin/ProductImageApi.php | 49 +++++ src/Api/Admin/ProductImageApiInterface.php | 10 + src/Api/Admin/ProductOptionApi.php | 74 +++++++ src/Api/Admin/ProductOptionApiInterface.php | 30 +++ src/Api/Admin/ProductOptionTranslationApi.php | 19 ++ .../ProductOptionTranslationApiInterface.php | 9 + src/Api/Admin/ProductOptionValueApi.php | 49 +++++ .../Admin/ProductOptionValueApiInterface.php | 10 + src/Api/Admin/ProductReviewApi.php | 73 +++++++ src/Api/Admin/ProductReviewApiInterface.php | 14 ++ src/Api/Admin/ProductTaxonApi.php | 49 +++++ src/Api/Admin/ProductTaxonApiInterface.php | 10 + src/Api/Admin/ProductTranslationApi.php | 19 ++ .../Admin/ProductTranslationApiInterface.php | 9 + src/Api/Admin/ProductVariantApi.php | 55 +++++ src/Api/Admin/ProductVariantApiInterface.php | 11 + .../Admin/ProductVariantTranslationApi.php | 19 ++ .../ProductVariantTranslationApiInterface.php | 9 + src/Api/Admin/PromotionApi.php | 55 +++++ src/Api/Admin/PromotionApiInterface.php | 11 + src/Api/Admin/ResetPasswordRequestApi.php | 24 +++ .../ResetPasswordRequestApiInterface.php | 10 + src/Api/Admin/ShipmentApi.php | 55 +++++ src/Api/Admin/ShipmentApiInterface.php | 19 ++ src/Api/Admin/ShippingCategoryApi.php | 67 ++++++ .../Admin/ShippingCategoryApiInterface.php | 13 ++ src/Api/Admin/ShippingMethodApi.php | 81 +++++++ src/Api/Admin/ShippingMethodApiInterface.php | 15 ++ .../Admin/ShippingMethodTranslationApi.php | 19 ++ .../ShippingMethodTranslationApiInterface.php | 9 + src/Api/Admin/TaxCategoryApi.php | 69 ++++++ src/Api/Admin/TaxCategoryApiInterface.php | 13 ++ src/Api/Admin/TaxonApi.php | 61 ++++++ src/Api/Admin/TaxonApiInterface.php | 12 ++ src/Api/Admin/TaxonTranslationApi.php | 47 +++++ .../Admin/TaxonTranslationApiInterface.php | 10 + src/Api/Admin/VerifyCustomerAccountApi.php | 27 +++ .../VerifyCustomerAccountApiInterface.php | 10 + src/Api/Admin/ZoneApi.php | 69 ++++++ src/Api/Admin/ZoneApiInterface.php | 13 ++ src/Api/Admin/ZoneMemberApi.php | 51 +++++ src/Api/Admin/ZoneMemberApiInterface.php | 10 + src/SyliusAdminClient.php | 198 ++++++++++++++++++ src/SyliusAdminClientBuilder.php | 34 +++ src/SyliusAdminClientDecorator.php | 165 +++++++++++++++ src/SyliusAdminClientInterface.php | 27 +++ src/SyliusLegacyClientDecorator.php | 84 +++----- 61 files changed, 2221 insertions(+), 65 deletions(-) create mode 100644 src/Api/Admin/OrderApi.php create mode 100644 src/Api/Admin/OrderApiInterface.php create mode 100644 src/Api/Admin/PaymentApi.php create mode 100644 src/Api/Admin/PaymentApiInterface.php create mode 100644 src/Api/Admin/PaymentMethodApi.php create mode 100644 src/Api/Admin/PaymentMethodApiInterface.php create mode 100644 src/Api/Admin/ProductApi.php create mode 100644 src/Api/Admin/ProductApiInterface.php create mode 100644 src/Api/Admin/ProductAssociationTypeApi.php create mode 100644 src/Api/Admin/ProductAssociationTypeApiInterface.php create mode 100644 src/Api/Admin/ProductAssociationTypeTranslationApi.php create mode 100644 src/Api/Admin/ProductAssociationTypeTranslationApiInterface.php create mode 100644 src/Api/Admin/ProductImageApi.php create mode 100644 src/Api/Admin/ProductImageApiInterface.php create mode 100644 src/Api/Admin/ProductOptionApi.php create mode 100644 src/Api/Admin/ProductOptionApiInterface.php create mode 100644 src/Api/Admin/ProductOptionTranslationApi.php create mode 100644 src/Api/Admin/ProductOptionTranslationApiInterface.php create mode 100644 src/Api/Admin/ProductOptionValueApi.php create mode 100644 src/Api/Admin/ProductOptionValueApiInterface.php create mode 100644 src/Api/Admin/ProductReviewApi.php create mode 100644 src/Api/Admin/ProductReviewApiInterface.php create mode 100644 src/Api/Admin/ProductTaxonApi.php create mode 100644 src/Api/Admin/ProductTaxonApiInterface.php create mode 100644 src/Api/Admin/ProductTranslationApi.php create mode 100644 src/Api/Admin/ProductTranslationApiInterface.php create mode 100644 src/Api/Admin/ProductVariantApi.php create mode 100644 src/Api/Admin/ProductVariantApiInterface.php create mode 100644 src/Api/Admin/ProductVariantTranslationApi.php create mode 100644 src/Api/Admin/ProductVariantTranslationApiInterface.php create mode 100644 src/Api/Admin/PromotionApi.php create mode 100644 src/Api/Admin/PromotionApiInterface.php create mode 100644 src/Api/Admin/ResetPasswordRequestApi.php create mode 100644 src/Api/Admin/ResetPasswordRequestApiInterface.php create mode 100644 src/Api/Admin/ShipmentApi.php create mode 100644 src/Api/Admin/ShipmentApiInterface.php create mode 100644 src/Api/Admin/ShippingCategoryApi.php create mode 100644 src/Api/Admin/ShippingCategoryApiInterface.php create mode 100644 src/Api/Admin/ShippingMethodApi.php create mode 100644 src/Api/Admin/ShippingMethodApiInterface.php create mode 100644 src/Api/Admin/ShippingMethodTranslationApi.php create mode 100644 src/Api/Admin/ShippingMethodTranslationApiInterface.php create mode 100644 src/Api/Admin/TaxCategoryApi.php create mode 100644 src/Api/Admin/TaxCategoryApiInterface.php create mode 100644 src/Api/Admin/TaxonApi.php create mode 100644 src/Api/Admin/TaxonApiInterface.php create mode 100644 src/Api/Admin/TaxonTranslationApi.php create mode 100644 src/Api/Admin/TaxonTranslationApiInterface.php create mode 100644 src/Api/Admin/VerifyCustomerAccountApi.php create mode 100644 src/Api/Admin/VerifyCustomerAccountApiInterface.php create mode 100644 src/Api/Admin/ZoneApi.php create mode 100644 src/Api/Admin/ZoneApiInterface.php create mode 100644 src/Api/Admin/ZoneMemberApi.php create mode 100644 src/Api/Admin/ZoneMemberApiInterface.php diff --git a/README.md b/README.md index 8c7b7ae..634c7c0 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,64 @@ A simple PHP client to use the [Sylius PHP API](https://docs.sylius.com/en/lates *IMPORTANT:* Documentation is work in progress. -Matrix compatibility: +Compatibility matrix: -| Sylius version(s) | API PHP Client version |CI status | -|--------------------|-------------------------|--------------------------------------------------------------------------------------------------------------------------| -| v1.6 | v1.0 || -| v1.7 | v1.0 || -| - | master || +| Sylius version(s) | API PHP Client version | PHP requirements |CI status | +|--------------------|------------------------|------------------|--------------------------------------------------------------------------------------------------------------------------| +| \>= 1.6 <=1.7 | ^1.0 (master) | ^7.3 | | +| 1.8 | no support | | | +| \>= 1.9 | ^2.0 (next) | ^8.0 | | Note that our PHP client is backward compatible. -## Requirements +## Usage for API v2 (Sylius >= 1.9) -* PHP >= 7.3 -* Composer +In Sylius versions 1.9 and later, you will be using the v2 API, or Unified API. +This APU will expose 2 sections: +* the Shop API, for accessing data from the customer's point of view +* the Admin API, for accessing data from an administrator point of view +Additionally, you can activate the now deprecated v1 Admin API. + +To create your client, there is a client builder for each API that will take care for +you of the internals and dependency injection. + +### Admin API usage + +```php +buildAuthenticatedByPassword('johndoe', 'password'); +$client->getProductApi()->all(); +``` + +### Store API usage + +```php +buildAuthenticatedByPassword('johndoe@example.com', 'password'); +$client->getProductApi()->all(); +``` + +## Usage for API v1 (Sylius >= 1.6 <=1.7, deprecated after 1.7) + +> NOTE: If you are using Sylius version >= 1.10, you will need to reactivate this API +> following this documentation: https://docs.sylius.com/en/1.10/book/api/introduction.html?highlight=sylius_api + +To create your client, there is a client builder that will take care for +you of the internals and dependency injection. + +```php +buildAuthenticatedByPassword('johndoe', 'password', '', ''); +$client->getProductsApi()->all(); +``` diff --git a/composer.json b/composer.json index d2bbfb8..c75f018 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,10 @@ { "name": "Diglin (Derivative Work)", "homepage": "https://www.diglin.com" + }, + { + "name": "Gyroscops (Derivative Work)", + "homepage": "https://gyroscops.com" } ], "autoload": { @@ -25,7 +29,7 @@ } }, "require": { - "php": ">=7.1", + "php": ">=8.0", "psr/http-client": "^1.0", "psr/http-message": "^1.0", "php-http/httplug": "^1.1 || ^2.0", diff --git a/src/Api/Admin/OrderApi.php b/src/Api/Admin/OrderApi.php new file mode 100644 index 0000000..105a1d8 --- /dev/null +++ b/src/Api/Admin/OrderApi.php @@ -0,0 +1,79 @@ +resourceClient->getResource('api/v2/admin/orders/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/orders', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function cancel(string $code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->patchResource('api/v2/admin/orders/%s/cancel', [$code], $data); + } + + public function listPayments( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->resourceClient->getResources('api/v2/admin/orders/%s/payments', [], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + } + + public function listShipments( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->resourceClient->getResources('api/v2/admin/orders/%s/shipments', [], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + } +} diff --git a/src/Api/Admin/OrderApiInterface.php b/src/Api/Admin/OrderApiInterface.php new file mode 100644 index 0000000..ba0e9d4 --- /dev/null +++ b/src/Api/Admin/OrderApiInterface.php @@ -0,0 +1,52 @@ +resourceClient->getResource('api/v2/admin/payments/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/payments', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function complete(string $code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->patchResource('api/v2/admin/payments/%s/complete', [$code], $data); + } +} diff --git a/src/Api/Admin/PaymentApiInterface.php b/src/Api/Admin/PaymentApiInterface.php new file mode 100644 index 0000000..cde3492 --- /dev/null +++ b/src/Api/Admin/PaymentApiInterface.php @@ -0,0 +1,19 @@ +resourceClient->getResource('api/v2/admin/payment-methods/%s', [$code]); + } +} diff --git a/src/Api/Admin/PaymentMethodApiInterface.php b/src/Api/Admin/PaymentMethodApiInterface.php new file mode 100644 index 0000000..678451c --- /dev/null +++ b/src/Api/Admin/PaymentMethodApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/products/%s', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/products/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/products', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/products', [], $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/products/%s', [$code]); + } +} diff --git a/src/Api/Admin/ProductApiInterface.php b/src/Api/Admin/ProductApiInterface.php new file mode 100644 index 0000000..933efa8 --- /dev/null +++ b/src/Api/Admin/ProductApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/product-association-types/%s', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/product-association-types', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/product-association-types', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/admin/product-association-types/%d', [$code], $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/product-association-types/%s', [$code]); + } +} diff --git a/src/Api/Admin/ProductAssociationTypeApiInterface.php b/src/Api/Admin/ProductAssociationTypeApiInterface.php new file mode 100644 index 0000000..dae73b8 --- /dev/null +++ b/src/Api/Admin/ProductAssociationTypeApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/product-association-type-translations/%d', [$code]); + } +} diff --git a/src/Api/Admin/ProductAssociationTypeTranslationApiInterface.php b/src/Api/Admin/ProductAssociationTypeTranslationApiInterface.php new file mode 100644 index 0000000..14514d4 --- /dev/null +++ b/src/Api/Admin/ProductAssociationTypeTranslationApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/product-images/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/product-images', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/ProductImageApiInterface.php b/src/Api/Admin/ProductImageApiInterface.php new file mode 100644 index 0000000..0dad805 --- /dev/null +++ b/src/Api/Admin/ProductImageApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/admin/product-options/%s', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/product-options', [], $data); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/product-options', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/product-options/%s', [$code], $data); + } + + public function listValues( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/admin/product-options/%s/values', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + } +} diff --git a/src/Api/Admin/ProductOptionApiInterface.php b/src/Api/Admin/ProductOptionApiInterface.php new file mode 100644 index 0000000..1b11d72 --- /dev/null +++ b/src/Api/Admin/ProductOptionApiInterface.php @@ -0,0 +1,30 @@ +resourceClient->getResource('api/v2/admin/product-option-translations/%d', [$code]); + } +} diff --git a/src/Api/Admin/ProductOptionTranslationApiInterface.php b/src/Api/Admin/ProductOptionTranslationApiInterface.php new file mode 100644 index 0000000..ee90c16 --- /dev/null +++ b/src/Api/Admin/ProductOptionTranslationApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/product-options/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/product-options', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/ProductOptionValueApiInterface.php b/src/Api/Admin/ProductOptionValueApiInterface.php new file mode 100644 index 0000000..a4de2c8 --- /dev/null +++ b/src/Api/Admin/ProductOptionValueApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/admin/product-reviews/%d', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/admin/product-reviews/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/product-reviews', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/admin/product-reviews/%d', [$code]); + } + + public function accept(string $code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->patchResource('api/v2/admin/product-reviews/%d/accept', [$code], $data); + } + + public function reject(string $code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->patchResource('api/v2/admin/product-reviews/%d/reject', [$code], $data); + } +} diff --git a/src/Api/Admin/ProductReviewApiInterface.php b/src/Api/Admin/ProductReviewApiInterface.php new file mode 100644 index 0000000..76de13a --- /dev/null +++ b/src/Api/Admin/ProductReviewApiInterface.php @@ -0,0 +1,14 @@ +resourceClient->getResource('api/v2/admin/product-taxons/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/product-taxons', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/ProductTaxonApiInterface.php b/src/Api/Admin/ProductTaxonApiInterface.php new file mode 100644 index 0000000..25311ca --- /dev/null +++ b/src/Api/Admin/ProductTaxonApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/admin/product-translations/%d', [$code]); + } +} diff --git a/src/Api/Admin/ProductTranslationApiInterface.php b/src/Api/Admin/ProductTranslationApiInterface.php new file mode 100644 index 0000000..de186cf --- /dev/null +++ b/src/Api/Admin/ProductTranslationApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/product-variants/%s', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/product-variants/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/product-variants', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/ProductVariantApiInterface.php b/src/Api/Admin/ProductVariantApiInterface.php new file mode 100644 index 0000000..c733329 --- /dev/null +++ b/src/Api/Admin/ProductVariantApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->getResource('api/v2/admin/product-variant-translations/%d', [$code]); + } +} diff --git a/src/Api/Admin/ProductVariantTranslationApiInterface.php b/src/Api/Admin/ProductVariantTranslationApiInterface.php new file mode 100644 index 0000000..fd39669 --- /dev/null +++ b/src/Api/Admin/ProductVariantTranslationApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/promotions/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/promotions', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function delete($code): int + { + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/admin/promotions/%d', [$code]); + } +} diff --git a/src/Api/Admin/PromotionApiInterface.php b/src/Api/Admin/PromotionApiInterface.php new file mode 100644 index 0000000..a0679d3 --- /dev/null +++ b/src/Api/Admin/PromotionApiInterface.php @@ -0,0 +1,11 @@ +resourceClient->createResource('api/v2/admin/reset-password-requests', [], $data); + } + + public function acknowledge(string $token): int + { + return $this->resourceClient->patchResource('api/v2/admin/reset-password-requests/%s', [$token], ['token' => $token]); + } +} diff --git a/src/Api/Admin/ResetPasswordRequestApiInterface.php b/src/Api/Admin/ResetPasswordRequestApiInterface.php new file mode 100644 index 0000000..52f05df --- /dev/null +++ b/src/Api/Admin/ResetPasswordRequestApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/admin/shipments/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/shipments', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function ship(string $code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->patchResource('api/v2/admin/shipments/%s/ship', [$code], $data); + } +} diff --git a/src/Api/Admin/ShipmentApiInterface.php b/src/Api/Admin/ShipmentApiInterface.php new file mode 100644 index 0000000..3ae1b97 --- /dev/null +++ b/src/Api/Admin/ShipmentApiInterface.php @@ -0,0 +1,19 @@ +resourceClient->getResource('api/v2/admin/shipping-categories/%s', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/shipping-categories/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/shipping-categories', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/shipping-categories', [], $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/shipping-categories/%s', [$code]); + } +} diff --git a/src/Api/Admin/ShippingCategoryApiInterface.php b/src/Api/Admin/ShippingCategoryApiInterface.php new file mode 100644 index 0000000..4e9e252 --- /dev/null +++ b/src/Api/Admin/ShippingCategoryApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/shipping-methods/%s', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/shipping-methods/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/shipping-methods', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/shipping-methods', [], $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/shipping-methods/%s', [$code]); + } + + public function archive(string $code, array $data = []) + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/shipping-methods/%s/archive', [$code], $data); + } + + public function restore(string $code, array $data = []) + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/shipping-methods/%s/restore', [$code], $data); + } +} diff --git a/src/Api/Admin/ShippingMethodApiInterface.php b/src/Api/Admin/ShippingMethodApiInterface.php new file mode 100644 index 0000000..d04bb78 --- /dev/null +++ b/src/Api/Admin/ShippingMethodApiInterface.php @@ -0,0 +1,15 @@ +resourceClient->getResource('api/v2/admin/shipping-method-translations/%d', [$code]); + } +} diff --git a/src/Api/Admin/ShippingMethodTranslationApiInterface.php b/src/Api/Admin/ShippingMethodTranslationApiInterface.php new file mode 100644 index 0000000..d2f9ef1 --- /dev/null +++ b/src/Api/Admin/ShippingMethodTranslationApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/admin/tax-categories/%s', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/tax-categories/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/tax-categories', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/tax-categories', [], $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/tax-categories/%s', [$code]); + } +} diff --git a/src/Api/Admin/TaxCategoryApiInterface.php b/src/Api/Admin/TaxCategoryApiInterface.php new file mode 100644 index 0000000..5bb6b71 --- /dev/null +++ b/src/Api/Admin/TaxCategoryApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/taxons/%s', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/taxons/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/taxons', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/taxons', [], $data); + } +} diff --git a/src/Api/Admin/TaxonApiInterface.php b/src/Api/Admin/TaxonApiInterface.php new file mode 100644 index 0000000..e18b454 --- /dev/null +++ b/src/Api/Admin/TaxonApiInterface.php @@ -0,0 +1,12 @@ +resourceClient->getResource('api/v2/admin/taxon-translations/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/taxon-translations', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + // TODO: Implement all() method. + } +} diff --git a/src/Api/Admin/TaxonTranslationApiInterface.php b/src/Api/Admin/TaxonTranslationApiInterface.php new file mode 100644 index 0000000..ee5ba93 --- /dev/null +++ b/src/Api/Admin/TaxonTranslationApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->createResource('api/v2/admin/account-verification-requests', [], $data); + } + + public function acknowledge(string $token, string $password, string $confirmation): int + { + return $this->resourceClient->patchResource('api/v2/admin/account-verification-requests/%s', [$token], [ + 'newPassword' => $password, + 'confirmNewPassword' => $confirmation, + ]); + } +} diff --git a/src/Api/Admin/VerifyCustomerAccountApiInterface.php b/src/Api/Admin/VerifyCustomerAccountApiInterface.php new file mode 100644 index 0000000..c935a0a --- /dev/null +++ b/src/Api/Admin/VerifyCustomerAccountApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/admin/zones/%s', [$code]); + } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/zones/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/zones', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->createResource('api/v2/admin/zones', [], $data); + } + + public function delete($code): int + { + Assert::string($code); + return $this->resourceClient->deleteResource('api/v2/admin/zones/%s', [$code]); + } +} diff --git a/src/Api/Admin/ZoneApiInterface.php b/src/Api/Admin/ZoneApiInterface.php new file mode 100644 index 0000000..f19cafa --- /dev/null +++ b/src/Api/Admin/ZoneApiInterface.php @@ -0,0 +1,13 @@ +resourceClient->getResource('api/v2/admin/zone-members/%s', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/zones/%s/members', [$code], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Admin/ZoneMemberApiInterface.php b/src/Api/Admin/ZoneMemberApiInterface.php new file mode 100644 index 0000000..1461f40 --- /dev/null +++ b/src/Api/Admin/ZoneMemberApiInterface.php @@ -0,0 +1,10 @@ +currencyApi; } + + public function getCustomerGroupApi(): Api\Admin\CustomerGroupApiInterface + { + return $this->customerGroupApi; + } + + public function getCustomerApi(): Api\Admin\CustomerApiInterface + { + return $this->customerApi; + } + + public function getExchangeRateApi(): Api\Admin\ExchangeRateApiInterface + { + return $this->exchangeRateApi; + } + + public function getLocaleApi(): Api\Admin\LocaleApiInterface + { + return $this->localeApi; + } + + public function getOrderItemUnitApi(): Api\Admin\OrderItemUnitApiInterface + { + return $this->orderItemUnitApi; + } + + public function getOrderItemApi(): Api\Admin\OrderItemApiInterface + { + return $this->orderItemApi; + } + + public function getOrderApi(): Api\Admin\OrderApiInterface + { + return $this->orderApi; + } + + public function getPaymentApi(): Api\Admin\PaymentApiInterface + { + return $this->paymentApi; + } + + public function getShipmentApi(): Api\Admin\ShipmentApiInterface + { + return $this->shipmentApi; + } + + public function getPaymentMethodApi(): Api\Admin\PaymentMethodApiInterface + { + return $this->paymentMethodApi; + } + + public function getProductAssociationTypeTranslationApi(): Api\Admin\ProductAssociationTypeTranslationApiInterface + { + return $this->productAssociationTypeTranslationApi; + } + + public function getProductAssociationTypeApi(): Api\Admin\ProductAssociationTypeApiInterface + { + return $this->productAssociationTypeApi; + } + + public function getProductImageApi(): Api\Admin\ProductImageApiInterface + { + return $this->productImageApi; + } + + public function getProductOptionTranslationApi(): Api\Admin\ProductOptionTranslationApiInterface + { + return $this->productOptionTranslationApi; + } + + public function getProductOptionValueApi(): Api\Admin\ProductOptionValueApiInterface + { + return $this->productOptionValueApi; + } + + public function getProductOptionApi(): Api\Admin\ProductOptionApiInterface + { + return $this->productOptionApi; + } + + public function getProductReviewApi(): Api\Admin\ProductReviewApiInterface + { + return $this->productReviewApi; + } + + public function getProductTaxonApi(): Api\Admin\ProductTaxonApiInterface + { + return $this->productTaxonApi; + } + + public function getProductTranslationApi(): Api\Admin\ProductTranslationApiInterface + { + return $this->productTranslationApi; + } + + public function getProductVariantTranslationApi(): Api\Admin\ProductVariantTranslationApiInterface + { + return $this->productVariantTranslationApi; + } + + public function getProductVariantApi(): Api\Admin\ProductVariantApiInterface + { + return $this->productVariantApi; + } + + public function getProductApi(): Api\Admin\ProductApiInterface + { + return $this->productApi; + } + + public function getPromotionApi(): Api\Admin\PromotionApiInterface + { + return $this->promotionApi; + } + + public function getShippingCategoryApi(): Api\Admin\ShippingCategoryApiInterface + { + return $this->shippingCategoryApi; + } + + public function getShippingMethodTranslationApi(): Api\Admin\ShippingMethodTranslationApiInterface + { + return $this->shippingMethodTranslationApi; + } + + public function getShippingMethodApi(): Api\Admin\ShippingMethodApiInterface + { + return $this->shippingMethodApi; + } + + public function getTaxCategoryApi(): Api\Admin\TaxCategoryApiInterface + { + return $this->taxCategoryApi; + } + + public function getTaxonTranslationApi(): Api\Admin\TaxonTranslationApiInterface + { + return $this->taxonTranslationApi; + } + + public function getTaxonApi(): Api\Admin\TaxonApiInterface + { + return $this->taxonApi; + } + + public function getZoneMemberApi(): Api\Admin\ZoneMemberApiInterface + { + return $this->zoneMemberApi; + } + + public function getZoneApi(): Api\Admin\ZoneApiInterface + { + return $this->zoneApi; + } + + public function getVerifyCustomerAccountApi(): Api\Admin\VerifyCustomerAccountApiInterface + { + return $this->verifyCustomerAccountApi; + } + + public function getResetPasswordRequestApi(): Api\Admin\ResetPasswordRequestApiInterface + { + return $this->resetPasswordRequestApi; + } } diff --git a/src/SyliusAdminClientBuilder.php b/src/SyliusAdminClientBuilder.php index b78725c..8c09364 100644 --- a/src/SyliusAdminClientBuilder.php +++ b/src/SyliusAdminClientBuilder.php @@ -145,6 +145,40 @@ private function buildAuthenticatedClient(Authentication $authentication): Syliu new Api\Admin\ShopBillingDataApi($resourceClient, $pageFactory, $cursorFactory), new Api\Admin\CountryApi($resourceClient, $pageFactory, $cursorFactory), new Api\Admin\ProvinceApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\CurrencyApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\CustomerGroupApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\CustomerApi($resourceClient), + new Api\Admin\ExchangeRateApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\LocaleApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\OrderItemUnitApi($resourceClient), + new Api\Admin\OrderItemApi($resourceClient), + new Api\Admin\OrderApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\PaymentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ShipmentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\PaymentMethodApi($resourceClient), + new Api\Admin\ProductAssociationTypeTranslationApi($resourceClient), + new Api\Admin\ProductAssociationTypeApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductImageApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductOptionTranslationApi($resourceClient), + new Api\Admin\ProductOptionValueApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductOptionApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductReviewApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductTaxonApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductVariantTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductVariantApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ProductApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\PromotionApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ShippingCategoryApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ShippingMethodTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ShippingMethodApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\TaxCategoryApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\TaxonTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\TaxonApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ZoneMemberApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ZoneApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\VerifyCustomerAccountApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Admin\ResetPasswordRequestApi($resourceClient, $pageFactory, $cursorFactory), ) ); diff --git a/src/SyliusAdminClientDecorator.php b/src/SyliusAdminClientDecorator.php index 59e6204..3334b60 100644 --- a/src/SyliusAdminClientDecorator.php +++ b/src/SyliusAdminClientDecorator.php @@ -87,4 +87,169 @@ public function getCurrencyApi(): Api\Admin\CurrencyApiInterface { return $this->decoratedClient->getCurrencyApi(); } + + public function getCustomerGroupApi(): Api\Admin\CustomerGroupApiInterface + { + return $this->decoratedClient->getCustomerGroupApi(); + } + + public function getCustomerApi(): Api\Admin\CustomerApiInterface + { + return $this->decoratedClient->getCustomerApi(); + } + + public function getExchangeRateApi(): Api\Admin\ExchangeRateApiInterface + { + return $this->decoratedClient->getExchangeRateApi(); + } + + public function getLocaleApi(): Api\Admin\LocaleApiInterface + { + return $this->decoratedClient->getLocaleApi(); + } + + public function getOrderItemUnitApi(): Api\Admin\OrderItemUnitApiInterface + { + return $this->decoratedClient->getOrderItemUnitApi(); + } + + public function getOrderItemApi(): Api\Admin\OrderItemApiInterface + { + return $this->decoratedClient->getOrderItemApi(); + } + + public function getOrderApi(): Api\Admin\OrderApiInterface + { + return $this->decoratedClient->getOrderApi(); + } + + public function getPaymentApi(): Api\Admin\PaymentApiInterface + { + return $this->decoratedClient->getPaymentApi(); + } + + public function getShipmentApi(): Api\Admin\ShipmentApiInterface + { + return $this->decoratedClient->getShipmentApi(); + } + + public function getPaymentMethodApi(): Api\Admin\PaymentMethodApiInterface + { + return $this->decoratedClient->getPaymentMethodApi(); + } + + public function getProductAssociationTypeTranslationApi(): Api\Admin\ProductAssociationTypeTranslationApiInterface + { + return $this->decoratedClient->getProductAssociationTypeTranslationApi(); + } + + public function getProductAssociationTypeApi(): Api\Admin\ProductAssociationTypeApiInterface + { + return $this->decoratedClient->getProductAssociationTypeApi(); + } + + public function getProductImageApi(): Api\Admin\ProductImageApiInterface + { + return $this->decoratedClient->getProductImageApi(); + } + + public function getProductOptionTranslationApi(): Api\Admin\ProductOptionTranslationApiInterface + { + return $this->decoratedClient->getProductOptionTranslationApi(); + } + + public function getProductOptionValueApi(): Api\Admin\ProductOptionValueApiInterface + { + return $this->decoratedClient->getProductOptionValueApi(); + } + + public function getProductOptionApi(): Api\Admin\ProductOptionApiInterface + { + return $this->decoratedClient->getProductOptionApi(); + } + + public function getProductReviewApi(): Api\Admin\ProductReviewApiInterface + { + return $this->decoratedClient->getProductReviewApi(); + } + + public function getProductTaxonApi(): Api\Admin\ProductTaxonApiInterface + { + return $this->decoratedClient->getProductTaxonApi(); + } + + public function getProductTranslationApi(): Api\Admin\ProductTranslationApiInterface + { + return $this->decoratedClient->getProductTranslationApi(); + } + + public function getProductVariantTranslationApi(): Api\Admin\ProductVariantTranslationApiInterface + { + return $this->decoratedClient->getProductVariantTranslationApi(); + } + + public function getProductVariantApi(): Api\Admin\ProductVariantApiInterface + { + return $this->decoratedClient->getProductVariantApi(); + } + + public function getProductApi(): Api\Admin\ProductApiInterface + { + return $this->decoratedClient->getProductApi(); + } + + public function getPromotionApi(): Api\Admin\PromotionApiInterface + { + return $this->decoratedClient->getPromotionApi(); + } + + public function getShippingCategoryApi(): Api\Admin\ShippingCategoryApiInterface + { + return $this->decoratedClient->getShippingCategoryApi(); + } + + public function getShippingMethodTranslationApi(): Api\Admin\ShippingMethodTranslationApiInterface + { + return $this->decoratedClient->getShippingMethodTranslationApi(); + } + + public function getShippingMethodApi(): Api\Admin\ShippingMethodApiInterface + { + return $this->decoratedClient->getShippingMethodApi(); + } + + public function getTaxCategoryApi(): Api\Admin\TaxCategoryApiInterface + { + return $this->decoratedClient->getTaxCategoryApi(); + } + + public function getTaxonTranslationApi(): Api\Admin\TaxonTranslationApiInterface + { + return $this->decoratedClient->getTaxonTranslationApi(); + } + + public function getTaxonApi(): Api\Admin\TaxonApiInterface + { + return $this->decoratedClient->getTaxonApi(); + } + + public function getZoneMemberApi(): Api\Admin\ZoneMemberApiInterface + { + return $this->decoratedClient->getZoneMemberApi(); + } + + public function getZoneApi(): Api\Admin\ZoneApiInterface + { + return $this->decoratedClient->getZoneApi(); + } + + public function getVerifyCustomerAccountApi(): Api\Admin\VerifyCustomerAccountApiInterface + { + return $this->decoratedClient->getVerifyCustomerAccountApi(); + } + + public function getResetPasswordRequestApi(): Api\Admin\ResetPasswordRequestApiInterface + { + return $this->decoratedClient->getResetPasswordRequestApi(); + } } diff --git a/src/SyliusAdminClientInterface.php b/src/SyliusAdminClientInterface.php index f2593d6..8f493bd 100644 --- a/src/SyliusAdminClientInterface.php +++ b/src/SyliusAdminClientInterface.php @@ -23,4 +23,31 @@ public function getExchangeRateApi(): Api\Admin\ExchangeRateApiInterface; public function getLocaleApi(): Api\Admin\LocaleApiInterface; public function getOrderItemUnitApi(): Api\Admin\OrderItemUnitApiInterface; public function getOrderItemApi(): Api\Admin\OrderItemApiInterface; + public function getOrderApi(): Api\Admin\OrderApiInterface; + public function getPaymentApi(): Api\Admin\PaymentApiInterface; + public function getShipmentApi(): Api\Admin\ShipmentApiInterface; + public function getPaymentMethodApi(): Api\Admin\PaymentMethodApiInterface; + public function getProductAssociationTypeTranslationApi(): Api\Admin\ProductAssociationTypeTranslationApiInterface; + public function getProductAssociationTypeApi(): Api\Admin\ProductAssociationTypeApiInterface; + public function getProductImageApi(): Api\Admin\ProductImageApiInterface; + public function getProductOptionTranslationApi(): Api\Admin\ProductOptionTranslationApiInterface; + public function getProductOptionValueApi(): Api\Admin\ProductOptionValueApiInterface; + public function getProductOptionApi(): Api\Admin\ProductOptionApiInterface; + public function getProductReviewApi(): Api\Admin\ProductReviewApiInterface; + public function getProductTaxonApi(): Api\Admin\ProductTaxonApiInterface; + public function getProductTranslationApi(): Api\Admin\ProductTranslationApiInterface; + public function getProductVariantTranslationApi(): Api\Admin\ProductVariantTranslationApiInterface; + public function getProductVariantApi(): Api\Admin\ProductVariantApiInterface; + public function getProductApi(): Api\Admin\ProductApiInterface; + public function getPromotionApi(): Api\Admin\PromotionApiInterface; + public function getShippingCategoryApi(): Api\Admin\ShippingCategoryApiInterface; + public function getShippingMethodTranslationApi(): Api\Admin\ShippingMethodTranslationApiInterface; + public function getShippingMethodApi(): Api\Admin\ShippingMethodApiInterface; + public function getTaxCategoryApi(): Api\Admin\TaxCategoryApiInterface; + public function getTaxonTranslationApi(): Api\Admin\TaxonTranslationApiInterface; + public function getTaxonApi(): Api\Admin\TaxonApiInterface; + public function getZoneMemberApi(): Api\Admin\ZoneMemberApiInterface; + public function getZoneApi(): Api\Admin\ZoneApiInterface; + public function getVerifyCustomerAccountApi(): Api\Admin\VerifyCustomerAccountApiInterface; + public function getResetPasswordRequestApi(): Api\Admin\ResetPasswordRequestApiInterface; } diff --git a/src/SyliusLegacyClientDecorator.php b/src/SyliusLegacyClientDecorator.php index d1023ce..6c15795 100644 --- a/src/SyliusLegacyClientDecorator.php +++ b/src/SyliusLegacyClientDecorator.php @@ -12,39 +12,13 @@ namespace Diglin\Sylius\ApiClient; use Diglin\Sylius\ApiClient\Api\ApiAwareInterface; -use Diglin\Sylius\ApiClient\Api\CartsApiInterface; -use Diglin\Sylius\ApiClient\Api\ChannelsApiInterface; -use Diglin\Sylius\ApiClient\Api\CountriesApiInterface; -use Diglin\Sylius\ApiClient\Api\CurrenciesApiInterface; -use Diglin\Sylius\ApiClient\Api\CustomersApiInterface; -use Diglin\Sylius\ApiClient\Api\ExchangeRatesApiInterface; -use Diglin\Sylius\ApiClient\Api\LocalesApiInterface; -use Diglin\Sylius\ApiClient\Api\OrdersApiInterface; -use Diglin\Sylius\ApiClient\Api\PaymentMethodsApiInterface; -use Diglin\Sylius\ApiClient\Api\PaymentsApiInterface; -use Diglin\Sylius\ApiClient\Api\ProductAssociationTypesApiInterface; -use Diglin\Sylius\ApiClient\Api\ProductAttributesApiInterface; -use Diglin\Sylius\ApiClient\Api\ProductOptionsApiInterface; -use Diglin\Sylius\ApiClient\Api\ProductReviewsApiInterface; -use Diglin\Sylius\ApiClient\Api\ProductsApiInterface; -use Diglin\Sylius\ApiClient\Api\ProductVariantsApiInterface; -use Diglin\Sylius\ApiClient\Api\PromotionCouponsApiInterface; -use Diglin\Sylius\ApiClient\Api\PromotionsApiInterface; -use Diglin\Sylius\ApiClient\Api\ShipmentsApiInterface; -use Diglin\Sylius\ApiClient\Api\ShippingCategoriesApi; -use Diglin\Sylius\ApiClient\Api\TaxCategoriesApiInterface; -use Diglin\Sylius\ApiClient\Api\TaxonsApiInterface; -use Diglin\Sylius\ApiClient\Api\TaxRatesApiInterface; -use Diglin\Sylius\ApiClient\Api\UsersApiInterface; -use Diglin\Sylius\ApiClient\Api\ZonesApiInterface; +use Diglin\Sylius\ApiClient\Api\Legacy AS Api; class SyliusLegacyClientDecorator implements SyliusLegacyClientInterface { - /** @var SyliusLegacyClientInterface */ - protected $decoratedClient; - - /** @var ApiAwareInterface[] */ - protected $apiRegistry = []; + private SyliusLegacyClientInterface $decoratedClient; + /** @var list */ + private array $apiRegistry = []; public function __construct( SyliusLegacyClientInterface $decoratedClient @@ -82,127 +56,127 @@ public function getRefreshToken(): ?string return $this->decoratedClient->getRefreshToken(); } - public function getChannelsApi(): ChannelsApiInterface + public function getChannelsApi(): Api\ChannelsApiInterface { return $this->decoratedClient->getChannelsApi(); } - public function getShippingCategoriesApi(): ShippingCategoriesApi + public function getShippingCategoriesApi(): Api\ShippingCategoriesApiInterface { return $this->decoratedClient->getShippingCategoriesApi(); } - public function getLocalesApi(): LocalesApiInterface + public function getLocalesApi(): Api\LocalesApiInterface { return $this->decoratedClient->getLocalesApi(); } - public function getCurrenciesApi(): CurrenciesApiInterface + public function getCurrenciesApi(): Api\CurrenciesApiInterface { return $this->decoratedClient->getCurrenciesApi(); } - public function getCountriesApi(): CountriesApiInterface + public function getCountriesApi(): Api\CountriesApiInterface { return $this->decoratedClient->getCountriesApi(); } - public function getExchangeRatesApi(): ExchangeRatesApiInterface + public function getExchangeRatesApi(): Api\ExchangeRatesApiInterface { return $this->decoratedClient->getExchangeRatesApi(); } - public function getPaymentMethodsApi(): PaymentMethodsApiInterface + public function getPaymentMethodsApi(): Api\PaymentMethodsApiInterface { return $this->decoratedClient->getPaymentMethodsApi(); } - public function getUsersApi(): UsersApiInterface + public function getUsersApi(): Api\UsersApiInterface { return $this->decoratedClient->getUsersApi(); } - public function getCustomersApi(): CustomersApiInterface + public function getCustomersApi(): Api\CustomersApiInterface { return $this->decoratedClient->getCustomersApi(); } - public function getProductsApi(): ProductsApiInterface + public function getProductsApi(): Api\ProductsApiInterface { return $this->decoratedClient->getProductsApi(); } - public function getProductAttributesApi(): ProductAttributesApiInterface + public function getProductAttributesApi(): Api\ProductAttributesApiInterface { return $this->decoratedClient->getProductAttributesApi(); } - public function getProductAssociationTypesApi(): ProductAssociationTypesApiInterface + public function getProductAssociationTypesApi(): Api\ProductAssociationTypesApiInterface { return $this->decoratedClient->getProductAssociationTypesApi(); } - public function getProductOptionsApi(): ProductOptionsApiInterface + public function getProductOptionsApi(): Api\ProductOptionsApiInterface { return $this->decoratedClient->getProductOptionsApi(); } - public function getProductReviewsApi(): ProductReviewsApiInterface + public function getProductReviewsApi(): Api\ProductReviewsApiInterface { return $this->decoratedClient->getProductReviewsApi(); } - public function getProductVariantsApi(): ProductVariantsApiInterface + public function getProductVariantsApi(): Api\ProductVariantsApiInterface { return $this->decoratedClient->getProductVariantsApi(); } - public function getPromotionsApi(): PromotionsApiInterface + public function getPromotionsApi(): Api\PromotionsApiInterface { return $this->decoratedClient->getPromotionsApi(); } - public function getPromotionCouponsApi(): PromotionCouponsApiInterface + public function getPromotionCouponsApi(): Api\PromotionCouponsApiInterface { return $this->decoratedClient->getPromotionCouponsApi(); } - public function getCartsApi(): CartsApiInterface + public function getCartsApi(): Api\CartsApiInterface { return $this->decoratedClient->getCartsApi(); } - public function getOrdersApi(): OrdersApiInterface + public function getOrdersApi(): Api\OrdersApiInterface { return $this->decoratedClient->getOrdersApi(); } - public function getPaymentsApi(): PaymentsApiInterface + public function getPaymentsApi(): Api\PaymentsApiInterface { return $this->decoratedClient->getPaymentsApi(); } - public function getShipmentsApi(): ShipmentsApiInterface + public function getShipmentsApi(): Api\ShipmentsApiInterface { return $this->decoratedClient->getShipmentsApi(); } - public function getTaxCategoriesApi(): TaxCategoriesApiInterface + public function getTaxCategoriesApi(): Api\TaxCategoriesApiInterface { return $this->decoratedClient->getTaxCategoriesApi(); } - public function getTaxRatesApi(): TaxRatesApiInterface + public function getTaxRatesApi(): Api\TaxRatesApiInterface { return $this->decoratedClient->getTaxRatesApi(); } - public function getTaxonsApi(): TaxonsApiInterface + public function getTaxonsApi(): Api\TaxonsApiInterface { return $this->decoratedClient->getTaxonsApi(); } - public function getZonesApi(): ZonesApiInterface + public function getZonesApi(): Api\ZonesApiInterface { return $this->decoratedClient->getZonesApi(); } From 5e12cea0aa4b2f55b38a416e9ffb1e4936fcd9b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Thu, 17 Mar 2022 10:07:30 +0100 Subject: [PATCH 08/13] Added more Shop API endpoints support --- src/Api/Shop/CurrencyApi.php | 25 ++++++ src/Api/Shop/CurrencyApiInterface.php | 9 +++ src/Api/Shop/CustomerApi.php | 48 +++++++++++ src/Api/Shop/CustomerApiInterface.php | 25 ++++++ src/Client/ResourceClient.php | 25 +++++- src/Client/ResourceClientInterface.php | 15 ++++ src/Stream/PatchResourceListResponse.php | 81 +++++++++++++++++++ .../PatchResourceListResponseFactory.php | 20 +++++ 8 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 src/Api/Shop/CurrencyApi.php create mode 100644 src/Api/Shop/CurrencyApiInterface.php create mode 100644 src/Api/Shop/CustomerApi.php create mode 100644 src/Api/Shop/CustomerApiInterface.php create mode 100644 src/Stream/PatchResourceListResponse.php create mode 100644 src/Stream/PatchResourceListResponseFactory.php diff --git a/src/Api/Shop/CurrencyApi.php b/src/Api/Shop/CurrencyApi.php new file mode 100644 index 0000000..c33853b --- /dev/null +++ b/src/Api/Shop/CurrencyApi.php @@ -0,0 +1,25 @@ +resourceClient->getResource('api/v2/shop/currencies/%d', [$code]); + } +} diff --git a/src/Api/Shop/CurrencyApiInterface.php b/src/Api/Shop/CurrencyApiInterface.php new file mode 100644 index 0000000..a0379b8 --- /dev/null +++ b/src/Api/Shop/CurrencyApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/shop/customers/%d', [$code]); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/customers', [], $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/shop/customers/%d', [$code], $data); + } + + public function changePassword($code, string $newPassword, string $confirmPassword, string $currentPassword): int + { + Assert::integer($code); + return $this->resourceClient->putResource('api/v2/shop/customers/%d/password', [$code], [ + 'newPassword' => $newPassword, + 'confirmNewPassword' => $confirmPassword, + 'currentPassword' => $currentPassword, + ]); + } +} diff --git a/src/Api/Shop/CustomerApiInterface.php b/src/Api/Shop/CustomerApiInterface.php new file mode 100644 index 0000000..06b8bec --- /dev/null +++ b/src/Api/Shop/CustomerApiInterface.php @@ -0,0 +1,25 @@ +upsertListResponseFactory->create($response->getBody()); + return $this->patchListResponseFactory->create($response->getBody()); + } + + public function putResource( + string|\Stringable $uri, + array $uriParameters = [], + array $body = [] + ): int { + unset($body['_links']); + + $uri = $this->uriGenerator->generate($uri, $uriParameters); + $response = $this->httpClient->sendRequest( + 'PUT', + $uri, + ['Content-Type' => 'application/json'], + json_encode($body) + ); + + return $response->getStatusCode(); } public function deleteResource( diff --git a/src/Client/ResourceClientInterface.php b/src/Client/ResourceClientInterface.php index f92e719..e3a6d90 100644 --- a/src/Client/ResourceClientInterface.php +++ b/src/Client/ResourceClientInterface.php @@ -6,6 +6,7 @@ use Diglin\Sylius\ApiClient\Exception\InvalidArgumentException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Diglin\Sylius\ApiClient\Stream\PatchResourceListResponse; use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -131,6 +132,20 @@ public function patchResource(string|\Stringable $uri, array $uriParameters = [] */ public function patchResourceList(string|\Stringable $uri, array $uriParameters = [], array|StreamInterface $resources = []): PatchResourceListResponse; + /** + * Updates partially the resource. + * + * @param string|\Stringable $uri URI of the resource + * @param array $uriParameters URI parameters of the resource + * @param array $body Body of the request + * + * @throws HttpException if the request failed + * + * @return int Status code 201 indicating that the resource has been well created. + * Status code 204 indicating that the resource has been well updated. + */ + public function putResource(string|\Stringable $uri, array $uriParameters = [], array $body = []): int; + /** * Deletes a resource. * diff --git a/src/Stream/PatchResourceListResponse.php b/src/Stream/PatchResourceListResponse.php new file mode 100644 index 0000000..6e6c83c --- /dev/null +++ b/src/Stream/PatchResourceListResponse.php @@ -0,0 +1,81 @@ + + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class PatchResourceListResponse implements \Iterator +{ + /** @var StreamInterface */ + protected $bodyStream; + + /** @var LineStreamReader */ + protected $streamReader; + + /** @var int */ + protected $lineNumber = 1; + + /** @var string */ + protected $line; + + public function __construct(StreamInterface $bodyStream, LineStreamReader $streamReader) + { + $this->bodyStream = $bodyStream; + $this->streamReader = $streamReader; + } + + /** + * {@inheritdoc} + */ + public function current() + { + return json_decode($this->line, true); + } + + /** + * {@inheritdoc} + */ + public function next() + { + $this->line = $this->streamReader->getNextLine($this->bodyStream); + ++$this->lineNumber; + } + + /** + * {@inheritdoc} + */ + public function key() + { + return $this->lineNumber; + } + + /** + * {@inheritdoc} + */ + public function valid() + { + return null !== $this->line; + } + + /** + * {@inheritdoc} + */ + public function rewind() + { + $this->bodyStream->rewind(); + $this->lineNumber = 1; + $this->line = $this->streamReader->getNextLine($this->bodyStream); + } +} diff --git a/src/Stream/PatchResourceListResponseFactory.php b/src/Stream/PatchResourceListResponseFactory.php new file mode 100644 index 0000000..10157c5 --- /dev/null +++ b/src/Stream/PatchResourceListResponseFactory.php @@ -0,0 +1,20 @@ + + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class PatchResourceListResponseFactory +{ + public function create(StreamInterface $bodyStream) + { + return new PatchResourceListResponse($bodyStream, new LineStreamReader()); + } +} From ac0ecdffccca5f6cb3a149fd47d11be5fd4cb626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Fri, 18 Mar 2022 23:46:43 +0100 Subject: [PATCH 09/13] Added more Shop API endpoints support --- src/Api/Shop/LocaleApi.php | 49 ++++++++++++ src/Api/Shop/LocaleApiInterface.php | 10 +++ src/Api/Shop/OrderApi.php | 87 ++++++++++++++++++++++ src/Api/Shop/OrderApiInterface.php | 45 +++++++++++ src/Api/Shop/OrderItemApi.php | 52 +++++++++++++ src/Api/Shop/OrderItemApiInterface.php | 10 +++ src/Api/Shop/OrderItemUnitApi.php | 19 +++++ src/Api/Shop/OrderItemUnitApiInterface.php | 9 +++ src/SyliusShopClient.php | 36 +++++++++ src/SyliusShopClientBuilder.php | 6 ++ 10 files changed, 323 insertions(+) create mode 100644 src/Api/Shop/LocaleApi.php create mode 100644 src/Api/Shop/LocaleApiInterface.php create mode 100644 src/Api/Shop/OrderApi.php create mode 100644 src/Api/Shop/OrderApiInterface.php create mode 100644 src/Api/Shop/OrderItemApi.php create mode 100644 src/Api/Shop/OrderItemApiInterface.php create mode 100644 src/Api/Shop/OrderItemUnitApi.php create mode 100644 src/Api/Shop/OrderItemUnitApiInterface.php diff --git a/src/Api/Shop/LocaleApi.php b/src/Api/Shop/LocaleApi.php new file mode 100644 index 0000000..6c408f2 --- /dev/null +++ b/src/Api/Shop/LocaleApi.php @@ -0,0 +1,49 @@ +resourceClient->getResource('api/v2/shop/locales/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/locales', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Shop/LocaleApiInterface.php b/src/Api/Shop/LocaleApiInterface.php new file mode 100644 index 0000000..7d6cf15 --- /dev/null +++ b/src/Api/Shop/LocaleApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/shop/orders/%d', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/orders', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/orders', [], $data); + } + + public function upsert($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->upsertResource('api/v2/shop/orders/%d', [$code]); + } + + public function listPaymentMethods( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->resourceClient->getResources('api/v2/shop/shipping-methods/%s', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + } + + public function listShipmentMethods( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->resourceClient->getResources('api/v2/shop/shipping-methods/%s', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + } +} diff --git a/src/Api/Shop/OrderApiInterface.php b/src/Api/Shop/OrderApiInterface.php new file mode 100644 index 0000000..8496e8c --- /dev/null +++ b/src/Api/Shop/OrderApiInterface.php @@ -0,0 +1,45 @@ +resourceClient->getResource('api/v2/shop/order-items/%d', [$code]); + } + + public function listPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/orders/{tokenValue}/items', [$code], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } +} diff --git a/src/Api/Shop/OrderItemApiInterface.php b/src/Api/Shop/OrderItemApiInterface.php new file mode 100644 index 0000000..3f69cb5 --- /dev/null +++ b/src/Api/Shop/OrderItemApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/shop/order-item-unit/%d', [$code]); + } +} diff --git a/src/Api/Shop/OrderItemUnitApiInterface.php b/src/Api/Shop/OrderItemUnitApiInterface.php new file mode 100644 index 0000000..53ccf3f --- /dev/null +++ b/src/Api/Shop/OrderItemUnitApiInterface.php @@ -0,0 +1,9 @@ +countryApi; } + + public function getCurrencyApi(): Api\Shop\CurrencyApiInterface + { + return $this->currencyApi; + } + + public function getCustomerApi(): Api\Shop\CustomerApiInterface + { + return $this->customerApi; + } + + public function getLocaleApi(): Api\Shop\LocaleApiInterface + { + return $this->localeApi; + } + + public function getOrderItemUnitApi(): Api\Shop\OrderItemUnitApiInterface + { + return $this->orderItemUnitApi; + } + + public function getOrderItemApi(): Api\Shop\OrderItemApiInterface + { + return $this->orderItemApi; + } + + public function getOrderApi(): Api\Shop\OrderApiInterface + { + return $this->orderApi; + } } diff --git a/src/SyliusShopClientBuilder.php b/src/SyliusShopClientBuilder.php index 9d42712..553f77e 100644 --- a/src/SyliusShopClientBuilder.php +++ b/src/SyliusShopClientBuilder.php @@ -139,6 +139,12 @@ private function buildAuthenticatedClient(Authentication $authentication): Syliu new Api\Shop\AdjustmentApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\ChannelApi($resourceClient), new Api\Shop\CountryApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\CurrencyApi($resourceClient), + new Api\Shop\CustomerApi($resourceClient), + new Api\Shop\LocaleApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\OrderItemUnitApi($resourceClient), + new Api\Shop\OrderItemApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\OrderApi($resourceClient, $pageFactory, $cursorFactory), ) ); From a8c094f269d809271e6be4aaf81d70b35c4c6260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Thu, 7 Apr 2022 17:54:26 +0200 Subject: [PATCH 10/13] Added all missing Shop API classes, some endpoints still missing --- src/Api/Admin/AdjustmentApi.php | 10 +- src/Api/Admin/OrderApi.php | 36 +++++- src/Api/Admin/OrderApiInterface.php | 35 +++++- src/Api/Admin/ProductOptionApi.php | 19 ++- src/Api/Admin/ProductOptionApiInterface.php | 12 +- src/Api/Admin/ProductVariantApi.php | 10 +- src/Api/Admin/ProductVariantApiInterface.php | 3 +- src/Api/Admin/PromotionApi.php | 6 + src/Api/Admin/PromotionApiInterface.php | 3 +- src/Api/Admin/ProvinceApi.php | 10 +- src/Api/Admin/ShopBillingDataApi.php | 10 +- src/Api/Admin/ZoneMemberApi.php | 8 +- src/Api/Legacy/ProductReviewsApi.php | 20 ++-- src/Api/Legacy/ProductVariantsApi.php | 16 +-- src/Api/Legacy/PromotionCouponsApi.php | 16 +-- .../CreatableDoubleResourceInterface.php | 23 ++++ .../DeletableDoubleResourceInterface.php | 10 +- .../GettableDoubleResourceInterface.php | 6 +- .../ListableDoubleResourceInterface.php | 12 +- src/Api/Shop/AdjustmentApi.php | 10 +- src/Api/Shop/CatalogPromotionApi.php | 19 +++ src/Api/Shop/CatalogPromotionApiInterface.php | 9 ++ src/Api/Shop/CurrencyApi.php | 24 ++++ src/Api/Shop/CurrencyApiInterface.php | 3 +- src/Api/Shop/OrderApi.php | 111 +++++++++++++++++- src/Api/Shop/OrderApiInterface.php | 87 +++++++++++++- src/Api/Shop/OrderItemApi.php | 56 ++++++++- src/Api/Shop/OrderItemApiInterface.php | 53 ++++++++- src/Api/Shop/PaymentApi.php | 7 ++ src/Api/Shop/PaymentApiInterface.php | 7 ++ src/Api/Shop/PaymentMethodApi.php | 7 ++ src/Api/Shop/PaymentMethodApiInterface.php | 7 ++ src/Api/Shop/ProductApi.php | 7 ++ src/Api/Shop/ProductApiInterface.php | 7 ++ src/Api/Shop/ProductImageApi.php | 7 ++ src/Api/Shop/ProductImageApiInterface.php | 7 ++ src/Api/Shop/ProductOptionApi.php | 7 ++ src/Api/Shop/ProductOptionApiInterface.php | 7 ++ src/Api/Shop/ProductOptionValueApi.php | 7 ++ .../Shop/ProductOptionValueApiInterface.php | 7 ++ src/Api/Shop/ProductReviewApi.php | 7 ++ src/Api/Shop/ProductReviewApiInterface.php | 7 ++ src/Api/Shop/ProductTaxonApi.php | 7 ++ src/Api/Shop/ProductTaxonApiInterface.php | 7 ++ src/Api/Shop/ProductTranslationApi.php | 7 ++ .../Shop/ProductTranslationApiInterface.php | 7 ++ src/Api/Shop/ProductVariantApi.php | 7 ++ src/Api/Shop/ProductVariantApiInterface.php | 7 ++ src/Api/Shop/ProductVariantTranslationApi.php | 7 ++ .../ProductVariantTranslationApiInterface.php | 7 ++ src/Api/Shop/ResetPasswordRequestApi.php | 7 ++ .../Shop/ResetPasswordRequestApiInterface.php | 7 ++ src/Api/Shop/ShipmentApi.php | 7 ++ src/Api/Shop/ShipmentApiInterface.php | 7 ++ src/Api/Shop/ShippingMethodApi.php | 7 ++ src/Api/Shop/ShippingMethodApiInterface.php | 7 ++ src/Api/Shop/TaxonApi.php | 7 ++ src/Api/Shop/TaxonApiInterface.php | 7 ++ src/Api/Shop/TaxonTranslationApi.php | 7 ++ src/Api/Shop/TaxonTranslationApiInterface.php | 7 ++ src/Api/Shop/VerifyCustomerAccountApi.php | 7 ++ .../VerifyCustomerAccountApiInterface.php | 7 ++ src/Client/ResourceClient.php | 2 +- src/SyliusShopClient.php | 109 ++++++++++++++++- src/SyliusShopClientBuilder.php | 25 +++- src/SyliusShopClientInterface.php | 24 ++++ 66 files changed, 937 insertions(+), 98 deletions(-) create mode 100644 src/Api/Operation/CreatableDoubleResourceInterface.php create mode 100644 src/Api/Shop/CatalogPromotionApi.php create mode 100644 src/Api/Shop/CatalogPromotionApiInterface.php create mode 100644 src/Api/Shop/PaymentApi.php create mode 100644 src/Api/Shop/PaymentApiInterface.php create mode 100644 src/Api/Shop/PaymentMethodApi.php create mode 100644 src/Api/Shop/PaymentMethodApiInterface.php create mode 100644 src/Api/Shop/ProductApi.php create mode 100644 src/Api/Shop/ProductApiInterface.php create mode 100644 src/Api/Shop/ProductImageApi.php create mode 100644 src/Api/Shop/ProductImageApiInterface.php create mode 100644 src/Api/Shop/ProductOptionApi.php create mode 100644 src/Api/Shop/ProductOptionApiInterface.php create mode 100644 src/Api/Shop/ProductOptionValueApi.php create mode 100644 src/Api/Shop/ProductOptionValueApiInterface.php create mode 100644 src/Api/Shop/ProductReviewApi.php create mode 100644 src/Api/Shop/ProductReviewApiInterface.php create mode 100644 src/Api/Shop/ProductTaxonApi.php create mode 100644 src/Api/Shop/ProductTaxonApiInterface.php create mode 100644 src/Api/Shop/ProductTranslationApi.php create mode 100644 src/Api/Shop/ProductTranslationApiInterface.php create mode 100644 src/Api/Shop/ProductVariantApi.php create mode 100644 src/Api/Shop/ProductVariantApiInterface.php create mode 100644 src/Api/Shop/ProductVariantTranslationApi.php create mode 100644 src/Api/Shop/ProductVariantTranslationApiInterface.php create mode 100644 src/Api/Shop/ResetPasswordRequestApi.php create mode 100644 src/Api/Shop/ResetPasswordRequestApiInterface.php create mode 100644 src/Api/Shop/ShipmentApi.php create mode 100644 src/Api/Shop/ShipmentApiInterface.php create mode 100644 src/Api/Shop/ShippingMethodApi.php create mode 100644 src/Api/Shop/ShippingMethodApiInterface.php create mode 100644 src/Api/Shop/TaxonApi.php create mode 100644 src/Api/Shop/TaxonApiInterface.php create mode 100644 src/Api/Shop/TaxonTranslationApi.php create mode 100644 src/Api/Shop/TaxonTranslationApiInterface.php create mode 100644 src/Api/Shop/VerifyCustomerAccountApi.php create mode 100644 src/Api/Shop/VerifyCustomerAccountApiInterface.php diff --git a/src/Api/Admin/AdjustmentApi.php b/src/Api/Admin/AdjustmentApi.php index 5505103..784e56d 100644 --- a/src/Api/Admin/AdjustmentApi.php +++ b/src/Api/Admin/AdjustmentApi.php @@ -26,26 +26,26 @@ public function get($code): array } public function listPerPage( - $code, + $parentCode, int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - Assert::string($code); - $data = $this->resourceClient->getResources('api/v2/admin/order-items/%s/adjustments', [$code]); + Assert::string($parentCode); + $data = $this->resourceClient->getResources('api/v2/admin/order-items/%s/adjustments', [$parentCode]); return $this->pageFactory->createPage($data); } public function all( - $code, + $parentCode, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $data); } diff --git a/src/Api/Admin/OrderApi.php b/src/Api/Admin/OrderApi.php index 105a1d8..a7913ac 100644 --- a/src/Api/Admin/OrderApi.php +++ b/src/Api/Admin/OrderApi.php @@ -53,27 +53,51 @@ public function cancel(string $code, array $data = []): int return $this->resourceClient->patchResource('api/v2/admin/orders/%s/cancel', [$code], $data); } - public function listPayments( + public function listPaymentsPerPage( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/orders/%s/payments', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function allPayments( string $code, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $data = $this->resourceClient->getResources('api/v2/admin/orders/%s/payments', [], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->listPaymentsPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } - return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + public function listShipmentsPerPage( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/admin/orders/%s/shipments', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); } - public function listShipments( + public function allShipments( string $code, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $data = $this->resourceClient->getResources('api/v2/admin/orders/%s/shipments', [], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->listShipmentsPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); - return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + return $this->cursorFactory->createCursor($pageSize, $data); } } diff --git a/src/Api/Admin/OrderApiInterface.php b/src/Api/Admin/OrderApiInterface.php index ba0e9d4..9edec48 100644 --- a/src/Api/Admin/OrderApiInterface.php +++ b/src/Api/Admin/OrderApiInterface.php @@ -6,6 +6,7 @@ use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; @@ -27,7 +28,22 @@ public function cancel(string $code, array $data = []): int; * * @throws HttpException if the request failed */ - public function listPayments( + public function listPaymentsPerPage( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + /** + * Lists an order payments. + * + * @param string $code Code of the order + * + * @throws HttpException if the request failed + */ + public function allPayments( string $code, int $pageSize = 10, array $queryParameters = [], @@ -42,7 +58,22 @@ public function listPayments( * * @throws HttpException if the request failed */ - public function listShipments( + public function listShipmentsPerPage( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + /** + * Lists an order shipments. + * + * @param string $code Code of the order + * + * @throws HttpException if the request failed + */ + public function allShipments( string $code, int $pageSize = 10, array $queryParameters = [], diff --git a/src/Api/Admin/ProductOptionApi.php b/src/Api/Admin/ProductOptionApi.php index 2ce5e10..6d964ad 100644 --- a/src/Api/Admin/ProductOptionApi.php +++ b/src/Api/Admin/ProductOptionApi.php @@ -59,16 +59,29 @@ public function upsert($code, array $data = []): int return $this->resourceClient->upsertResource('api/v2/admin/product-options/%s', [$code], $data); } - public function listValues( + public function listValuesPerPage( string $code, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ): ResourceCursorInterface { + ): PageInterface { Assert::string($code); $data = $this->resourceClient->getResources('api/v2/admin/product-options/%s/values', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); - return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + return $this->pageFactory->createPage($data); + } + + public function allValues( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + Assert::string($code); + $data = $this->listValuesPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); } } diff --git a/src/Api/Admin/ProductOptionApiInterface.php b/src/Api/Admin/ProductOptionApiInterface.php index 1b11d72..1be2f3c 100644 --- a/src/Api/Admin/ProductOptionApiInterface.php +++ b/src/Api/Admin/ProductOptionApiInterface.php @@ -8,8 +8,10 @@ use Diglin\Sylius\ApiClient\Api\Operation\UpsertableResourceInterface; use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; interface ProductOptionApiInterface extends GettableResourceInterface, ListableResourceInterface, CreatableResourceInterface, UpsertableResourceInterface { @@ -20,7 +22,15 @@ interface ProductOptionApiInterface extends GettableResourceInterface, ListableR * * @throws HttpException if the request failed */ - public function listValues( + public function listValuesPerPage( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + public function allValues( string $code, int $pageSize = 10, array $queryParameters = [], diff --git a/src/Api/Admin/ProductVariantApi.php b/src/Api/Admin/ProductVariantApi.php index 90c791a..c797833 100644 --- a/src/Api/Admin/ProductVariantApi.php +++ b/src/Api/Admin/ProductVariantApi.php @@ -25,10 +25,10 @@ public function get($code): array return $this->resourceClient->getResource('api/v2/admin/product-variants/%s', [$code]); } - public function upsert($code, array $data = []): int + public function create($code, array $data = []): int { Assert::string($code); - return $this->resourceClient->upsertResource('api/v2/admin/product-variants/%s', [$code]); + return $this->resourceClient->createResource('api/v2/admin/product-variants', [], $data); } public function listPerPage( @@ -52,4 +52,10 @@ public function all( return $this->cursorFactory->createCursor($pageSize, $data); } + + public function upsert($code, array $data = []): int + { + Assert::string($code); + return $this->resourceClient->upsertResource('api/v2/admin/product-variants/%s', [$code]); + } } diff --git a/src/Api/Admin/ProductVariantApiInterface.php b/src/Api/Admin/ProductVariantApiInterface.php index c733329..857da03 100644 --- a/src/Api/Admin/ProductVariantApiInterface.php +++ b/src/Api/Admin/ProductVariantApiInterface.php @@ -2,10 +2,11 @@ namespace Diglin\Sylius\ApiClient\Api\Admin; +use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\UpsertableResourceInterface; -interface ProductVariantApiInterface extends GettableResourceInterface, ListableResourceInterface, UpsertableResourceInterface +interface ProductVariantApiInterface extends GettableResourceInterface, ListableResourceInterface, CreatableResourceInterface, UpsertableResourceInterface { } diff --git a/src/Api/Admin/PromotionApi.php b/src/Api/Admin/PromotionApi.php index 68e3bb3..cc8243d 100644 --- a/src/Api/Admin/PromotionApi.php +++ b/src/Api/Admin/PromotionApi.php @@ -25,6 +25,12 @@ public function get($code): array return $this->resourceClient->getResource('api/v2/admin/promotions/%d', [$code]); } + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/admin/promotions', [], $data); + } + public function listPerPage( int $limit = 10, array $queryParameters = [], diff --git a/src/Api/Admin/PromotionApiInterface.php b/src/Api/Admin/PromotionApiInterface.php index a0679d3..7488371 100644 --- a/src/Api/Admin/PromotionApiInterface.php +++ b/src/Api/Admin/PromotionApiInterface.php @@ -2,10 +2,11 @@ namespace Diglin\Sylius\ApiClient\Api\Admin; +use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\DeletableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; -interface PromotionApiInterface extends GettableResourceInterface, ListableResourceInterface, DeletableResourceInterface +interface PromotionApiInterface extends GettableResourceInterface, ListableResourceInterface, CreatableResourceInterface, DeletableResourceInterface { } diff --git a/src/Api/Admin/ProvinceApi.php b/src/Api/Admin/ProvinceApi.php index e89bc8b..489e0f0 100644 --- a/src/Api/Admin/ProvinceApi.php +++ b/src/Api/Admin/ProvinceApi.php @@ -26,26 +26,26 @@ public function get($code): array } public function listPerPage( - $code, + $parentCode, int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - $data = $this->resourceClient->getResources('api/v2/admin/countries/%d/provinces', [$code], $limit, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->resourceClient->getResources('api/v2/admin/countries/%d/provinces', [$parentCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); } public function all( - $code, + $parentCode, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - Assert::string($code); - $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + Assert::string($parentCode); + $data = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $data); } diff --git a/src/Api/Admin/ShopBillingDataApi.php b/src/Api/Admin/ShopBillingDataApi.php index 6f1f750..1a43cfb 100644 --- a/src/Api/Admin/ShopBillingDataApi.php +++ b/src/Api/Admin/ShopBillingDataApi.php @@ -26,26 +26,26 @@ public function get($code): array } public function listPerPage( - $code, + $parentCode, int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - Assert::string($code); - $data = $this->resourceClient->getResources('api/v2/admin/channels/%s/shop-billing-data', [$code]); + Assert::string($parentCode); + $data = $this->resourceClient->getResources('api/v2/admin/channels/%s/shop-billing-data', [$parentCode]); return $this->pageFactory->createPage($data); } public function all( - $code, + $parentCode, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $data); } diff --git a/src/Api/Admin/ZoneMemberApi.php b/src/Api/Admin/ZoneMemberApi.php index ba5665b..e066993 100644 --- a/src/Api/Admin/ZoneMemberApi.php +++ b/src/Api/Admin/ZoneMemberApi.php @@ -26,25 +26,25 @@ public function get($code): array } public function listPerPage( - $code, + $parentCode, int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - $data = $this->resourceClient->getResources('api/v2/admin/zones/%s/members', [$code], $limit, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->resourceClient->getResources('api/v2/admin/zones/%s/members', [$parentCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); } public function all( - $code, + $parentCode, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $data); } diff --git a/src/Api/Legacy/ProductReviewsApi.php b/src/Api/Legacy/ProductReviewsApi.php index 34d7e70..5982e92 100644 --- a/src/Api/Legacy/ProductReviewsApi.php +++ b/src/Api/Legacy/ProductReviewsApi.php @@ -38,41 +38,41 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - public function get($productCode, $id): array + public function get($parentCode, $code): array { - return $this->resourceClient->getResource(static::ENDPOINT_URI, [$productCode, $id]); + return $this->resourceClient->getResource(static::ENDPOINT_URI, [$parentCode, $code]); } - public function create($productCode, array $data = []): int + public function create($code, array $data = []): int { - return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$productCode], $data); + return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - public function delete($productCode, $id): int + public function delete($parentCode, $code): int { - return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$productCode, $id]); + return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$parentCode, $code]); } public function all( - string $productCode, + $parentCode, $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $firstPage = $this->listPerPage($productCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $firstPage = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } public function listPerPage( - string $productCode, + $parentCode, $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$productCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$parentCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); } diff --git a/src/Api/Legacy/ProductVariantsApi.php b/src/Api/Legacy/ProductVariantsApi.php index d2cbaf4..dac7c09 100644 --- a/src/Api/Legacy/ProductVariantsApi.php +++ b/src/Api/Legacy/ProductVariantsApi.php @@ -38,9 +38,9 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - public function get($productCode, $variantCode): array + public function get($parentCode, $code): array { - return $this->resourceClient->getResource(static::ENDPOINT_URI, [$productCode, $variantCode]); + return $this->resourceClient->getResource(static::ENDPOINT_URI, [$parentCode, $code]); } public function create($code, array $data = []): int @@ -48,31 +48,31 @@ public function create($code, array $data = []): int return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - public function delete($productCode, $variantCode): int + public function delete($parentCode, $code): int { - return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$productCode, $variantCode]); + return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$parentCode, $code]); } public function all( - $productCode, + $parentCode, $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $firstPage = $this->listPerPage($productCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $firstPage = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } public function listPerPage( - $productCode, + $parentCode, $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$productCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$parentCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); } diff --git a/src/Api/Legacy/PromotionCouponsApi.php b/src/Api/Legacy/PromotionCouponsApi.php index 965d840..f5d4ba4 100644 --- a/src/Api/Legacy/PromotionCouponsApi.php +++ b/src/Api/Legacy/PromotionCouponsApi.php @@ -38,9 +38,9 @@ public function __construct( $this->cursorFactory = $cursorFactory; } - public function get($promotionCode, $couponCode): array + public function get($parentCode, $code): array { - return $this->resourceClient->getResource(static::ENDPOINT_URI, [$promotionCode, $couponCode]); + return $this->resourceClient->getResource(static::ENDPOINT_URI, [$parentCode, $code]); } public function create($code, array $data = []): int @@ -48,31 +48,31 @@ public function create($code, array $data = []): int return $this->resourceClient->createResource(static::ENDPOINTS_URI, [$code], $data); } - public function delete($promotionCode, $couponCode): int + public function delete($parentCode, $code): int { - return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$promotionCode, $couponCode]); + return $this->resourceClient->deleteResource(static::ENDPOINT_URI, [$parentCode, $code]); } public function all( - $promotionCode, + $parentCode, $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $firstPage = $this->listPerPage($promotionCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $firstPage = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $firstPage); } public function listPerPage( - $promotionCode, + $parentCode, $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$promotionCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->resourceClient->getResources(static::ENDPOINTS_URI, [$parentCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); } diff --git a/src/Api/Operation/CreatableDoubleResourceInterface.php b/src/Api/Operation/CreatableDoubleResourceInterface.php new file mode 100644 index 0000000..e36da10 --- /dev/null +++ b/src/Api/Operation/CreatableDoubleResourceInterface.php @@ -0,0 +1,23 @@ +resourceClient->getResources('api/v2/shop/orders/%s/adjustments', [$code]); + Assert::string($parentCode); + $data = $this->resourceClient->getResources('api/v2/shop/orders/%s/adjustments', [$parentCode]); return $this->pageFactory->createPage($data); } public function all( - $code, + $parentCode, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $data); } diff --git a/src/Api/Shop/CatalogPromotionApi.php b/src/Api/Shop/CatalogPromotionApi.php new file mode 100644 index 0000000..9412ace --- /dev/null +++ b/src/Api/Shop/CatalogPromotionApi.php @@ -0,0 +1,19 @@ +resourceClient->getResource('api/v2/shop/catalog-promotions/%d'); + } +} diff --git a/src/Api/Shop/CatalogPromotionApiInterface.php b/src/Api/Shop/CatalogPromotionApiInterface.php new file mode 100644 index 0000000..c178d26 --- /dev/null +++ b/src/Api/Shop/CatalogPromotionApiInterface.php @@ -0,0 +1,9 @@ +resourceClient->getResource('api/v2/shop/currencies/%d', [$code]); } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/currencies', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/CurrencyApiInterface.php b/src/Api/Shop/CurrencyApiInterface.php index a0379b8..680d3e5 100644 --- a/src/Api/Shop/CurrencyApiInterface.php +++ b/src/Api/Shop/CurrencyApiInterface.php @@ -3,7 +3,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; -interface CurrencyApiInterface extends GettableResourceInterface +interface CurrencyApiInterface extends GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/Shop/OrderApi.php b/src/Api/Shop/OrderApi.php index 318d3fa..43d6ab6 100644 --- a/src/Api/Shop/OrderApi.php +++ b/src/Api/Shop/OrderApi.php @@ -4,7 +4,6 @@ use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Diglin\Sylius\ApiClient\Exception\HttpException; -use Diglin\Sylius\ApiClient\Exception\InvalidArgumentException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; use Diglin\Sylius\ApiClient\Pagination\PageInterface; @@ -61,27 +60,127 @@ public function upsert($code, array $data = []): int return $this->resourceClient->upsertResource('api/v2/shop/orders/%d', [$code]); } - public function listPaymentMethods( + public function listPaymentMethodsPerPage( string $code, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null - ): ResourceCursorInterface { + ): PageInterface { $data = $this->resourceClient->getResources('api/v2/shop/shipping-methods/%s', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); - return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + return $this->pageFactory->createPage($data); } - public function listShipmentMethods( + public function allPaymentMethods( string $code, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { + $data = $this->listPaymentMethodsPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function listShipmentMethodsPerPage( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { $data = $this->resourceClient->getResources('api/v2/shop/shipping-methods/%s', [$code], $pageSize, $queryParameters, $filterBuilder, $sortBuilder); - return $this->cursorFactory->createCursor($pageSize, $this->pageFactory->createPage($data)); + return $this->pageFactory->createPage($data); + } + + public function allShipmentMethods( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listShipmentMethodsPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function listAdjustmentsPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/shop/orders/%s/adjustments', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function allAdjustments( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listAdjustmentsPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function listItemsPerPage( + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($code); + $data = $this->resourceClient->getResources('api/v2/shop/orders/%s/items', [$code]); + + return $this->pageFactory->createPage($data); + } + + public function allItems( + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listItemsPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function choosePayment(string $code, string $paymentId, string $paymentMethod): int + { + Assert::string($code); + Assert::string($paymentId); + return $this->resourceClient->patchResource('api/v2/shop/orders/%1$s/payments/%2$s', [$code, $paymentId], [ + 'paymentMethod' => $paymentMethod, + ]); + } + + public function chooseShipment(string $code, string $shipmentId, string $shippingMethod): int + { + Assert::string($code); + Assert::string($shipmentId); + return $this->resourceClient->patchResource('api/v2/shop/orders/%1$s/shipments/%2$s', [$code, $shipmentId], [ + 'shippingMethod' => $shippingMethod, + ]); + } + + public function complete(string $code, string $notes): int + { + Assert::string($code); + return $this->resourceClient->patchResource('api/v2/shop/orders/%s/complete', [$code], [ + 'notes' => $notes, + ]); } } diff --git a/src/Api/Shop/OrderApiInterface.php b/src/Api/Shop/OrderApiInterface.php index 8496e8c..e390e7d 100644 --- a/src/Api/Shop/OrderApiInterface.php +++ b/src/Api/Shop/OrderApiInterface.php @@ -8,6 +8,7 @@ use Diglin\Sylius\ApiClient\Api\Operation\UpsertableResourceInterface; use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; @@ -20,7 +21,15 @@ interface OrderApiInterface extends GettableResourceInterface, ListableResourceI * * @throws HttpException if the request failed */ - public function listPaymentMethods( + public function listPaymentMethodsPerPage( + string $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + public function allPaymentMethods( string $code, int $pageSize = 10, array $queryParameters = [], @@ -35,11 +44,85 @@ public function listPaymentMethods( * * @throws HttpException if the request failed */ - public function listShipmentMethods( + public function listShipmentMethodsPerPage( + string $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + public function allShipmentMethods( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface; + + public function listAdjustmentsPerPage( + string $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + public function allAdjustments( + string $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface; + + public function listItemsPerPage( + string $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + public function allItems( string $code, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface; + + /** + * Lists an order shipments. + * + * @param string $code Code of the order + * @param string $paymentId Id of the payment + * @param string $shippingMethod The chosen payment method + * + * @throws HttpException if the request failed + */ + public function choosePayment(string $code, string $paymentId, string $paymentMethod): int; + + /** + * Lists an order shipments. + * + * @param string $code Code of the order + * @param string $shipmentId Id of the shipment + * @param string $shippingMethod The chosen shipment method + * + * @throws HttpException if the request failed + */ + public function chooseShipment(string $code, string $shipmentId, string $shippingMethod): int; + + /** + * Lists an order shipments. + * + * @param string $code Code of the order + * @param string $notes Notes to add to the order + * + * @returns 200 if the request has succeeded + * + * @throws HttpException if the request failed + */ + public function complete(string $code, string $notes): int; } diff --git a/src/Api/Shop/OrderItemApi.php b/src/Api/Shop/OrderItemApi.php index c4256b4..df202d0 100644 --- a/src/Api/Shop/OrderItemApi.php +++ b/src/Api/Shop/OrderItemApi.php @@ -3,7 +3,6 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; -use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; use Diglin\Sylius\ApiClient\Pagination\PageInterface; @@ -27,25 +26,74 @@ public function get($code): array } public function listPerPage( - $code, + $parentCode, int $limit = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): PageInterface { - $data = $this->resourceClient->getResources('api/v2/shop/orders/{tokenValue}/items', [$code], $limit, $queryParameters, $filterBuilder, $sortBuilder); + Assert::integer($parentCode); + $data = $this->resourceClient->getResources('api/v2/shop/orders/%d/items', [$parentCode], $limit, $queryParameters, $filterBuilder, $sortBuilder); return $this->pageFactory->createPage($data); } public function all( + $parentCode, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($parentCode, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($parentCode, $code, array $data = []): int + { + Assert::integer($parentCode); + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/orders/%d/items', [$parentCode], $data); + } + + public function delete($parentCode, $code): int + { + Assert::integer($parentCode); + Assert::integer($code); + return $this->resourceClient->deleteResource('api/v2/shop/orders/%1$d/items/%2$d', [$parentCode, $code]); + } + + public function changeQuantity($parentCode, $code, int $quantity): int + { + return $this->resourceClient->patchResource('api/v2/shop/orders/%1$d/items/%2%d', [$parentCode, $code], [ + 'quantity' => $quantity, + ]); + } + + public function listAdjustmentsPerPage( + $parentCode, + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + Assert::string($parentCode); + $data = $this->resourceClient->getResources('api/v2/shop/orders/%1$s/items/%1$d/adjustments', [$parentCode, $code]); + + return $this->pageFactory->createPage($data); + } + + public function allAdjustments( + $parentCode, $code, int $pageSize = 10, array $queryParameters = [], FilterBuilderInterface $filterBuilder = null, SortBuilderInterface $sortBuilder = null ): ResourceCursorInterface { - $data = $this->listPerPage($code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); + $data = $this->listAdjustmentsPerPage($parentCode, $code, $pageSize, $queryParameters, $filterBuilder, $sortBuilder); return $this->cursorFactory->createCursor($pageSize, $data); } diff --git a/src/Api/Shop/OrderItemApiInterface.php b/src/Api/Shop/OrderItemApiInterface.php index 3f69cb5..6ed1f69 100644 --- a/src/Api/Shop/OrderItemApiInterface.php +++ b/src/Api/Shop/OrderItemApiInterface.php @@ -2,9 +2,60 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Api\Operation\CreatableDoubleResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\DeletableDoubleResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; use Diglin\Sylius\ApiClient\Api\Operation\ListableDoubleResourceInterface; +use Diglin\Sylius\ApiClient\Exception\HttpException; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; -interface OrderItemApiInterface extends GettableResourceInterface, ListableDoubleResourceInterface +interface OrderItemApiInterface extends GettableResourceInterface, CreatableDoubleResourceInterface, ListableDoubleResourceInterface, DeletableDoubleResourceInterface { + public function changeQuantity($parentCode, $code, int $quantity): int; + + /** + * Gets a list of resources by returning the first page. + * Consequently, this method does not return all the resources. + * + * @param string|int $parentCode Code of the parent resource + * @param string|int $code Code of the resource + * @param int $limit The maximum number of resources to return. + * Do note that the server has a maximum limit allowed. + * @param array $queryParameters additional query parameters to pass in the request + * + * @return PageInterface + *@throws HttpException if the request failed + * + */ + public function listAdjustmentsPerPage( + $parentCode, + $code, + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface; + + /** + * Gets a cursor to iterate over a list of resources. + * + * @param string|int $parentCode Code of the parent resource + * @param string|int $code Code of the resource + * @param int $pageSize The size of the page returned by the server. + * Do note that the server has a maximum limit allowed. + * @param array $queryParameters Additional query parameters to pass in the request + * + * @return ResourceCursorInterface + */ + public function allAdjustments( + $parentCode, + $code, + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface; } diff --git a/src/Api/Shop/PaymentApi.php b/src/Api/Shop/PaymentApi.php new file mode 100644 index 0000000..82d403a --- /dev/null +++ b/src/Api/Shop/PaymentApi.php @@ -0,0 +1,7 @@ +uriGenerator->generate($uri, $uriParameters); $response = $this->httpClient->sendRequest( - 'PATCH', + 'PUT', $uri, ['Content-Type' => 'application/json'], $body diff --git a/src/SyliusShopClient.php b/src/SyliusShopClient.php index dd38697..4d29a57 100644 --- a/src/SyliusShopClient.php +++ b/src/SyliusShopClient.php @@ -4,7 +4,6 @@ use Diglin\Sylius\ApiClient\Api; use Diglin\Sylius\ApiClient\Security\Authentication; -use phpDocumentor\Reflection\Utils; class SyliusShopClient implements SyliusShopClientInterface { @@ -12,6 +11,7 @@ public function __construct( private Authentication $authentication, private Api\Shop\AddressApiInterface $addressApi, private Api\Shop\AdjustmentApiInterface $adjustmentApi, + private Api\Shop\CatalogPromotionApiInterface $catalogPromotionApi, private Api\Shop\ChannelApiInterface $channelApi, private Api\Shop\CountryApiInterface $countryApi, private Api\Shop\CurrencyApiInterface $currencyApi, @@ -20,6 +20,23 @@ public function __construct( private Api\Shop\OrderItemUnitApiInterface $orderItemUnitApi, private Api\Shop\OrderItemApiInterface $orderItemApi, private Api\Shop\OrderApiInterface $orderApi, + private Api\Shop\PaymentApiInterface $paymentApi, + private Api\Shop\ShipmentApiInterface $shipmentApi, + private Api\Shop\PaymentMethodApiInterface $paymentMethodApi, + private Api\Shop\ProductImageApiInterface $productImageApi, + private Api\Shop\ProductOptionValueApiInterface $productOptionValueApi, + private Api\Shop\ProductOptionApiInterface $productOptionApi, + private Api\Shop\ProductReviewApiInterface $productReviewApi, + private Api\Shop\ProductTaxonApiInterface $productTaxonApi, + private Api\Shop\ProductTranslationApiInterface $productTranslationApi, + private Api\Shop\ProductVariantTranslationApiInterface $productVariantTranslationApi, + private Api\Shop\ProductVariantApiInterface $productVariantApi, + private Api\Shop\ProductApiInterface $productApi, + private Api\Shop\ShippingMethodApiInterface $shippingMethodApi, + private Api\Shop\TaxonTranslationApiInterface $taxonTranslationApi, + private Api\Shop\TaxonApiInterface $taxonApi, + private Api\Shop\VerifyCustomerAccountApiInterface $verifyCustomerAccountApi, + private Api\Shop\ResetPasswordRequestApiInterface $resetPasswordRequestApi, ) {} public function getAddressApi(): Api\Shop\AddressApiInterface @@ -32,6 +49,11 @@ public function getAdjustmentApi(): Api\Shop\AdjustmentApiInterface return $this->adjustmentApi; } + public function getCatalogPromotionApi(): Api\Shop\CatalogPromotionApiInterface + { + return $this->catalogPromotionApi; + } + public function getChannelApi(): Api\Shop\ChannelApiInterface { return $this->channelApi; @@ -71,4 +93,89 @@ public function getOrderApi(): Api\Shop\OrderApiInterface { return $this->orderApi; } + + public function getPaymentApi(): Api\Shop\PaymentApiInterface + { + return $this->paymentApi; + } + + public function getShipmentApi(): Api\Shop\ShipmentApiInterface + { + return $this->shipmentApi; + } + + public function getPaymentMethodApi(): Api\Shop\PaymentMethodApiInterface + { + return $this->paymentMethodApi; + } + + public function getProductImageApi(): Api\Shop\ProductImageApiInterface + { + return $this->productImageApi; + } + + public function getProductOptionValueApi(): Api\Shop\ProductOptionValueApiInterface + { + return $this->productOptionValueApi; + } + + public function getProductOptionApi(): Api\Shop\ProductOptionApiInterface + { + return $this->productOptionApi; + } + + public function getProductReviewApi(): Api\Shop\ProductReviewApiInterface + { + return $this->productReviewApi; + } + + public function getProductTaxonApi(): Api\Shop\ProductTaxonApiInterface + { + return $this->productTaxonApi; + } + + public function getProductTranslationApi(): Api\Shop\ProductTranslationApiInterface + { + return $this->productTranslationApi; + } + + public function getProductVariantTranslationApi(): Api\Shop\ProductVariantTranslationApiInterface + { + return $this->productVariantTranslationApi; + } + + public function getProductVariantApi(): Api\Shop\ProductVariantApiInterface + { + return $this->productVariantApi; + } + + public function getProductApi(): Api\Shop\ProductApiInterface + { + return $this->productApi; + } + + public function getShippingMethodApi(): Api\Shop\ShippingMethodApiInterface + { + return $this->shippingMethodApi; + } + + public function getTaxonTranslationApi(): Api\Shop\TaxonTranslationApiInterface + { + return $this->taxonTranslationApi; + } + + public function getTaxonApi(): Api\Shop\TaxonApiInterface + { + return $this->taxonApi; + } + + public function getVerifyCustomerAccountApi(): Api\Shop\VerifyCustomerAccountApiInterface + { + return $this->verifyCustomerAccountApi; + } + + public function getResetPasswordRequestApi(): Api\Shop\ResetPasswordRequestApiInterface + { + return $this->resetPasswordRequestApi; + } } diff --git a/src/SyliusShopClientBuilder.php b/src/SyliusShopClientBuilder.php index 553f77e..a4ba36d 100644 --- a/src/SyliusShopClientBuilder.php +++ b/src/SyliusShopClientBuilder.php @@ -13,6 +13,7 @@ use Diglin\Sylius\ApiClient\Routing\UriGenerator; use Diglin\Sylius\ApiClient\Security\Authentication; use Diglin\Sylius\ApiClient\Stream\MultipartStreamBuilderFactory; +use Diglin\Sylius\ApiClient\Stream\PatchResourceListResponseFactory; use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponseFactory; use Http\Client\HttpClient as Client; use Http\Discovery\HttpClientDiscovery; @@ -120,12 +121,14 @@ private function buildAuthenticatedClient(Authentication $authentication): Syliu $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + $patchListResponseFactory = new PatchResourceListResponseFactory(); $resourceClient = new ResourceClient( $authenticatedHttpClient, $uriGenerator, $multipartStreamBuilderFactory, - $upsertListResponseFactory + $upsertListResponseFactory, + $patchListResponseFactory, ); $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator); @@ -137,14 +140,32 @@ private function buildAuthenticatedClient(Authentication $authentication): Syliu $authentication, new Api\Shop\AddressApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\AdjustmentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\CatalogPromotionApi($resourceClient), new Api\Shop\ChannelApi($resourceClient), new Api\Shop\CountryApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\CurrencyApi($resourceClient), + new Api\Shop\CurrencyApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\CustomerApi($resourceClient), new Api\Shop\LocaleApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\OrderItemUnitApi($resourceClient), new Api\Shop\OrderItemApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\OrderApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\PaymentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ShipmentApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\PaymentMethodApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductImageApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductOptionValueApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductOptionApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductReviewApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductTaxonApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductVariantTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductVariantApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ShippingMethodApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\TaxonTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\TaxonApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\VerifyCustomerAccountApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ResetPasswordRequestApi($resourceClient, $pageFactory, $cursorFactory), ) ); diff --git a/src/SyliusShopClientInterface.php b/src/SyliusShopClientInterface.php index 76303ac..8e848bf 100644 --- a/src/SyliusShopClientInterface.php +++ b/src/SyliusShopClientInterface.php @@ -8,6 +8,30 @@ interface SyliusShopClientInterface { public function getAddressApi(): Api\Shop\AddressApiInterface; public function getAdjustmentApi(): Api\Shop\AdjustmentApiInterface; + public function getCatalogPromotionApi(): Api\Shop\CatalogPromotionApiInterface; public function getChannelApi(): Api\Shop\ChannelApiInterface; public function getCountryApi(): Api\Shop\CountryApiInterface; + public function getCurrencyApi(): Api\Shop\CurrencyApiInterface; + public function getCustomerApi(): Api\Shop\CustomerApiInterface; + public function getLocaleApi(): Api\Shop\LocaleApiInterface; + public function getOrderItemUnitApi(): Api\Shop\OrderItemUnitApiInterface; + public function getOrderItemApi(): Api\Shop\OrderItemApiInterface; + public function getOrderApi(): Api\Shop\OrderApiInterface; + public function getPaymentApi(): Api\Shop\PaymentApiInterface; + public function getShipmentApi(): Api\Shop\ShipmentApiInterface; + public function getPaymentMethodApi(): Api\Shop\PaymentMethodApiInterface; + public function getProductImageApi(): Api\Shop\ProductImageApiInterface; + public function getProductOptionValueApi(): Api\Shop\ProductOptionValueApiInterface; + public function getProductOptionApi(): Api\Shop\ProductOptionApiInterface; + public function getProductReviewApi(): Api\Shop\ProductReviewApiInterface; + public function getProductTaxonApi(): Api\Shop\ProductTaxonApiInterface; + public function getProductTranslationApi(): Api\Shop\ProductTranslationApiInterface; + public function getProductVariantTranslationApi(): Api\Shop\ProductVariantTranslationApiInterface; + public function getProductVariantApi(): Api\Shop\ProductVariantApiInterface; + public function getProductApi(): Api\Shop\ProductApiInterface; + public function getShippingMethodApi(): Api\Shop\ShippingMethodApiInterface; + public function getTaxonTranslationApi(): Api\Shop\TaxonTranslationApiInterface; + public function getTaxonApi(): Api\Shop\TaxonApiInterface; + public function getVerifyCustomerAccountApi(): Api\Shop\VerifyCustomerAccountApiInterface; + public function getResetPasswordRequestApi(): Api\Shop\ResetPasswordRequestApiInterface; } From 5cacb3eea2467e6a0a3a8314906ce660eb64334b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Thu, 7 Apr 2022 18:16:40 +0200 Subject: [PATCH 11/13] Added more Shop API endpoints support --- src/Api/Shop/CountryApi.php | 2 +- src/Api/Shop/CurrencyApi.php | 2 +- src/Api/Shop/CustomerApi.php | 2 +- src/Api/Shop/LocaleApi.php | 2 +- src/Api/Shop/OrderApi.php | 3 +- src/Api/Shop/OrderItemApi.php | 2 +- src/Api/Shop/OrderItemUnitApi.php | 2 +- src/Api/Shop/PaymentApi.php | 42 +++++++++++++++++++++ src/Api/Shop/PaymentApiInterface.php | 5 ++- src/Api/Shop/PaymentMethodApi.php | 42 +++++++++++++++++++++ src/Api/Shop/PaymentMethodApiInterface.php | 5 ++- src/Api/Shop/ShipmentApi.php | 42 +++++++++++++++++++++ src/Api/Shop/ShipmentApiInterface.php | 5 ++- src/Api/Shop/ShippingMethodApi.php | 42 +++++++++++++++++++++ src/Api/Shop/ShippingMethodApiInterface.php | 5 ++- 15 files changed, 191 insertions(+), 12 deletions(-) diff --git a/src/Api/Shop/CountryApi.php b/src/Api/Shop/CountryApi.php index d436596..5c53bd6 100644 --- a/src/Api/Shop/CountryApi.php +++ b/src/Api/Shop/CountryApi.php @@ -11,7 +11,7 @@ use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; use Webmozart\Assert\Assert; -class CountryApi implements CountryApiInterface +final class CountryApi implements CountryApiInterface { public function __construct( private ResourceClientInterface $resourceClient, diff --git a/src/Api/Shop/CurrencyApi.php b/src/Api/Shop/CurrencyApi.php index 7af1cdd..e04508d 100644 --- a/src/Api/Shop/CurrencyApi.php +++ b/src/Api/Shop/CurrencyApi.php @@ -11,7 +11,7 @@ use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; use Webmozart\Assert\Assert; -class CurrencyApi implements CurrencyApiInterface +final class CurrencyApi implements CurrencyApiInterface { public function __construct( private ResourceClientInterface $resourceClient, diff --git a/src/Api/Shop/CustomerApi.php b/src/Api/Shop/CustomerApi.php index cf045f4..f1367ed 100644 --- a/src/Api/Shop/CustomerApi.php +++ b/src/Api/Shop/CustomerApi.php @@ -12,7 +12,7 @@ use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; use Webmozart\Assert\Assert; -class CustomerApi implements CustomerApiInterface +final class CustomerApi implements CustomerApiInterface { public function __construct( private ResourceClientInterface $resourceClient, diff --git a/src/Api/Shop/LocaleApi.php b/src/Api/Shop/LocaleApi.php index 6c408f2..9f6e3b5 100644 --- a/src/Api/Shop/LocaleApi.php +++ b/src/Api/Shop/LocaleApi.php @@ -11,7 +11,7 @@ use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; use Webmozart\Assert\Assert; -class LocaleApi implements LocaleApiInterface +final class LocaleApi implements LocaleApiInterface { public function __construct( private ResourceClientInterface $resourceClient, diff --git a/src/Api/Shop/OrderApi.php b/src/Api/Shop/OrderApi.php index 43d6ab6..ab869dd 100644 --- a/src/Api/Shop/OrderApi.php +++ b/src/Api/Shop/OrderApi.php @@ -3,7 +3,6 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; -use Diglin\Sylius\ApiClient\Exception\HttpException; use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; use Diglin\Sylius\ApiClient\Pagination\PageInterface; @@ -12,7 +11,7 @@ use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; use Webmozart\Assert\Assert; -class OrderApi implements OrderApiInterface +final class OrderApi implements OrderApiInterface { public function __construct( private ResourceClientInterface $resourceClient, diff --git a/src/Api/Shop/OrderItemApi.php b/src/Api/Shop/OrderItemApi.php index df202d0..9ee8f71 100644 --- a/src/Api/Shop/OrderItemApi.php +++ b/src/Api/Shop/OrderItemApi.php @@ -11,7 +11,7 @@ use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; use Webmozart\Assert\Assert; -class OrderItemApi implements OrderItemApiInterface +final class OrderItemApi implements OrderItemApiInterface { public function __construct( private ResourceClientInterface $resourceClient, diff --git a/src/Api/Shop/OrderItemUnitApi.php b/src/Api/Shop/OrderItemUnitApi.php index 23aee8f..29c2763 100644 --- a/src/Api/Shop/OrderItemUnitApi.php +++ b/src/Api/Shop/OrderItemUnitApi.php @@ -5,7 +5,7 @@ use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; use Webmozart\Assert\Assert; -class OrderItemUnitApi implements OrderItemUnitApiInterface +final class OrderItemUnitApi implements OrderItemUnitApiInterface { public function __construct( private ResourceClientInterface $resourceClient, diff --git a/src/Api/Shop/PaymentApi.php b/src/Api/Shop/PaymentApi.php index 82d403a..ff416cd 100644 --- a/src/Api/Shop/PaymentApi.php +++ b/src/Api/Shop/PaymentApi.php @@ -2,6 +2,48 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; + final class PaymentApi implements PaymentApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/payments/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/payments', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/PaymentApiInterface.php b/src/Api/Shop/PaymentApiInterface.php index 2d88140..de9c03c 100644 --- a/src/Api/Shop/PaymentApiInterface.php +++ b/src/Api/Shop/PaymentApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface PaymentApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; + +interface PaymentApiInterface extends GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/Shop/PaymentMethodApi.php b/src/Api/Shop/PaymentMethodApi.php index 5368145..57888ba 100644 --- a/src/Api/Shop/PaymentMethodApi.php +++ b/src/Api/Shop/PaymentMethodApi.php @@ -2,6 +2,48 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; + final class PaymentMethodApi implements PaymentMethodApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/payment-methods/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/payment-methods', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/PaymentMethodApiInterface.php b/src/Api/Shop/PaymentMethodApiInterface.php index cdb75d5..6962002 100644 --- a/src/Api/Shop/PaymentMethodApiInterface.php +++ b/src/Api/Shop/PaymentMethodApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface PaymentMethodApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; + +interface PaymentMethodApiInterface extends GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/Shop/ShipmentApi.php b/src/Api/Shop/ShipmentApi.php index c42d002..0b9a59f 100644 --- a/src/Api/Shop/ShipmentApi.php +++ b/src/Api/Shop/ShipmentApi.php @@ -2,6 +2,48 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; + final class ShipmentApi implements ShipmentApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/shipments/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/shipments', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/ShipmentApiInterface.php b/src/Api/Shop/ShipmentApiInterface.php index 4561f4f..fd94a99 100644 --- a/src/Api/Shop/ShipmentApiInterface.php +++ b/src/Api/Shop/ShipmentApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ShipmentApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; + +interface ShipmentApiInterface extends GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/Shop/ShippingMethodApi.php b/src/Api/Shop/ShippingMethodApi.php index 88422db..8622c1f 100644 --- a/src/Api/Shop/ShippingMethodApi.php +++ b/src/Api/Shop/ShippingMethodApi.php @@ -2,6 +2,48 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; + final class ShippingMethodApi implements ShippingMethodApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/shipping-methods/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/shipping-methods', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/ShippingMethodApiInterface.php b/src/Api/Shop/ShippingMethodApiInterface.php index b65e1c2..2400d55 100644 --- a/src/Api/Shop/ShippingMethodApiInterface.php +++ b/src/Api/Shop/ShippingMethodApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ShippingMethodApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; + +interface ShippingMethodApiInterface extends GettableResourceInterface, ListableResourceInterface { } From 6fb8e62fa138e9470a75484884afc09dcd5a741d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Sat, 9 Apr 2022 09:11:02 +0200 Subject: [PATCH 12/13] Added all still missing Shop API endpoints support --- src/Api/Shop/ProductApi.php | 47 ++++++++++++++++++ src/Api/Shop/ProductApiInterface.php | 14 +++++- src/Api/Shop/ProductImageApi.php | 12 +++++ src/Api/Shop/ProductImageApiInterface.php | 4 +- src/Api/Shop/ProductOptionApi.php | 12 +++++ src/Api/Shop/ProductOptionApiInterface.php | 4 +- src/Api/Shop/ProductOptionValueApi.php | 12 +++++ .../Shop/ProductOptionValueApiInterface.php | 4 +- src/Api/Shop/ProductReviewApi.php | 48 +++++++++++++++++++ src/Api/Shop/ProductReviewApiInterface.php | 6 ++- src/Api/Shop/ProductTaxonApi.php | 12 +++++ src/Api/Shop/ProductTaxonApiInterface.php | 4 +- src/Api/Shop/ProductTranslationApi.php | 12 +++++ .../Shop/ProductTranslationApiInterface.php | 4 +- src/Api/Shop/ProductVariantApi.php | 42 ++++++++++++++++ src/Api/Shop/ProductVariantApiInterface.php | 5 +- src/Api/Shop/ProductVariantTranslationApi.php | 12 +++++ .../ProductVariantTranslationApiInterface.php | 4 +- src/Api/Shop/ResetPasswordRequestApi.php | 17 +++++++ .../Shop/ResetPasswordRequestApiInterface.php | 5 +- src/Api/Shop/ShippingMethodTranslationApi.php | 19 ++++++++ .../ShippingMethodTranslationApiInterface.php | 10 ++++ src/Api/Shop/TaxonApi.php | 42 ++++++++++++++++ src/Api/Shop/TaxonApiInterface.php | 5 +- src/Api/Shop/TaxonTranslationApi.php | 12 +++++ src/Api/Shop/TaxonTranslationApiInterface.php | 4 +- src/Api/Shop/VerifyCustomerAccountApi.php | 17 +++++++ .../VerifyCustomerAccountApiInterface.php | 5 +- src/SyliusAdminClientBuilder.php | 10 ++-- src/SyliusShopClient.php | 6 +++ src/SyliusShopClientBuilder.php | 29 +++++------ src/SyliusShopClientInterface.php | 1 + 32 files changed, 408 insertions(+), 32 deletions(-) create mode 100644 src/Api/Shop/ShippingMethodTranslationApi.php create mode 100644 src/Api/Shop/ShippingMethodTranslationApiInterface.php diff --git a/src/Api/Shop/ProductApi.php b/src/Api/Shop/ProductApi.php index 2e50d01..da2b283 100644 --- a/src/Api/Shop/ProductApi.php +++ b/src/Api/Shop/ProductApi.php @@ -2,6 +2,53 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; + final class ProductApi implements ProductApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/products/%s', [$code]); + } + + public function getBySlug(string $slug): array + { + return $this->resourceClient->getResource('api/v2/shop/products-by-slug/%s', [$slug]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null, + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/products', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null, + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/ProductApiInterface.php b/src/Api/Shop/ProductApiInterface.php index 251fb75..d409901 100644 --- a/src/Api/Shop/ProductApiInterface.php +++ b/src/Api/Shop/ProductApiInterface.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; +use Diglin\Sylius\ApiClient\Exception\HttpException; + +interface ProductApiInterface extends GettableResourceInterface, ListableResourceInterface { + /** + * Gets a resource by its slug. + * + * @param string $slug Slug of the resource + * + * @throws HttpException if the request failed + */ + public function getBySlug(string $slug): array; } diff --git a/src/Api/Shop/ProductImageApi.php b/src/Api/Shop/ProductImageApi.php index 99b275b..ea7a81f 100644 --- a/src/Api/Shop/ProductImageApi.php +++ b/src/Api/Shop/ProductImageApi.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class ProductImageApi implements ProductImageApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-images/%s', [$code]); + } } diff --git a/src/Api/Shop/ProductImageApiInterface.php b/src/Api/Shop/ProductImageApiInterface.php index e6faa5a..927fbd0 100644 --- a/src/Api/Shop/ProductImageApiInterface.php +++ b/src/Api/Shop/ProductImageApiInterface.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductImageApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; + +interface ProductImageApiInterface extends GettableResourceInterface { } diff --git a/src/Api/Shop/ProductOptionApi.php b/src/Api/Shop/ProductOptionApi.php index c2dbf94..7b6d680 100644 --- a/src/Api/Shop/ProductOptionApi.php +++ b/src/Api/Shop/ProductOptionApi.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class ProductOptionApi implements ProductOptionApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-options/%s', [$code]); + } } diff --git a/src/Api/Shop/ProductOptionApiInterface.php b/src/Api/Shop/ProductOptionApiInterface.php index 15bed9d..ef7b507 100644 --- a/src/Api/Shop/ProductOptionApiInterface.php +++ b/src/Api/Shop/ProductOptionApiInterface.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductOptionApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; + +interface ProductOptionApiInterface extends GettableResourceInterface { } diff --git a/src/Api/Shop/ProductOptionValueApi.php b/src/Api/Shop/ProductOptionValueApi.php index 6575fda..3b70af8 100644 --- a/src/Api/Shop/ProductOptionValueApi.php +++ b/src/Api/Shop/ProductOptionValueApi.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class ProductOptionValueApi implements ProductOptionValueApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-option-values/%s', [$code]); + } } diff --git a/src/Api/Shop/ProductOptionValueApiInterface.php b/src/Api/Shop/ProductOptionValueApiInterface.php index 276c2d7..2f82729 100644 --- a/src/Api/Shop/ProductOptionValueApiInterface.php +++ b/src/Api/Shop/ProductOptionValueApiInterface.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductOptionValueApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; + +interface ProductOptionValueApiInterface extends GettableResourceInterface { } diff --git a/src/Api/Shop/ProductReviewApi.php b/src/Api/Shop/ProductReviewApi.php index 5e3f483..b70a5dc 100644 --- a/src/Api/Shop/ProductReviewApi.php +++ b/src/Api/Shop/ProductReviewApi.php @@ -2,6 +2,54 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; + final class ProductReviewApi implements ProductReviewApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-reviews/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/product-reviews', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/product-reviews', [], $data); + } } diff --git a/src/Api/Shop/ProductReviewApiInterface.php b/src/Api/Shop/ProductReviewApiInterface.php index e8e2238..fd6372a 100644 --- a/src/Api/Shop/ProductReviewApiInterface.php +++ b/src/Api/Shop/ProductReviewApiInterface.php @@ -2,6 +2,10 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductReviewApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; + +interface ProductReviewApiInterface extends GettableResourceInterface, ListableResourceInterface, CreatableResourceInterface { } diff --git a/src/Api/Shop/ProductTaxonApi.php b/src/Api/Shop/ProductTaxonApi.php index 77a91cf..d9af701 100644 --- a/src/Api/Shop/ProductTaxonApi.php +++ b/src/Api/Shop/ProductTaxonApi.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class ProductTaxonApi implements ProductTaxonApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-taxons/%s', [$code]); + } } diff --git a/src/Api/Shop/ProductTaxonApiInterface.php b/src/Api/Shop/ProductTaxonApiInterface.php index 5f1a1d9..444836b 100644 --- a/src/Api/Shop/ProductTaxonApiInterface.php +++ b/src/Api/Shop/ProductTaxonApiInterface.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductTaxonApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; + +interface ProductTaxonApiInterface extends GettableResourceInterface { } diff --git a/src/Api/Shop/ProductTranslationApi.php b/src/Api/Shop/ProductTranslationApi.php index 293fc93..4412f9d 100644 --- a/src/Api/Shop/ProductTranslationApi.php +++ b/src/Api/Shop/ProductTranslationApi.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class ProductTranslationApi implements ProductTranslationApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-translations/%s', [$code]); + } } diff --git a/src/Api/Shop/ProductTranslationApiInterface.php b/src/Api/Shop/ProductTranslationApiInterface.php index 25a1322..ccfbbdd 100644 --- a/src/Api/Shop/ProductTranslationApiInterface.php +++ b/src/Api/Shop/ProductTranslationApiInterface.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductTranslationApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; + +interface ProductTranslationApiInterface extends GettableResourceInterface { } diff --git a/src/Api/Shop/ProductVariantApi.php b/src/Api/Shop/ProductVariantApi.php index 1829566..1fcf474 100644 --- a/src/Api/Shop/ProductVariantApi.php +++ b/src/Api/Shop/ProductVariantApi.php @@ -2,6 +2,48 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Diglin\Sylius\ApiClient\Filter\FilterBuilderInterface; +use Diglin\Sylius\ApiClient\Pagination\PageFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\PageInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorFactoryInterface; +use Diglin\Sylius\ApiClient\Pagination\ResourceCursorInterface; +use Diglin\Sylius\ApiClient\Sort\SortBuilderInterface; +use Webmozart\Assert\Assert; + final class ProductVariantApi implements ProductVariantApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-variants/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/product-variants', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/ProductVariantApiInterface.php b/src/Api/Shop/ProductVariantApiInterface.php index fce2661..7c88232 100644 --- a/src/Api/Shop/ProductVariantApiInterface.php +++ b/src/Api/Shop/ProductVariantApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductVariantApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; + +interface ProductVariantApiInterface extends GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/Shop/ProductVariantTranslationApi.php b/src/Api/Shop/ProductVariantTranslationApi.php index cedf9b3..bb4e6a3 100644 --- a/src/Api/Shop/ProductVariantTranslationApi.php +++ b/src/Api/Shop/ProductVariantTranslationApi.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class ProductVariantTranslationApi implements ProductVariantTranslationApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/product-variant-translations/%s', [$code]); + } } diff --git a/src/Api/Shop/ProductVariantTranslationApiInterface.php b/src/Api/Shop/ProductVariantTranslationApiInterface.php index f496630..0e5a7f2 100644 --- a/src/Api/Shop/ProductVariantTranslationApiInterface.php +++ b/src/Api/Shop/ProductVariantTranslationApiInterface.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ProductVariantTranslationApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; + +interface ProductVariantTranslationApiInterface extends GettableResourceInterface { } diff --git a/src/Api/Shop/ResetPasswordRequestApi.php b/src/Api/Shop/ResetPasswordRequestApi.php index 79e639a..bbc4b0e 100644 --- a/src/Api/Shop/ResetPasswordRequestApi.php +++ b/src/Api/Shop/ResetPasswordRequestApi.php @@ -2,6 +2,23 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class ResetPasswordRequestApi implements ResetPasswordRequestApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/reset-password-requests', [], $data); + } + + public function verify(string $token): int + { + return $this->resourceClient->patchResource('api/v2/shop/reset-password-requests/%s', [$token]); + } } diff --git a/src/Api/Shop/ResetPasswordRequestApiInterface.php b/src/Api/Shop/ResetPasswordRequestApiInterface.php index d9fd821..a868d5b 100644 --- a/src/Api/Shop/ResetPasswordRequestApiInterface.php +++ b/src/Api/Shop/ResetPasswordRequestApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface ResetPasswordRequestApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; + +interface ResetPasswordRequestApiInterface extends CreatableResourceInterface { + public function verify(string $token): int; } diff --git a/src/Api/Shop/ShippingMethodTranslationApi.php b/src/Api/Shop/ShippingMethodTranslationApi.php new file mode 100644 index 0000000..0add03a --- /dev/null +++ b/src/Api/Shop/ShippingMethodTranslationApi.php @@ -0,0 +1,19 @@ +resourceClient->getResource('api/v2/shop/shipping-method-translations/%s', [$code]); + } +} diff --git a/src/Api/Shop/ShippingMethodTranslationApiInterface.php b/src/Api/Shop/ShippingMethodTranslationApiInterface.php new file mode 100644 index 0000000..ae5e888 --- /dev/null +++ b/src/Api/Shop/ShippingMethodTranslationApiInterface.php @@ -0,0 +1,10 @@ +resourceClient->getResource('api/v2/shop/taxons/%s', [$code]); + } + + public function listPerPage( + int $limit = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null, + ): PageInterface { + $data = $this->resourceClient->getResources('api/v2/shop/taxons', [], $limit, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->pageFactory->createPage($data); + } + + public function all( + int $pageSize = 10, + array $queryParameters = [], + FilterBuilderInterface $filterBuilder = null, + SortBuilderInterface $sortBuilder = null, + ): ResourceCursorInterface { + $data = $this->listPerPage($pageSize, $queryParameters, $filterBuilder, $sortBuilder); + + return $this->cursorFactory->createCursor($pageSize, $data); + } } diff --git a/src/Api/Shop/TaxonApiInterface.php b/src/Api/Shop/TaxonApiInterface.php index 7e54c77..0f736ec 100644 --- a/src/Api/Shop/TaxonApiInterface.php +++ b/src/Api/Shop/TaxonApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface TaxonApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; +use Diglin\Sylius\ApiClient\Api\Operation\ListableResourceInterface; + +interface TaxonApiInterface extends GettableResourceInterface, ListableResourceInterface { } diff --git a/src/Api/Shop/TaxonTranslationApi.php b/src/Api/Shop/TaxonTranslationApi.php index 0f98b74..4048438 100644 --- a/src/Api/Shop/TaxonTranslationApi.php +++ b/src/Api/Shop/TaxonTranslationApi.php @@ -2,6 +2,18 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class TaxonTranslationApi implements TaxonTranslationApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function get($code): array + { + Assert::string($code); + return $this->resourceClient->getResource('api/v2/shop/taxon-translations/%s', [$code]); + } } diff --git a/src/Api/Shop/TaxonTranslationApiInterface.php b/src/Api/Shop/TaxonTranslationApiInterface.php index 3cfecee..07cc3ac 100644 --- a/src/Api/Shop/TaxonTranslationApiInterface.php +++ b/src/Api/Shop/TaxonTranslationApiInterface.php @@ -2,6 +2,8 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface TaxonTranslationApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\GettableResourceInterface; + +interface TaxonTranslationApiInterface extends GettableResourceInterface { } diff --git a/src/Api/Shop/VerifyCustomerAccountApi.php b/src/Api/Shop/VerifyCustomerAccountApi.php index b8a3bb6..3efa515 100644 --- a/src/Api/Shop/VerifyCustomerAccountApi.php +++ b/src/Api/Shop/VerifyCustomerAccountApi.php @@ -2,6 +2,23 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; +use Diglin\Sylius\ApiClient\Client\ResourceClientInterface; +use Webmozart\Assert\Assert; + final class VerifyCustomerAccountApi implements VerifyCustomerAccountApiInterface { + public function __construct( + private ResourceClientInterface $resourceClient, + ) {} + + public function create($code, array $data = []): int + { + Assert::integer($code); + return $this->resourceClient->createResource('api/v2/shop/account-verification-requests', [], $data); + } + + public function verify(string $token): int + { + return $this->resourceClient->patchResource('api/v2/shop/account-verification-requests/%s', [$token]); + } } diff --git a/src/Api/Shop/VerifyCustomerAccountApiInterface.php b/src/Api/Shop/VerifyCustomerAccountApiInterface.php index 7a9d7c8..69df706 100644 --- a/src/Api/Shop/VerifyCustomerAccountApiInterface.php +++ b/src/Api/Shop/VerifyCustomerAccountApiInterface.php @@ -2,6 +2,9 @@ namespace Diglin\Sylius\ApiClient\Api\Shop; -interface VerifyCustomerAccountApiInterface +use Diglin\Sylius\ApiClient\Api\Operation\CreatableResourceInterface; + +interface VerifyCustomerAccountApiInterface extends CreatableResourceInterface { + public function verify(string $token): int; } diff --git a/src/SyliusAdminClientBuilder.php b/src/SyliusAdminClientBuilder.php index 8c09364..d13994e 100644 --- a/src/SyliusAdminClientBuilder.php +++ b/src/SyliusAdminClientBuilder.php @@ -23,11 +23,11 @@ class SyliusAdminClientBuilder implements SyliusAdminClientBuilderInterface { private string $baseUri; - private Client $httpClient; - private RequestFactoryInterface $requestFactory; - private StreamFactoryInterface $streamFactory; - private FileSystemInterface $fileSystem; - /** @var list */ + private ?Client $httpClient; + private ?RequestFactoryInterface $requestFactory; + private ?StreamFactoryInterface $streamFactory; + private ?FileSystemInterface $fileSystem; + /** @var array */ private array $apiRegistry = []; /** @var array */ private array $defaultHeaders = []; diff --git a/src/SyliusShopClient.php b/src/SyliusShopClient.php index 4d29a57..70be297 100644 --- a/src/SyliusShopClient.php +++ b/src/SyliusShopClient.php @@ -33,6 +33,7 @@ public function __construct( private Api\Shop\ProductVariantApiInterface $productVariantApi, private Api\Shop\ProductApiInterface $productApi, private Api\Shop\ShippingMethodApiInterface $shippingMethodApi, + private Api\Shop\ShippingMethodTranslationApiInterface $shippingMethodTranslationApi, private Api\Shop\TaxonTranslationApiInterface $taxonTranslationApi, private Api\Shop\TaxonApiInterface $taxonApi, private Api\Shop\VerifyCustomerAccountApiInterface $verifyCustomerAccountApi, @@ -159,6 +160,11 @@ public function getShippingMethodApi(): Api\Shop\ShippingMethodApiInterface return $this->shippingMethodApi; } + public function getShippingMethodTranslationApi(): Api\Shop\ShippingMethodTranslationApiInterface + { + return $this->shippingMethodTranslationApi; + } + public function getTaxonTranslationApi(): Api\Shop\TaxonTranslationApiInterface { return $this->taxonTranslationApi; diff --git a/src/SyliusShopClientBuilder.php b/src/SyliusShopClientBuilder.php index a4ba36d..bb87689 100644 --- a/src/SyliusShopClientBuilder.php +++ b/src/SyliusShopClientBuilder.php @@ -24,11 +24,11 @@ class SyliusShopClientBuilder implements SyliusShopClientBuilderInterface { private string $baseUri; - private Client $httpClient; - private RequestFactoryInterface $requestFactory; - private StreamFactoryInterface $streamFactory; - private FileSystemInterface $fileSystem; - /** @var list */ + private ?Client $httpClient; + private ?RequestFactoryInterface $requestFactory; + private ?StreamFactoryInterface $streamFactory; + private ?FileSystemInterface $fileSystem; + /** @var array */ private array $apiRegistry = []; /** @var array */ private array $defaultHeaders = []; @@ -152,20 +152,21 @@ private function buildAuthenticatedClient(Authentication $authentication): Syliu new Api\Shop\PaymentApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\ShipmentApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\PaymentMethodApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\ProductImageApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\ProductOptionValueApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\ProductOptionApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductImageApi($resourceClient), + new Api\Shop\ProductOptionValueApi($resourceClient), + new Api\Shop\ProductOptionApi($resourceClient), new Api\Shop\ProductReviewApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\ProductTaxonApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\ProductTranslationApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\ProductVariantTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ProductTaxonApi($resourceClient), + new Api\Shop\ProductTranslationApi($resourceClient), + new Api\Shop\ProductVariantTranslationApi($resourceClient), new Api\Shop\ProductVariantApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\ProductApi($resourceClient, $pageFactory, $cursorFactory), new Api\Shop\ShippingMethodApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\TaxonTranslationApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\ShippingMethodTranslationApi($resourceClient), + new Api\Shop\TaxonTranslationApi($resourceClient), new Api\Shop\TaxonApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\VerifyCustomerAccountApi($resourceClient, $pageFactory, $cursorFactory), - new Api\Shop\ResetPasswordRequestApi($resourceClient, $pageFactory, $cursorFactory), + new Api\Shop\VerifyCustomerAccountApi($resourceClient), + new Api\Shop\ResetPasswordRequestApi($resourceClient), ) ); diff --git a/src/SyliusShopClientInterface.php b/src/SyliusShopClientInterface.php index 8e848bf..6d642fa 100644 --- a/src/SyliusShopClientInterface.php +++ b/src/SyliusShopClientInterface.php @@ -30,6 +30,7 @@ public function getProductVariantTranslationApi(): Api\Shop\ProductVariantTransl public function getProductVariantApi(): Api\Shop\ProductVariantApiInterface; public function getProductApi(): Api\Shop\ProductApiInterface; public function getShippingMethodApi(): Api\Shop\ShippingMethodApiInterface; + public function getShippingMethodTranslationApi(): Api\Shop\ShippingMethodTranslationApiInterface; public function getTaxonTranslationApi(): Api\Shop\TaxonTranslationApiInterface; public function getTaxonApi(): Api\Shop\TaxonApiInterface; public function getVerifyCustomerAccountApi(): Api\Shop\VerifyCustomerAccountApiInterface; From 7b3f36f2c89f2c0057aac6a2818503def79bb58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Mon, 11 Apr 2022 09:14:06 +0200 Subject: [PATCH 13/13] Added all still missing Shop API endpoints support --- src/SyliusLegacyClientFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SyliusLegacyClientFactory.php b/src/SyliusLegacyClientFactory.php index 18e3df1..bb83904 100644 --- a/src/SyliusLegacyClientFactory.php +++ b/src/SyliusLegacyClientFactory.php @@ -23,6 +23,7 @@ use Diglin\Sylius\ApiClient\Routing\UriGenerator; use Diglin\Sylius\ApiClient\Security\LegacyAuthentication; use Diglin\Sylius\ApiClient\Stream\MultipartStreamBuilderFactory; +use Diglin\Sylius\ApiClient\Stream\PatchResourceListResponseFactory; use Diglin\Sylius\ApiClient\Stream\UpsertResourceListResponseFactory; use Http\Client\HttpClient as Client; use Http\Discovery\HttpClientDiscovery; @@ -69,12 +70,14 @@ protected function setUp(LegacyAuthentication $authentication) $authenticatedHttpClient = new AuthenticatedHttpClient($httpClient, $authenticationApi, $authentication); $multipartStreamBuilderFactory = new MultipartStreamBuilderFactory($this->getStreamFactory()); $upsertListResponseFactory = new UpsertResourceListResponseFactory(); + $patchListResponseFactory = new PatchResourceListResponseFactory(); $resourceClient = new ResourceClient( $authenticatedHttpClient, $uriGenerator, $multipartStreamBuilderFactory, - $upsertListResponseFactory + $upsertListResponseFactory, + $patchListResponseFactory, ); $pageFactory = new PageFactory($authenticatedHttpClient, $uriGenerator);