Skip to content

Commit a133a0a

Browse files
authored
Merge pull request #174 from akeneo/MET-23
MET-23: add measurement families to the php client
2 parents 9c3e334 + da043dc commit a133a0a

File tree

7 files changed

+156
-1
lines changed

7 files changed

+156
-1
lines changed

spec/AkeneoPimClientSpec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Akeneo\Pim\ApiClient\Api\FamilyVariantApiInterface;
1616
use Akeneo\Pim\ApiClient\Api\LocaleApiInterface;
1717
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApiInterface;
18+
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
1819
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface;
1920
use Akeneo\Pim\ApiClient\Api\ProductApiInterface;
2021
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
@@ -36,6 +37,7 @@ function let(
3637
ChannelApiInterface $channelApi,
3738
CurrencyApiInterface $currencyApi,
3839
MeasureFamilyApiInterface $measureFamilyApi,
40+
MeasurementFamilyApiInterface $measurementFamilyApi,
3941
AssociationTypeApiInterface $associationTypeApi,
4042
FamilyVariantApiInterface $familyVariantApi,
4143
ProductModelApiInterface $productModelApi
@@ -52,6 +54,7 @@ function let(
5254
$channelApi,
5355
$currencyApi,
5456
$measureFamilyApi,
57+
$measurementFamilyApi,
5558
$associationTypeApi,
5659
$familyVariantApi,
5760
$productModelApi
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace spec\Akeneo\Pim\ApiClient\Api;
4+
5+
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApi;
6+
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
7+
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
8+
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface;
9+
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
10+
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
11+
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
12+
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
13+
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
14+
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponse;
15+
use PhpSpec\ObjectBehavior;
16+
17+
class MeasurementFamilyApiSpec extends ObjectBehavior
18+
{
19+
function let(ResourceClientInterface $resourceClient) {
20+
$this->beConstructedWith($resourceClient);
21+
}
22+
23+
function it_is_initializable()
24+
{
25+
$this->shouldHaveType(MeasurementFamilyApi::class);
26+
$this->shouldImplement(MeasurementFamilyApiInterface::class);
27+
}
28+
29+
function it_returns_all_measurement_families($resourceClient) {
30+
$resourceClient->getResource(MeasurementFamilyApi::MEASUREMENT_FAMILIES_URI)->willReturn([]);
31+
$this->all()->shouldReturn([]);
32+
}
33+
34+
function it_upserts_a_list_of_measurement_families($resourceClient)
35+
{
36+
$resourceClient->upsertJsonResourceList(
37+
MeasurementFamilyApi::MEASUREMENT_FAMILIES_URI,
38+
[],
39+
[
40+
['code' => 'measurement_family_1'],
41+
['code' => 'measurement_family_2'],
42+
['code' => 'measurement_family_3'],
43+
]
44+
)->willReturn([]);
45+
46+
$this->upsertList(
47+
[
48+
['code' => 'measurement_family_1'],
49+
['code' => 'measurement_family_2'],
50+
['code' => 'measurement_family_3'],
51+
]
52+
)->shouldReturn([]);
53+
}
54+
}

src/AkeneoPimClient.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Akeneo\Pim\ApiClient\Api\FamilyVariantApiInterface;
1414
use Akeneo\Pim\ApiClient\Api\LocaleApiInterface;
1515
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApiInterface;
16+
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
1617
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface;
1718
use Akeneo\Pim\ApiClient\Api\ProductApiInterface;
1819
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
@@ -72,6 +73,9 @@ class AkeneoPimClient implements AkeneoPimClientInterface
7273
/** @var ProductModelApiInterface */
7374
protected $productModelApi;
7475

76+
/** @var MeasurementFamilyApiInterface */
77+
private $measurementFamilyApi;
78+
7579
public function __construct(
7680
Authentication $authentication,
7781
ProductApiInterface $productApi,
@@ -85,6 +89,7 @@ public function __construct(
8589
ChannelApiInterface $channelApi,
8690
CurrencyApiInterface $currencyApi,
8791
MeasureFamilyApiInterface $measureFamilyApi,
92+
MeasurementFamilyApiInterface $measurementFamilyApi,
8893
AssociationTypeApiInterface $associationTypeApi,
8994
FamilyVariantApiInterface $familyVariantApi,
9095
ProductModelApiInterface $productModelApi
@@ -101,6 +106,7 @@ public function __construct(
101106
$this->channelApi = $channelApi;
102107
$this->currencyApi = $currencyApi;
103108
$this->measureFamilyApi = $measureFamilyApi;
109+
$this->measurementFamilyApi = $measurementFamilyApi;
104110
$this->associationTypeApi = $associationTypeApi;
105111
$this->familyVariantApi = $familyVariantApi;
106112
$this->productModelApi = $productModelApi;
@@ -210,6 +216,14 @@ public function getMeasureFamilyApi(): MeasureFamilyApiInterface
210216
return $this->measureFamilyApi;
211217
}
212218

219+
/**
220+
* {@inheritdoc}
221+
*/
222+
public function getMeasurementFamilyApi(): MeasurementFamilyApiInterface
223+
{
224+
return $this->measurementFamilyApi;
225+
}
226+
213227
/**
214228
* {@inheritdoc}
215229
*/

src/AkeneoPimClientBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Akeneo\Pim\ApiClient\Api\FamilyVariantApi;
1515
use Akeneo\Pim\ApiClient\Api\LocaleApi;
1616
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApi;
17+
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApi;
1718
use Akeneo\Pim\ApiClient\Api\ProductApi;
1819
use Akeneo\Pim\ApiClient\Api\ProductMediaFileApi;
1920
use Akeneo\Pim\ApiClient\Api\ProductModelApi;
@@ -152,7 +153,7 @@ public function buildAuthenticatedByToken(string $clientId, string $secret, stri
152153
*/
153154
protected function buildAuthenticatedClient(Authentication $authentication): AkeneoPimClientInterface
154155
{
155-
list($resourceClient, $pageFactory, $cursorFactory, $fileSystem) = $this->setUp($authentication);
156+
[$resourceClient, $pageFactory, $cursorFactory, $fileSystem] = $this->setUp($authentication);
156157

157158
$client = new AkeneoPimClient(
158159
$authentication,
@@ -167,6 +168,7 @@ protected function buildAuthenticatedClient(Authentication $authentication): Ake
167168
new ChannelApi($resourceClient, $pageFactory, $cursorFactory),
168169
new CurrencyApi($resourceClient, $pageFactory, $cursorFactory),
169170
new MeasureFamilyApi($resourceClient, $pageFactory, $cursorFactory),
171+
new MeasurementFamilyApi($resourceClient),
170172
new AssociationTypeApi($resourceClient, $pageFactory, $cursorFactory),
171173
new FamilyVariantApi($resourceClient, $pageFactory, $cursorFactory),
172174
new ProductModelApi($resourceClient, $pageFactory, $cursorFactory)

src/AkeneoPimClientInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Akeneo\Pim\ApiClient\Api\FamilyVariantApiInterface;
1414
use Akeneo\Pim\ApiClient\Api\LocaleApiInterface;
1515
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApiInterface;
16+
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
1617
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface;
1718
use Akeneo\Pim\ApiClient\Api\ProductApiInterface;
1819
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
@@ -52,6 +53,8 @@ public function getCurrencyApi(): CurrencyApiInterface;
5253

5354
public function getMeasureFamilyApi(): MeasureFamilyApiInterface;
5455

56+
public function getMeasurementFamilyApi(): MeasurementFamilyApiInterface;
57+
5558
public function getAssociationTypeApi(): AssociationTypeApiInterface;
5659

5760
public function getFamilyVariantApi(): FamilyVariantApiInterface;

src/Api/MeasurementFamilyApi.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Akeneo\Pim\ApiClient\Api;
4+
5+
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
6+
7+
/**
8+
* API implementation to manage measurement families.
9+
*
10+
* @author Julien Sanchez <[email protected]>
11+
* @copyright 2020 Akeneo SAS (http://www.akeneo.com)
12+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13+
*/
14+
class MeasurementFamilyApi implements MeasurementFamilyApiInterface
15+
{
16+
const MEASUREMENT_FAMILIES_URI = 'api/rest/v1/measurement-families';
17+
18+
/** @var ResourceClientInterface */
19+
protected $resourceClient;
20+
21+
/**
22+
* @param ResourceClientInterface $resourceClient
23+
*/
24+
public function __construct(ResourceClientInterface $resourceClient)
25+
{
26+
$this->resourceClient = $resourceClient;
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function all(): array
33+
{
34+
return $this->resourceClient->getResource(static::MEASUREMENT_FAMILIES_URI);
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function upsertList($measurementFamilies): array
41+
{
42+
return $this->resourceClient->upsertJsonResourceList(static::MEASUREMENT_FAMILIES_URI, [], $measurementFamilies);
43+
}
44+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Akeneo\Pim\ApiClient\Api;
4+
5+
use Akeneo\Pim\ApiClient\Exception\HttpException;
6+
7+
/**
8+
* API to manage the measurement families.
9+
*
10+
* @author Julien Sanchez <[email protected]>
11+
* @copyright 2020 Akeneo SAS (http://www.akeneo.com)
12+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13+
*/
14+
interface MeasurementFamilyApiInterface
15+
{
16+
/**
17+
* Gets a cursor to iterate over all the measurement families
18+
*
19+
* @throws HttpException If the request failed.
20+
*
21+
* @return array
22+
*/
23+
public function all(): array;
24+
25+
/**
26+
* Updates or creates several resources.
27+
*
28+
* @param array $resources array object containing the measurement families to create or update
29+
*
30+
* @throws HttpException
31+
*
32+
* @return array returns an array, each entry corresponding to the response of the upserted measurement families
33+
*/
34+
public function upsertList($resources): array;
35+
}

0 commit comments

Comments
 (0)