Skip to content

Commit e387f3e

Browse files
Merge pull request #266 from akeneo/dx-104
feat(DX-104) : Adding asynchronous calls in Client
2 parents 77339f1 + dd7987a commit e387f3e

File tree

66 files changed

+1668
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1668
-260
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ phpspec.yml
66
phpunit.xml
77
.php_cs.cache
88
.php-cs-fixer.cache
9+
10+
### PhpStorm ###
11+
.idea

composer.lock

Lines changed: 216 additions & 218 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
11-
stopOnFailure="false">
11+
stopOnFailure="false"
12+
cacheResult ="false">
1213

1314
<testsuite name="Integration">
1415
<directory>tests/</directory>

src/AkeneoPimClientBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use Akeneo\Pim\ApiClient\Cache\LRUCache;
4545
use Akeneo\Pim\ApiClient\Client\AuthenticatedHttpClient;
4646
use Akeneo\Pim\ApiClient\Client\CachedResourceClient;
47+
use Akeneo\Pim\ApiClient\Client\ClientInterface;
4748
use Akeneo\Pim\ApiClient\Client\HttpClient;
4849
use Akeneo\Pim\ApiClient\Client\Options;
4950
use Akeneo\Pim\ApiClient\Client\ResourceClient;
@@ -57,7 +58,6 @@
5758
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponseFactory;
5859
use Http\Discovery\Psr17FactoryDiscovery;
5960
use Http\Discovery\Psr18ClientDiscovery;
60-
use Psr\Http\Client\ClientInterface;
6161
use Psr\Http\Message\RequestFactoryInterface;
6262
use Psr\Http\Message\StreamFactoryInterface;
6363

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

298-
private function getHttpClient(): ClientInterface
298+
private function getHttpClient(): ClientInterface|\Psr\Http\Client\ClientInterface
299299
{
300300
if (null === $this->httpClient) {
301301
$this->httpClient = Psr18ClientDiscovery::find();

src/Api/AppCatalog/AppCatalogApi.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
1111
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
1212
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
13+
use GuzzleHttp\Promise\PromiseInterface;
14+
use Http\Promise\Promise;
1315

1416
/**
1517
* @copyright 2022 Akeneo SAS (https://www.akeneo.com)
@@ -60,4 +62,9 @@ public function delete(string $code): int
6062
{
6163
return $this->resourceClient->deleteResource(static::APP_CATALOG_URI, [$code]);
6264
}
65+
66+
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
67+
{
68+
return $this->resourceClient->upsertAsyncAndReturnPromise(static::APP_CATALOG_URI, [$code], $data);
69+
}
6370
}

src/Api/AppCatalog/AppCatalogApiInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Akeneo\Pim\ApiClient\Api\Operation\DeletableResourceInterface;
88
use Akeneo\Pim\ApiClient\Api\Operation\GettableResourceInterface;
99
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
10+
use GuzzleHttp\Promise\PromiseInterface;
11+
use Http\Promise\Promise;
1012

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

2224
public function upsert(string $code, array $data = []): array;
25+
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise;
2326
}

src/Api/AssetApi.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
1111
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
1212
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
13+
use GuzzleHttp\Promise\PromiseInterface;
14+
use Http\Promise\Promise;
15+
use Psr\Http\Message\StreamInterface;
1316

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

95+
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
96+
{
97+
return $this->resourceClient->upsertAsyncResource(static::ASSET_URI, [$code], $data);
98+
}
99+
92100
/**
93101
* {@inheritdoc}
94102
*/
95103
public function upsertList($resources): \Traversable
96104
{
97105
return $this->resourceClient->upsertStreamResourceList(static::ASSETS_URI, [], $resources);
98106
}
107+
108+
public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise
109+
{
110+
return $this->resourceClient->upsertAsyncStreamResourceList(self::ASSETS_URI, [], $resources);
111+
}
99112
}

src/Api/AssetCategoryApi.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
1111
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
1212
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
13+
use GuzzleHttp\Promise\PromiseInterface;
14+
use Http\Promise\Promise;
15+
use Psr\Http\Message\StreamInterface;
1316

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

80+
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
81+
{
82+
return $this->resourceClient->upsertAsyncResource(static::ASSET_CATEGORY_URI, [$code], $data);
83+
}
84+
7785
/**
7886
* {@inheritdoc}
7987
*/
@@ -95,4 +103,9 @@ public function create(string $code, array $data = []): int
95103

96104
return $this->resourceClient->createResource(static::ASSET_CATEGORIES_URI, [], $data);
97105
}
106+
107+
public function upsertAsyncList(StreamInterface|array $resources): PromiseInterface|Promise
108+
{
109+
return $this->resourceClient->upsertAsyncStreamResourceList(static::ASSET_CATEGORIES_URI, [], $resources);
110+
}
98111
}

src/Api/AssetManager/AssetApi.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
99
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
1010
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
11+
use GuzzleHttp\Promise\PromiseInterface;
12+
use Http\Promise\Promise;
1113

1214
class AssetApi implements AssetApiInterface
1315
{
@@ -70,4 +72,20 @@ public function delete(string $assetFamilyCode, string $assetCode): int
7072
{
7173
return $this->resourceClient->deleteResource(static::ASSET_URI, [$assetFamilyCode, $assetCode]);
7274
}
75+
76+
/**
77+
* {@inheritdoc}
78+
*/
79+
public function upsertAsync(string $assetFamilyCode, string $assetCode, array $data = []): PromiseInterface|Promise
80+
{
81+
return $this->resourceClient->upsertAsyncResource(static::ASSET_URI, [$assetFamilyCode, $assetCode], $data);
82+
}
83+
84+
/**
85+
* {@inheritdoc}
86+
*/
87+
public function upsertAsyncList(string $assetFamilyCode, array $assets): PromiseInterface|Promise
88+
{
89+
return $this->resourceClient->upsertAsyncJsonResourceList(static::ASSETS_URI, [$assetFamilyCode], $assets);
90+
}
7391
}

src/Api/AssetManager/AssetApiInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Akeneo\Pim\ApiClient\Exception\HttpException;
88
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
9+
use GuzzleHttp\Promise\PromiseInterface;
10+
use Http\Promise\Promise;
911

1012
interface AssetApiInterface
1113
{
@@ -56,6 +58,27 @@ public function upsert(string $assetFamilyCode, string $assetCode, array $data =
5658
*/
5759
public function upsertList(string $assetFamilyCode, array $assets): array;
5860

61+
/**
62+
* Creates an asset family if it does not exist yet, otherwise updates partially the asset family.
63+
*
64+
* @throws HttpException
65+
*
66+
* @return Promise
67+
*/
68+
public function upsertAsync(string $assetFamilyCode, string $assetCode, array $data = []): PromiseInterface|Promise;
69+
70+
/**
71+
* Updates or creates several assets.
72+
*
73+
* @param string $assetFamilyCode Code of the asset family
74+
* @param array $assets Array containing the assets to create or update
75+
*
76+
* @throws HttpException
77+
*
78+
* @return Promise
79+
*/
80+
public function upsertAsyncList(string $assetFamilyCode, array $assets): PromiseInterface|Promise;
81+
5982
/**
6083
* Deletes an asset.
6184
*

src/Api/AssetManager/AssetAttributeApi.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Akeneo\Pim\ApiClient\Api\AssetManager;
66

77
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
8+
use GuzzleHttp\Promise\PromiseInterface;
9+
use Http\Promise\Promise;
810

911
class AssetAttributeApi implements AssetAttributeApiInterface
1012
{
@@ -39,4 +41,12 @@ public function upsert(string $assetFamilyCode, string $attributeCode, array $da
3941
{
4042
return $this->resourceClient->upsertResource(static::ASSET_ATTRIBUTE_URI, [$assetFamilyCode, $attributeCode], $data);
4143
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function upsertAsync(string $assetFamilyCode, string $attributeCode, array $data = []): PromiseInterface|Promise
49+
{
50+
return $this->resourceClient->upsertAsyncResource(static::ASSET_ATTRIBUTE_URI, [$assetFamilyCode, $attributeCode], $data);
51+
}
4252
}

src/Api/AssetManager/AssetAttributeApiInterface.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Akeneo\Pim\ApiClient\Api\AssetManager;
66

77
use Akeneo\Pim\ApiClient\Exception\HttpException;
8+
use GuzzleHttp\Promise\PromiseInterface;
9+
use Http\Promise\Promise;
810

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

2527
/**
26-
* Creates a asset attribute if it does not exist yet, otherwise updates partially the attribute.
28+
* Creates an asset attribute if it does not exist yet, otherwise updates partially the attribute.
2729
*
2830
* @throws HttpException
2931
*
3032
* @return int Status code 201 indicating that the asset attribute has been well created.
3133
* Status code 204 indicating that the asset attribute has been well updated.
3234
*/
3335
public function upsert(string $assetFamilyCode, string $attributeCode, array $data = []): int;
36+
37+
/**
38+
* Creates an asset attribute if it does not exist yet, otherwise updates partially the attribute.
39+
*
40+
* @throws HttpException
41+
*
42+
* @return Promise
43+
*/
44+
public function upsertAsync(string $assetFamilyCode, string $attributeCode, array $data = []): PromiseInterface|Promise;
3445
}

src/Api/AssetManager/AssetAttributeOptionApi.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Akeneo\Pim\ApiClient\Api\AssetManager;
66

77
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
8+
use GuzzleHttp\Promise\PromiseInterface;
9+
use Http\Promise\Promise;
810

911
class AssetAttributeOptionApi implements AssetAttributeOptionApiInterface
1012
{
@@ -49,4 +51,20 @@ public function upsert(string $assetFamilyCode, string $attributeCode, string $a
4951
$data
5052
);
5153
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function upsertAsync(
59+
string $assetFamilyCode,
60+
string $attributeCode,
61+
string $attributeOptionCode,
62+
array $data = []
63+
): PromiseInterface|Promise {
64+
return $this->resourceClient->upsertAsyncResource(
65+
static::ASSET_ATTRIBUTE_OPTION_URI,
66+
[$assetFamilyCode, $attributeCode, $attributeOptionCode],
67+
$data
68+
);
69+
}
5270
}

src/Api/AssetManager/AssetAttributeOptionApiInterface.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Akeneo\Pim\ApiClient\Api\AssetManager;
66

77
use Akeneo\Pim\ApiClient\Exception\HttpException;
8+
use GuzzleHttp\Promise\PromiseInterface;
9+
use Http\Promise\Promise;
810

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

2527
/**
26-
* Creates a asset attribute option if it does not exist yet, otherwise updates partially the attribute option.
28+
* Creates an asset attribute option if it does not exist yet, otherwise updates partially the attribute option.
2729
*
2830
* @throws HttpException
2931
*
3032
* @return int Status code 201 indicating that the asset attribute option has been well created.
3133
* Status code 204 indicating that the asset attribute option has been well updated.
3234
*/
3335
public function upsert(string $assetFamilyCode, string $attributeCode, string $attributeOptionCode, array $data = []): int;
36+
37+
/**
38+
* Creates an asset attribute option if it does not exist yet, otherwise updates partially the attribute option.
39+
*
40+
* @throws HttpException
41+
*
42+
* @return Promise
43+
*/
44+
public function upsertAsync(
45+
string $assetFamilyCode,
46+
string $attributeCode,
47+
string $attributeOptionCode,
48+
array $data = []
49+
): PromiseInterface|Promise;
3450
}

src/Api/AssetManager/AssetFamilyApi.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
99
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
1010
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
11+
use GuzzleHttp\Promise\PromiseInterface;
12+
use Http\Promise\Promise;
1113

1214
class AssetFamilyApi implements AssetFamilyApiInterface
1315
{
@@ -54,4 +56,12 @@ public function upsert(string $code, array $data = []): int
5456
{
5557
return $this->resourceClient->upsertResource(static::ASSET_FAMILY_URI, [$code], $data);
5658
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
64+
{
65+
return $this->resourceClient->upsertAsyncResource(static::ASSET_FAMILY_URI, [$code], $data);
66+
}
5767
}

src/Api/AssetManager/AssetFamilyApiInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Akeneo\Pim\ApiClient\Exception\HttpException;
88
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
9+
use GuzzleHttp\Promise\PromiseInterface;
10+
use Http\Promise\Promise;
911

1012
interface AssetFamilyApiInterface
1113
{
@@ -32,4 +34,13 @@ public function all(array $queryParameters = []): ResourceCursorInterface;
3234
* Status code 204 indicating that the asset family has been well updated.
3335
*/
3436
public function upsert(string $assetFamilyCode, array $data = []): int;
37+
38+
/**
39+
* Creates an asset family if it does not exist yet, otherwise updates partially the asset family.
40+
*
41+
* @throws HttpException
42+
*
43+
* @return Promise
44+
*/
45+
public function upsertAsync(string $assetFamilyCode, array $data = []): PromiseInterface|Promise;
3546
}

src/Api/AssetTagApi.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
1010
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
1111
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
12+
use GuzzleHttp\Promise\PromiseInterface;
13+
use Http\Promise\Promise;
1214

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

7274
return $this->pageFactory->createPage($data);
7375
}
76+
77+
public function upsertAsync(string $code, array $data = []): PromiseInterface|Promise
78+
{
79+
return $this->resourceClient->upsertAsyncResource(static::ASSET_TAG_URI, [$code], $data);
80+
}
7481
}

0 commit comments

Comments
 (0)