wip: integrate with typo3 to fetch product and hotel data
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class CmsDataService
|
||||
{
|
||||
public const MODE_PRODUCT = 'product';
|
||||
public const MODE_HOTEL = 'hotel';
|
||||
|
||||
public function __construct(private readonly HttpClientInterface $httpClient)
|
||||
{
|
||||
}
|
||||
|
||||
public function getProductDetails(string $code): array
|
||||
{
|
||||
return $this->makeApiCall(static::MODE_PRODUCT, $code);
|
||||
}
|
||||
|
||||
public function getHotelDetails(string $code): array
|
||||
{
|
||||
return $this->makeApiCall(static::MODE_HOTEL, $code);
|
||||
}
|
||||
|
||||
public function makeApiCall(string $mode, string $code): array
|
||||
{
|
||||
if (false === in_array($mode, [self::MODE_PRODUCT, self::MODE_HOTEL])) {
|
||||
throw new \InvalidArgumentException('Invalid mode provided');
|
||||
}
|
||||
|
||||
try {
|
||||
$request = $this->httpClient->request('GET', '/', [
|
||||
'query' => [
|
||||
'type' => 1720,
|
||||
'tx_epproducts_api[code]' => $code,
|
||||
'tx_epproducts_api[action]' => $mode,
|
||||
'tx_epproducts_api[controller]' => 'Api',
|
||||
]
|
||||
]);
|
||||
} catch (ExceptionInterface $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $request->toArray();
|
||||
} catch (ExceptionInterface $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user