WIP: Implement Admin CRUD
This commit is contained in:
@@ -208,6 +208,41 @@ class ApiClient
|
||||
});
|
||||
}
|
||||
|
||||
public function getPickups(): BaseResponse
|
||||
{
|
||||
return $this->cache->get('bpn_pickups', function (ItemInterface $item) {
|
||||
$item->expiresAfter(3600);
|
||||
|
||||
$data = [
|
||||
'anfrage' => [
|
||||
'user' => $this->config['bpn_username'],
|
||||
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], 'STAMMZUSTIEGE'),
|
||||
'satz' => ['@typ' => 'STAMMZUSTIEGE'],
|
||||
],
|
||||
];
|
||||
|
||||
$body = $this
|
||||
->serializer
|
||||
->serialize($data, 'xml');
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('GET', $this->config['bpn_url'], [
|
||||
'query' => [
|
||||
'operation' => $body,
|
||||
]
|
||||
]);
|
||||
|
||||
$xml = $response->getContent();
|
||||
|
||||
return $this->responseParser->parseXmlString($xml);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
$this->logger->error('API error', ['error' => $e->getMessage()]);
|
||||
throw new ApiClientException($e->getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
private function createKey(string $username, string $password, string $type): string
|
||||
{
|
||||
$date = (new \DateTimeImmutable())->format('Ymd');
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class Pickup
|
||||
{
|
||||
private ?int $id = null;
|
||||
private ?int $busProId = null;
|
||||
private ?string $code = null;
|
||||
private ?string $city;
|
||||
private ?string $street;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(?int $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBusProId(): ?int
|
||||
{
|
||||
return $this->busProId;
|
||||
}
|
||||
|
||||
public function setBusProId(?int $busProId): static
|
||||
{
|
||||
$this->busProId = $busProId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode(): ?string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode(?string $code): static
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCity(): ?string
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
public function setCity(?string $city): static
|
||||
{
|
||||
$this->city = $city;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStreet(): ?string
|
||||
{
|
||||
return $this->street;
|
||||
}
|
||||
|
||||
public function setStreet(?string $street): static
|
||||
{
|
||||
$this->street = $street;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class PickupsResponse extends BaseResponse
|
||||
{
|
||||
private array $pickups = [];
|
||||
|
||||
public function getPickups(): array
|
||||
{
|
||||
return $this->pickups;
|
||||
}
|
||||
|
||||
public function setPickups(array $pickups): static
|
||||
{
|
||||
$this->pickups = $pickups;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ use App\BusProNet\Model\Country;
|
||||
use App\BusProNet\Model\CrmAttribute;
|
||||
use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\CrmAttributeGroup;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\PickupsResponse;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\BusProNet\Model\BaseResponse;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@@ -28,7 +30,7 @@ class ResponseParser
|
||||
public function parseXmlString(string $content): BaseResponse
|
||||
{
|
||||
$xml = simplexml_load_string($content);
|
||||
$type = (string) $xml->xpath('satz/@typ')[0];
|
||||
$type = (string)$xml->xpath('satz/@typ')[0];
|
||||
|
||||
switch ($type) {
|
||||
case 'HINWEIS':
|
||||
@@ -43,6 +45,8 @@ class ResponseParser
|
||||
}
|
||||
case 'STAMMLAENDER':
|
||||
return $this->createCountriesResponse($xml);
|
||||
case 'STAMMZUSTIEGE':
|
||||
return $this->createPickupsResponse($xml);
|
||||
}
|
||||
|
||||
throw new ResponseParserException('Unable to parse XML response');
|
||||
@@ -180,6 +184,28 @@ class ResponseParser
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function createPickupsResponse(\SimpleXMLElement $xml): PickupsResponse
|
||||
{
|
||||
$pickups = [];
|
||||
|
||||
foreach ($xml->xpath('zustiege/zustieg') as $item) {
|
||||
$pickup = new Pickup();
|
||||
$pickup
|
||||
->setId((int)$item->attributes()['id'])
|
||||
->setBusProId((int)$item->attributes()['idbuspro'])
|
||||
->setCode((string)$item->attributes()['code'])
|
||||
->setCity((string)$item->xpath('ort')[0])
|
||||
->setStreet((string)$item->xpath('strasse')[0])
|
||||
;
|
||||
$pickups[] = $pickup;
|
||||
}
|
||||
|
||||
$response = new PickupsResponse();
|
||||
$response->setPickups($pickups);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function resolveOptions(array $options): array
|
||||
{
|
||||
$optionsResolver = new OptionsResolver();
|
||||
|
||||
Reference in New Issue
Block a user