Skip to content

Commit

Permalink
Merge pull request #266 from akeneo/dx-104
Browse files Browse the repository at this point in the history
feat(DX-104) : Adding asynchronous calls in Client
  • Loading branch information
gwendalaubert committed Jun 29, 2023
2 parents 77339f1 + dd7987a commit e387f3e
Show file tree
Hide file tree
Showing 66 changed files with 1,668 additions and 260 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ phpspec.yml
phpunit.xml
.php_cs.cache
.php-cs-fixer.cache

### PhpStorm ###
.idea
434 changes: 216 additions & 218 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
cacheResult ="false">

<testsuite name="Integration">
<directory>tests/</directory>
Expand Down
4 changes: 2 additions & 2 deletions src/AkeneoPimClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use Akeneo\Pim\ApiClient\Cache\LRUCache;
use Akeneo\Pim\ApiClient\Client\AuthenticatedHttpClient;
use Akeneo\Pim\ApiClient\Client\CachedResourceClient;
use Akeneo\Pim\ApiClient\Client\ClientInterface;
use Akeneo\Pim\ApiClient\Client\HttpClient;
use Akeneo\Pim\ApiClient\Client\Options;
use Akeneo\Pim\ApiClient\Client\ResourceClient;
Expand All @@ -57,7 +58,6 @@
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

Expand Down Expand Up @@ -295,7 +295,7 @@ protected function setUp(Authentication $authentication): array
return [$resourceClient, $pageFactory, $cursorFactory, $fileSystem];
}

private function getHttpClient(): ClientInterface
private function getHttpClient(): ClientInterface|\Psr\Http\Client\ClientInterface
{
if (null === $this->httpClient) {
$this->httpClient = Psr18ClientDiscovery::find();
Expand Down
7 changes: 7 additions & 0 deletions src/Api/AppCatalog/AppCatalogApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

/**
* @copyright 2022 Akeneo SAS (https://www.akeneo.com)
Expand Down Expand Up @@ -60,4 +62,9 @@ public function delete(string $code): int
{
return $this->resourceClient->deleteResource(static::APP_CATALOG_URI, [$code]);
}

public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncAndReturnPromise(static::APP_CATALOG_URI, [$code], $data);
}
}
3 changes: 3 additions & 0 deletions src/Api/AppCatalog/AppCatalogApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Akeneo\Pim\ApiClient\Api\Operation\DeletableResourceInterface;
use Akeneo\Pim\ApiClient\Api\Operation\GettableResourceInterface;
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

/**
* @copyright 2022 Akeneo SAS (https://www.akeneo.com)
Expand All @@ -20,4 +22,5 @@ interface AppCatalogApiInterface extends
public function create(array $data): array;

public function upsert(string $code, array $data = []): array;
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise;
}
13 changes: 13 additions & 0 deletions src/Api/AssetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;
use Psr\Http\Message\StreamInterface;

/**
* API implementation to manage assets.
Expand Down Expand Up @@ -89,11 +92,21 @@ public function upsert(string $code, array $data = []): int
return $this->resourceClient->upsertResource(static::ASSET_URI, [$code], $data);
}

public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncResource(static::ASSET_URI, [$code], $data);
}

/**
* {@inheritdoc}
*/
public function upsertList($resources): \Traversable
{
return $this->resourceClient->upsertStreamResourceList(static::ASSETS_URI, [], $resources);
}

public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncStreamResourceList(self::ASSETS_URI, [], $resources);
}
}
13 changes: 13 additions & 0 deletions src/Api/AssetCategoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;
use Psr\Http\Message\StreamInterface;

/**
* API implementation to manage asset categories.
Expand Down Expand Up @@ -74,6 +77,11 @@ public function upsert(string $code, array $data = []): int
return $this->resourceClient->upsertResource(static::ASSET_CATEGORY_URI, [$code], $data);
}

public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncResource(static::ASSET_CATEGORY_URI, [$code], $data);
}

/**
* {@inheritdoc}
*/
Expand All @@ -95,4 +103,9 @@ public function create(string $code, array $data = []): int

return $this->resourceClient->createResource(static::ASSET_CATEGORIES_URI, [], $data);
}

public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncStreamResourceList(static::ASSET_CATEGORIES_URI, [], $resources);
}
}
18 changes: 18 additions & 0 deletions src/Api/AssetManager/AssetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

class AssetApi implements AssetApiInterface
{
Expand Down Expand Up @@ -70,4 +72,20 @@ public function delete(string $assetFamilyCode, string $assetCode): int
{
return $this->resourceClient->deleteResource(static::ASSET_URI, [$assetFamilyCode, $assetCode]);
}

/**
* {@inheritdoc}
*/
public function upsertAsync(string $assetFamilyCode, string $assetCode, array $data = []): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncResource(static::ASSET_URI, [$assetFamilyCode, $assetCode], $data);
}

/**
* {@inheritdoc}
*/
public function upsertAsyncList(string $assetFamilyCode, array $assets): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncJsonResourceList(static::ASSETS_URI, [$assetFamilyCode], $assets);
}
}
23 changes: 23 additions & 0 deletions src/Api/AssetManager/AssetApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Akeneo\Pim\ApiClient\Exception\HttpException;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

interface AssetApiInterface
{
Expand Down Expand Up @@ -56,6 +58,27 @@ public function upsert(string $assetFamilyCode, string $assetCode, array $data =
*/
public function upsertList(string $assetFamilyCode, array $assets): array;

/**
* Creates an asset family if it does not exist yet, otherwise updates partially the asset family.
*
* @throws HttpException
*
* @return Promise
*/
public function upsertAsync(string $assetFamilyCode, string $assetCode, array $data = []): PromiseInterface|Promise;

/**
* Updates or creates several assets.
*
* @param string $assetFamilyCode Code of the asset family
* @param array $assets Array containing the assets to create or update
*
* @throws HttpException
*
* @return Promise
*/
public function upsertAsyncList(string $assetFamilyCode, array $assets): PromiseInterface|Promise;

/**
* Deletes an asset.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Api/AssetManager/AssetAttributeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Akeneo\Pim\ApiClient\Api\AssetManager;

use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

class AssetAttributeApi implements AssetAttributeApiInterface
{
Expand Down Expand Up @@ -39,4 +41,12 @@ public function upsert(string $assetFamilyCode, string $attributeCode, array $da
{
return $this->resourceClient->upsertResource(static::ASSET_ATTRIBUTE_URI, [$assetFamilyCode, $attributeCode], $data);
}

/**
* {@inheritdoc}
*/
public function upsertAsync(string $assetFamilyCode, string $attributeCode, array $data = []): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncResource(static::ASSET_ATTRIBUTE_URI, [$assetFamilyCode, $attributeCode], $data);
}
}
13 changes: 12 additions & 1 deletion src/Api/AssetManager/AssetAttributeApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Akeneo\Pim\ApiClient\Api\AssetManager;

use Akeneo\Pim\ApiClient\Exception\HttpException;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

interface AssetAttributeApiInterface
{
Expand All @@ -23,12 +25,21 @@ public function get(string $assetFamilyCode, string $attributeCode): array;
public function all(string $assetFamilyCode, array $queryParameters = []): array;

/**
* Creates a asset attribute if it does not exist yet, otherwise updates partially the attribute.
* Creates an asset attribute if it does not exist yet, otherwise updates partially the attribute.
*
* @throws HttpException
*
* @return int Status code 201 indicating that the asset attribute has been well created.
* Status code 204 indicating that the asset attribute has been well updated.
*/
public function upsert(string $assetFamilyCode, string $attributeCode, array $data = []): int;

/**
* Creates an asset attribute if it does not exist yet, otherwise updates partially the attribute.
*
* @throws HttpException
*
* @return Promise
*/
public function upsertAsync(string $assetFamilyCode, string $attributeCode, array $data = []): PromiseInterface|Promise;
}
18 changes: 18 additions & 0 deletions src/Api/AssetManager/AssetAttributeOptionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Akeneo\Pim\ApiClient\Api\AssetManager;

use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

class AssetAttributeOptionApi implements AssetAttributeOptionApiInterface
{
Expand Down Expand Up @@ -49,4 +51,20 @@ public function upsert(string $assetFamilyCode, string $attributeCode, string $a
$data
);
}

/**
* {@inheritdoc}
*/
public function upsertAsync(
string $assetFamilyCode,
string $attributeCode,
string $attributeOptionCode,
array $data = []
): PromiseInterface|Promise {
return $this->resourceClient->upsertAsyncResource(
static::ASSET_ATTRIBUTE_OPTION_URI,
[$assetFamilyCode, $attributeCode, $attributeOptionCode],
$data
);
}
}
18 changes: 17 additions & 1 deletion src/Api/AssetManager/AssetAttributeOptionApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Akeneo\Pim\ApiClient\Api\AssetManager;

use Akeneo\Pim\ApiClient\Exception\HttpException;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

interface AssetAttributeOptionApiInterface
{
Expand All @@ -23,12 +25,26 @@ public function get(string $assetFamilyCode, string $attributeCode, string $attr
public function all(string $assetFamilyCode, string $attributeCode): array;

/**
* Creates a asset attribute option if it does not exist yet, otherwise updates partially the attribute option.
* Creates an asset attribute option if it does not exist yet, otherwise updates partially the attribute option.
*
* @throws HttpException
*
* @return int Status code 201 indicating that the asset attribute option has been well created.
* Status code 204 indicating that the asset attribute option has been well updated.
*/
public function upsert(string $assetFamilyCode, string $attributeCode, string $attributeOptionCode, array $data = []): int;

/**
* Creates an asset attribute option if it does not exist yet, otherwise updates partially the attribute option.
*
* @throws HttpException
*
* @return Promise
*/
public function upsertAsync(
string $assetFamilyCode,
string $attributeCode,
string $attributeOptionCode,
array $data = []
): PromiseInterface|Promise;
}
10 changes: 10 additions & 0 deletions src/Api/AssetManager/AssetFamilyApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

class AssetFamilyApi implements AssetFamilyApiInterface
{
Expand Down Expand Up @@ -54,4 +56,12 @@ public function upsert(string $code, array $data = []): int
{
return $this->resourceClient->upsertResource(static::ASSET_FAMILY_URI, [$code], $data);
}

/**
* {@inheritdoc}
*/
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncResource(static::ASSET_FAMILY_URI, [$code], $data);
}
}
11 changes: 11 additions & 0 deletions src/Api/AssetManager/AssetFamilyApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Akeneo\Pim\ApiClient\Exception\HttpException;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

interface AssetFamilyApiInterface
{
Expand All @@ -32,4 +34,13 @@ public function all(array $queryParameters = []): ResourceCursorInterface;
* Status code 204 indicating that the asset family has been well updated.
*/
public function upsert(string $assetFamilyCode, array $data = []): int;

/**
* Creates an asset family if it does not exist yet, otherwise updates partially the asset family.
*
* @throws HttpException
*
* @return Promise
*/
public function upsertAsync(string $assetFamilyCode, array $data = []): PromiseInterface|Promise;
}
7 changes: 7 additions & 0 deletions src/Api/AssetTagApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Promise\Promise;

/**
* API implementation to manage asset tags.
Expand Down Expand Up @@ -71,4 +73,9 @@ public function listPerPage(int $limit = 100, bool $withCount = false, array $qu

return $this->pageFactory->createPage($data);
}

public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
{
return $this->resourceClient->upsertAsyncResource(static::ASSET_TAG_URI, [$code], $data);
}
}
Loading

0 comments on commit e387f3e

Please sign in to comment.