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
*

0 commit comments

Comments
 (0)