Skip to content

Commit

Permalink
Merge pull request #174 from akeneo/MET-23
Browse files Browse the repository at this point in the history
MET-23: add measurement families to the php client
  • Loading branch information
SamirBoulil authored Mar 12, 2020
2 parents 9c3e334 + da043dc commit a133a0a
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 1 deletion.
3 changes: 3 additions & 0 deletions spec/AkeneoPimClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Akeneo\Pim\ApiClient\Api\FamilyVariantApiInterface;
use Akeneo\Pim\ApiClient\Api\LocaleApiInterface;
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApiInterface;
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
Expand All @@ -36,6 +37,7 @@ function let(
ChannelApiInterface $channelApi,
CurrencyApiInterface $currencyApi,
MeasureFamilyApiInterface $measureFamilyApi,
MeasurementFamilyApiInterface $measurementFamilyApi,
AssociationTypeApiInterface $associationTypeApi,
FamilyVariantApiInterface $familyVariantApi,
ProductModelApiInterface $productModelApi
Expand All @@ -52,6 +54,7 @@ function let(
$channelApi,
$currencyApi,
$measureFamilyApi,
$measurementFamilyApi,
$associationTypeApi,
$familyVariantApi,
$productModelApi
Expand Down
54 changes: 54 additions & 0 deletions spec/Api/MeasurementFamilyApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace spec\Akeneo\Pim\ApiClient\Api;

use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApi;
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface;
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponse;
use PhpSpec\ObjectBehavior;

class MeasurementFamilyApiSpec extends ObjectBehavior
{
function let(ResourceClientInterface $resourceClient) {
$this->beConstructedWith($resourceClient);
}

function it_is_initializable()
{
$this->shouldHaveType(MeasurementFamilyApi::class);
$this->shouldImplement(MeasurementFamilyApiInterface::class);
}

function it_returns_all_measurement_families($resourceClient) {
$resourceClient->getResource(MeasurementFamilyApi::MEASUREMENT_FAMILIES_URI)->willReturn([]);
$this->all()->shouldReturn([]);
}

function it_upserts_a_list_of_measurement_families($resourceClient)
{
$resourceClient->upsertJsonResourceList(
MeasurementFamilyApi::MEASUREMENT_FAMILIES_URI,
[],
[
['code' => 'measurement_family_1'],
['code' => 'measurement_family_2'],
['code' => 'measurement_family_3'],
]
)->willReturn([]);

$this->upsertList(
[
['code' => 'measurement_family_1'],
['code' => 'measurement_family_2'],
['code' => 'measurement_family_3'],
]
)->shouldReturn([]);
}
}
14 changes: 14 additions & 0 deletions src/AkeneoPimClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Akeneo\Pim\ApiClient\Api\FamilyVariantApiInterface;
use Akeneo\Pim\ApiClient\Api\LocaleApiInterface;
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApiInterface;
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
Expand Down Expand Up @@ -72,6 +73,9 @@ class AkeneoPimClient implements AkeneoPimClientInterface
/** @var ProductModelApiInterface */
protected $productModelApi;

/** @var MeasurementFamilyApiInterface */
private $measurementFamilyApi;

public function __construct(
Authentication $authentication,
ProductApiInterface $productApi,
Expand All @@ -85,6 +89,7 @@ public function __construct(
ChannelApiInterface $channelApi,
CurrencyApiInterface $currencyApi,
MeasureFamilyApiInterface $measureFamilyApi,
MeasurementFamilyApiInterface $measurementFamilyApi,
AssociationTypeApiInterface $associationTypeApi,
FamilyVariantApiInterface $familyVariantApi,
ProductModelApiInterface $productModelApi
Expand All @@ -101,6 +106,7 @@ public function __construct(
$this->channelApi = $channelApi;
$this->currencyApi = $currencyApi;
$this->measureFamilyApi = $measureFamilyApi;
$this->measurementFamilyApi = $measurementFamilyApi;
$this->associationTypeApi = $associationTypeApi;
$this->familyVariantApi = $familyVariantApi;
$this->productModelApi = $productModelApi;
Expand Down Expand Up @@ -210,6 +216,14 @@ public function getMeasureFamilyApi(): MeasureFamilyApiInterface
return $this->measureFamilyApi;
}

/**
* {@inheritdoc}
*/
public function getMeasurementFamilyApi(): MeasurementFamilyApiInterface
{
return $this->measurementFamilyApi;
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 3 additions & 1 deletion src/AkeneoPimClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Akeneo\Pim\ApiClient\Api\FamilyVariantApi;
use Akeneo\Pim\ApiClient\Api\LocaleApi;
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApi;
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApi;
use Akeneo\Pim\ApiClient\Api\ProductApi;
use Akeneo\Pim\ApiClient\Api\ProductMediaFileApi;
use Akeneo\Pim\ApiClient\Api\ProductModelApi;
Expand Down Expand Up @@ -152,7 +153,7 @@ public function buildAuthenticatedByToken(string $clientId, string $secret, stri
*/
protected function buildAuthenticatedClient(Authentication $authentication): AkeneoPimClientInterface
{
list($resourceClient, $pageFactory, $cursorFactory, $fileSystem) = $this->setUp($authentication);
[$resourceClient, $pageFactory, $cursorFactory, $fileSystem] = $this->setUp($authentication);

$client = new AkeneoPimClient(
$authentication,
Expand All @@ -167,6 +168,7 @@ protected function buildAuthenticatedClient(Authentication $authentication): Ake
new ChannelApi($resourceClient, $pageFactory, $cursorFactory),
new CurrencyApi($resourceClient, $pageFactory, $cursorFactory),
new MeasureFamilyApi($resourceClient, $pageFactory, $cursorFactory),
new MeasurementFamilyApi($resourceClient),
new AssociationTypeApi($resourceClient, $pageFactory, $cursorFactory),
new FamilyVariantApi($resourceClient, $pageFactory, $cursorFactory),
new ProductModelApi($resourceClient, $pageFactory, $cursorFactory)
Expand Down
3 changes: 3 additions & 0 deletions src/AkeneoPimClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Akeneo\Pim\ApiClient\Api\FamilyVariantApiInterface;
use Akeneo\Pim\ApiClient\Api\LocaleApiInterface;
use Akeneo\Pim\ApiClient\Api\MeasureFamilyApiInterface;
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
Expand Down Expand Up @@ -52,6 +53,8 @@ public function getCurrencyApi(): CurrencyApiInterface;

public function getMeasureFamilyApi(): MeasureFamilyApiInterface;

public function getMeasurementFamilyApi(): MeasurementFamilyApiInterface;

public function getAssociationTypeApi(): AssociationTypeApiInterface;

public function getFamilyVariantApi(): FamilyVariantApiInterface;
Expand Down
44 changes: 44 additions & 0 deletions src/Api/MeasurementFamilyApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Akeneo\Pim\ApiClient\Api;

use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;

/**
* API implementation to manage measurement families.
*
* @author Julien Sanchez <[email protected]>
* @copyright 2020 Akeneo SAS (http://www.akeneo.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class MeasurementFamilyApi implements MeasurementFamilyApiInterface
{
const MEASUREMENT_FAMILIES_URI = 'api/rest/v1/measurement-families';

/** @var ResourceClientInterface */
protected $resourceClient;

/**
* @param ResourceClientInterface $resourceClient
*/
public function __construct(ResourceClientInterface $resourceClient)
{
$this->resourceClient = $resourceClient;
}

/**
* {@inheritdoc}
*/
public function all(): array
{
return $this->resourceClient->getResource(static::MEASUREMENT_FAMILIES_URI);
}

/**
* {@inheritdoc}
*/
public function upsertList($measurementFamilies): array
{
return $this->resourceClient->upsertJsonResourceList(static::MEASUREMENT_FAMILIES_URI, [], $measurementFamilies);
}
}
35 changes: 35 additions & 0 deletions src/Api/MeasurementFamilyApiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Akeneo\Pim\ApiClient\Api;

use Akeneo\Pim\ApiClient\Exception\HttpException;

/**
* API to manage the measurement families.
*
* @author Julien Sanchez <[email protected]>
* @copyright 2020 Akeneo SAS (http://www.akeneo.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
interface MeasurementFamilyApiInterface
{
/**
* Gets a cursor to iterate over all the measurement families
*
* @throws HttpException If the request failed.
*
* @return array
*/
public function all(): array;

/**
* Updates or creates several resources.
*
* @param array $resources array object containing the measurement families to create or update
*
* @throws HttpException
*
* @return array returns an array, each entry corresponding to the response of the upserted measurement families
*/
public function upsertList($resources): array;
}

0 comments on commit a133a0a

Please sign in to comment.