feat: cli command to download travel xml data from buspro api

This commit is contained in:
Björn Fromme
2026-03-16 12:02:28 +01:00
parent f45718ea06
commit c90b93556a
2 changed files with 181 additions and 1 deletions
+71 -1
View File
@@ -401,6 +401,30 @@ class ApiClient
return $this->sendRequest(static::TYPE_PRODUCT_DATA, $data, ['hotelId' => $hotelId]);
}
/**
* Fetches raw XML travel data from the BusProNet API.
*
* Returns the unprocessed XML response for direct storage in the XML export directory.
* The response format matches the XML export structure from BusPro.
*
* @param int $travelId The travel product ID to fetch
*
* @return string The raw XML response
*
* @throws ApiClientException If the API request fails
*/
public function getTravelDataXml(int $travelId): string
{
$data = [
'user' => $this->config['bpn_username'],
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_PRODUCT_DATA),
'satz' => ['@typ' => static::TYPE_PRODUCT_DATA],
'idprodukt' => $travelId,
];
return $this->sendRequestRaw($data);
}
/**
* @throws ApiClientException
*/
@@ -582,6 +606,14 @@ class ApiClient
return $this->executeWithRetry(fn () => $this->doSendRequest($type, $data, $additionalArgs, $debug), $type);
}
/**
* @throws ApiClientException
*/
private function sendRequestRaw(array $data): string
{
return $this->executeWithRetry(fn () => $this->doSendRequestRaw($data));
}
/**
* Executes an operation with automatic retry on immediate connection close.
*
@@ -680,6 +712,44 @@ class ApiClient
throw new ApiClientException('Unexpected response received from API');
}
/**
* @throws ApiClientException
* @throws ImmediateConnectionCloseException
*/
private function doSendRequestRaw(array $data): string
{
$requestId = $this->getRequestId();
$body = $this->serializer->serialize($data, 'xml', [
XmlEncoder::ROOT_NODE_NAME => 'anfrage',
XmlEncoder::ENCODING => 'UTF-8',
]);
if (true === $this->config['debug']) {
$this->dumpXmlToFile('request', $requestId, $body);
}
$socket = $this->connect();
$this->logger->info('Sending raw request to BPN API', [
'requestId' => $requestId,
'type' => $data['satz']['@typ'],
'port' => $this->selectedPort,
]);
$this->send($socket, $body);
$response = $this->receive($socket);
$this->disconnect($socket);
$xml = substr($response, 10);
if (true === $this->config['debug']) {
$this->dumpXmlToFile('response', $requestId, $xml);
}
return $xml;
}
private function dumpXmlToFile(string $type, string $requestId, string $body): void
{
try {
@@ -693,7 +763,7 @@ class ApiClient
$baseId = $this->requestStack->getMainRequest()?->attributes->get('request_id')
?? date(DATE_ATOM);
return $baseId . '_' . ++$this->requestCounter;
return $baseId.'_'.++$this->requestCounter;
}
private function createKey(string $username, string $password, string $type): string