Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SystemInformationApi for the GET endpoint /api/rest/v1/system-information #279

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions spec/AkeneoPimClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApiInterface;
use Akeneo\Pim\ApiClient\Api\SystemInformationApiInterface;
use Akeneo\Pim\ApiClient\Security\Authentication;
use PhpSpec\ObjectBehavior;

Expand Down Expand Up @@ -86,7 +87,8 @@ function let(
ProductUuidApiInterface $productUuidApi,
ProductDraftUuidApiInterface $productDraftUuidApi,
AppCatalogApiInterface $appCatalogApi,
AppCatalogProductApiInterface $appCatalogProductApi
AppCatalogProductApiInterface $appCatalogProductApi,
SystemInformationApiInterface $systemInformationApi,
) {
$this->beConstructedWith(
$authentication,
Expand Down Expand Up @@ -127,7 +129,8 @@ function let(
$productUuidApi,
$productDraftUuidApi,
$appCatalogApi,
$appCatalogProductApi
$appCatalogProductApi,
$systemInformationApi
);
}

Expand Down
45 changes: 45 additions & 0 deletions spec/Api/SystemInformationApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace spec\Akeneo\Pim\ApiClient\Api;

use Akeneo\Pim\ApiClient\Api\SystemInformationApi;
use Akeneo\Pim\ApiClient\Api\SystemInformationApiInterface;
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use PhpSpec\ObjectBehavior;

class SystemInformationApiSpec extends ObjectBehavior
{
function let(
ResourceClientInterface $resourceClient,
PageFactoryInterface $pageFactory,
ResourceCursorFactoryInterface $cursorFactory
) {
$this->beConstructedWith($resourceClient, $pageFactory, $cursorFactory);
}

function it_is_initializable()
{
$this->shouldHaveType(SystemInformationApi::class);
$this->shouldImplement(SystemInformationApiInterface::class);
}

function it_returns_system_information($resourceClient)
{
$systemInformation = [
'code' => 'foo',
'attributes' => ['sku'],
'sort_order' => 1,
'labels' => [
'en_US' => 'Foo',
],
];

$resourceClient
->getResource(SystemInformationApi::SYSTEM_INFORMATION_URI)
->willReturn($systemInformation);

$this->get()->shouldReturn($systemInformation);
}
}
17 changes: 14 additions & 3 deletions src/AkeneoPimClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApiInterface;
use Akeneo\Pim\ApiClient\Api\SystemInformationApi;
use Akeneo\Pim\ApiClient\Api\SystemInformationApiInterface;
use Akeneo\Pim\ApiClient\Security\Authentication;

/**
Expand Down Expand Up @@ -91,7 +93,8 @@ public function __construct(
private ProductUuidApiInterface $productUuidApi,
private ProductDraftUuidApiInterface $productDraftUuidApi,
private AppCatalogApiInterface $appCatalogApi,
private AppCatalogProductApiInterface $appCatalogProductApi
private AppCatalogProductApiInterface $appCatalogProductApi,
private SystemInformationApiInterface $systemInformationApi
) {
}

Expand Down Expand Up @@ -265,7 +268,7 @@ public function getProductDraftApi(): ProductDraftApiInterface

/**
* @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0.
* @see getAssetManagerApi instead.
* @see getAssetManagerApi instead.
*/
public function getAssetApi(): AssetApiInterface
{
Expand All @@ -274,7 +277,7 @@ public function getAssetApi(): AssetApiInterface

/**
* @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0.
* @see getAssetFamilyApi instead.
* @see getAssetFamilyApi instead.
*/
public function getAssetCategoryApi(): AssetCategoryApiInterface
{
Expand Down Expand Up @@ -416,4 +419,12 @@ public function getAppCatalogProductApi(): AppCatalogProductApiInterface
{
return $this->appCatalogProductApi;
}

/**
* {@inheritDoc}
*/
public function getSystemInformationApi(): SystemInformationApi
{
return $this->systemInformationApi;
}
}
4 changes: 3 additions & 1 deletion src/AkeneoPimClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApi;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApi;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApi;
use Akeneo\Pim\ApiClient\Api\SystemInformationApi;
use Akeneo\Pim\ApiClient\Cache\LRUCache;
use Akeneo\Pim\ApiClient\Client\AuthenticatedHttpClient;
use Akeneo\Pim\ApiClient\Client\CachedResourceClient;
Expand Down Expand Up @@ -249,7 +250,8 @@ protected function buildAuthenticatedClient(Authentication $authentication): Ake
new ProductUuidApi($resourceClient, $pageFactory, $cursorFactory),
new ProductDraftUuidApi($resourceClient, $pageFactory, $cursorFactory),
new AppCatalogApi($resourceClient, $pageFactory, $cursorFactory),
new AppCatalogProductApi($resourceClient, $pageFactory, $cursorFactory)
new AppCatalogProductApi($resourceClient, $pageFactory, $cursorFactory),
new SystemInformationApi($resourceClient)
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/AkeneoPimClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApiInterface;
use Akeneo\Pim\ApiClient\Api\SystemInformationApi;

/**
* Client to use the Akeneo PIM API.
Expand Down Expand Up @@ -94,13 +95,13 @@ public function getProductDraftApi(): ProductDraftApiInterface;

/**
* @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0.
* @see getAssetManagerApi instead.
* @see getAssetManagerApi instead.
*/
public function getAssetApi(): AssetApiInterface;

/**
* @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0.
* @see getAssetFamilyApi instead.
* @see getAssetFamilyApi instead.
*/
public function getAssetCategoryApi(): AssetCategoryApiInterface;

Expand Down Expand Up @@ -146,4 +147,6 @@ public function getProductDraftUuidApi(): ProductDraftUuidApiInterface;
public function getAppCatalogApi(): AppCatalogApiInterface;

public function getAppCatalogProductApi(): AppCatalogProductApiInterface;

public function getSystemInformationApi(): SystemInformationApi;
}
26 changes: 26 additions & 0 deletions src/Api/SystemInformationApi.php
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add tests for this class. Get inspiration with spec/Api/AttributeGroupApiSpec.php

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tomglvng
I added SystemInformationApiSpec and fix the AkeneoPimClientSpec in my last commit.
The result of make tests is successful

Thanks 🙏

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Akeneo\Pim\ApiClient\Api;

use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;

/**
* API implementation to manage system information.
*/
class SystemInformationApi implements SystemInformationApiInterface
{
public const SYSTEM_INFORMATION_URI = 'api/rest/v1/system-information';

public function __construct(
protected ResourceClientInterface $resourceClient,
) {
}

/**
* {@inheritdoc}
*/
public function get(): array
{
return $this->resourceClient->getResource(static::SYSTEM_INFORMATION_URI);
}
}
21 changes: 21 additions & 0 deletions src/Api/SystemInformationApiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Akeneo\Pim\ApiClient\Api;

use Akeneo\Pim\ApiClient\Api\Operation\GettableResourceInterface;
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
use Akeneo\Pim\ApiClient\Exception\HttpException;

/**
* API to manage system information.
*/
interface SystemInformationApiInterface
{
/**
* Gets the system information
*
* @throws HttpException If the request failed.
* @return array
*/
public function get(): array;
}