wip: api client for bpn-connect
This commit is contained in:
1 parent
a8c0801c32
commit
b3210a7a27
12 files changed
+262
-5
No files matched your search
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BpnConnect;
|
||||
|
||||
use App\BpnConnect\Model\ContingentCalendarEntry;
|
||||
use App\BpnConnect\Model\ContingentCalendarMeta;
|
||||
use App\BpnConnect\Model\ContingentCalendarResponse;
|
||||
use App\BpnConnect\Model\ContingentMode;
|
||||
use App\BpnConnect\Model\ContingentRangeEntry;
|
||||
use App\BpnConnect\Model\ContingentRangeResponse;
|
||||
use App\BpnConnect\Model\ContingentStatus;
|
||||
|
||||
class ContingentsClient extends AbstractApiClient
|
||||
{
|
||||
private const string CALENDAR_PATH = '/api/v1/contingents/calendar';
|
||||
|
||||
public function getContingentCalendar(
|
||||
string $hotelCode,
|
||||
string $dateFrom,
|
||||
string $dateTo,
|
||||
): ContingentCalendarResponse {
|
||||
$payload = $this->request(self::CALENDAR_PATH, [
|
||||
'hotelCode' => $hotelCode,
|
||||
'dateFrom' => $dateFrom,
|
||||
'dateTo' => $dateTo,
|
||||
'mode' => ContingentMode::Days->value,
|
||||
]);
|
||||
|
||||
$entries = array_map(
|
||||
static fn (array $item) => new ContingentCalendarEntry(
|
||||
date: $item['date'],
|
||||
status: ContingentStatus::from($item['status']),
|
||||
),
|
||||
$payload['data'] ?? [],
|
||||
);
|
||||
|
||||
return new ContingentCalendarResponse($this->buildMeta($payload), $entries);
|
||||
}
|
||||
|
||||
public function getContingentRanges(
|
||||
string $hotelCode,
|
||||
string $dateFrom,
|
||||
string $dateTo,
|
||||
): ContingentRangeResponse {
|
||||
$payload = $this->request(self::CALENDAR_PATH, [
|
||||
'hotelCode' => $hotelCode,
|
||||
'dateFrom' => $dateFrom,
|
||||
'dateTo' => $dateTo,
|
||||
'mode' => ContingentMode::Ranges->value,
|
||||
]);
|
||||
|
||||
$entries = array_map(
|
||||
static fn (array $item) => new ContingentRangeEntry(
|
||||
dateFrom: $item['date_from'],
|
||||
dateTo: $item['date_to'],
|
||||
status: ContingentStatus::from($item['status']),
|
||||
),
|
||||
$payload['data'] ?? [],
|
||||
);
|
||||
|
||||
return new ContingentRangeResponse($this->buildMeta($payload), $entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
private function buildMeta(array $payload): ContingentCalendarMeta
|
||||
{
|
||||
$raw = $payload['meta'] ?? [];
|
||||
|
||||
return new ContingentCalendarMeta(
|
||||
dateFrom: $raw['date_from'] ?? '',
|
||||
dateTo: $raw['date_to'] ?? '',
|
||||
mode: $raw['mode'] ?? '',
|
||||
hotelCode: $raw['hotel_code'] ?? '',
|
||||
hotelId: (int) ($raw['hotel_id'] ?? 0),
|
||||
rowCount: (int) ($raw['row_count'] ?? 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user