88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\BusProNet\Client;
|
|
|
|
use App\BusProNet\Exception\ApiClientException;
|
|
use App\BusProNet\MessageType;
|
|
use App\BusProNet\Model\BaseData;
|
|
use App\BusProNet\Model\ExtendedServiceAvailabilityResponse;
|
|
use App\BusProNet\Model\Notification;
|
|
use App\BusProNet\Model\ServiceAvailabilityResponse;
|
|
use App\BusProNet\Model\Travel;
|
|
use App\BusProNet\Transport\XmlChannel;
|
|
|
|
/**
|
|
* Travels from the live API. Most reads belong in TravelDataProvider, which arbitrates
|
|
* between this, the XML export and the snapshots.
|
|
*/
|
|
class TravelClient
|
|
{
|
|
public function __construct(
|
|
private readonly XmlChannel $channel,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getTravelData(int $travelId, ?int $hotelId = null): Notification|Travel
|
|
{
|
|
return $this->channel->request(MessageType::ProductData, ['idprodukt' => $travelId], ['hotelId' => $hotelId]);
|
|
}
|
|
|
|
/**
|
|
* Returns the unparsed response, which has the structure of BusPro's XML export and is
|
|
* stored in the export directory as is.
|
|
*
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getTravelDataXml(int $travelId): string
|
|
{
|
|
return $this->channel->requestRaw(MessageType::ProductData, ['idprodukt' => $travelId]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getProducts(): Notification|BaseData
|
|
{
|
|
return $this->channel->request(MessageType::Products);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getMutableData(int $dateId): Notification|BaseData
|
|
{
|
|
return $this->channel->request(MessageType::MutableData, ['idreise' => $dateId]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getAvailabilities(int $dateId): Notification|ServiceAvailabilityResponse
|
|
{
|
|
return $this->channel->request(MessageType::Availability, ['idreise' => $dateId]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getAvailabilitiesExtended(int $dateId): Notification|ExtendedServiceAvailabilityResponse
|
|
{
|
|
return $this->channel->request(MessageType::AvailabilityExtended, ['idreise' => $dateId]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getHotelAvailability(int $dateId, int $hotelId, \DateTimeInterface $dateTo): Notification|BaseData
|
|
{
|
|
return $this->channel->request(MessageType::AvailabilityHotel, [
|
|
'idreise' => $dateId,
|
|
'idpartner' => $hotelId,
|
|
'terminbis' => $dateTo->format('d.m.Y'),
|
|
]);
|
|
}
|
|
}
|