API: Support HAFAS checkin (via journeyID)

This commit is contained in:
Birte Kristina Friesel 2023-08-19 12:43:43 +02:00
parent 85022709d7
commit b85e8a1e04
No known key found for this signature in database
GPG key ID: 19E6E524EBB177BA
3 changed files with 30 additions and 7 deletions

View file

@ -527,7 +527,8 @@ sub startup {
my ($journey) = @_; my ($journey) = @_;
my $found; my $found;
for my $stop ( $journey->route ) { for my $stop ( $journey->route ) {
if ( $stop->eva == $station ) { if ( $stop->name eq $station or $stop->eva == $station )
{
$found = $stop; $found = $stop;
last; last;
} }

View file

@ -176,12 +176,14 @@ sub travel_v1 {
my $from_station = sanitize( q{}, $payload->{fromStation} ); my $from_station = sanitize( q{}, $payload->{fromStation} );
my $to_station = sanitize( q{}, $payload->{toStation} ); my $to_station = sanitize( q{}, $payload->{toStation} );
my $train_id; my $train_id;
my $hafas = exists $payload->{train}{journeyID} ? 1 : 0;
if ( if (
not( not(
$from_station $from_station
and ( ( $payload->{train}{type} and $payload->{train}{no} ) and ( ( $payload->{train}{type} and $payload->{train}{no} )
or $payload->{train}{id} ) or $payload->{train}{id}
or $payload->{train}{journeyID} )
) )
) )
{ {
@ -196,7 +198,7 @@ sub travel_v1 {
return; return;
} }
if ( not $self->stations->search($from_station) ) { if ( not $hafas and not $self->stations->search($from_station) ) {
$self->render( $self->render(
json => { json => {
success => \0, success => \0,
@ -208,7 +210,10 @@ sub travel_v1 {
return; return;
} }
if ( $to_station and not $self->stations->search($to_station) ) { if ( $to_station
and not $hafas
and not $self->stations->search($to_station) )
{
$self->render( $self->render(
json => { json => {
success => \0, success => \0,
@ -222,7 +227,11 @@ sub travel_v1 {
my $train_p; my $train_p;
if ( exists $payload->{train}{id} ) { if ( exists $payload->{train}{journeyID} ) {
$train_p = Mojo::Promise->resolve(
sanitize( q{}, $payload->{train}{journeyID} ) );
}
elsif ( exists $payload->{train}{id} ) {
$train_p $train_p
= Mojo::Promise->resolve( sanitize( 0, $payload->{train}{id} ) ); = Mojo::Promise->resolve( sanitize( 0, $payload->{train}{id} ) );
} }

View file

@ -102,7 +102,7 @@
<p style="font-family: Monospace;"> <p style="font-family: Monospace;">
curl -X POST -H "Content-Type: application/json" -d '{"token":"<%= $uid %>-<%= $token->{travel} // 'TOKEN' %>"}' <%= $api_root %>/travel curl -X POST -H "Content-Type: application/json" -d '{"token":"<%= $uid %>-<%= $token->{travel} // 'TOKEN' %>"}' <%= $api_root %>/travel
</p> </p>
<p>Payload zum Einchecken, optional mit Zielwahl:</p> <p>Payload zum Einchecken per IRIS-Backend (Schienenverkehr DE/DB), optional mit Zielwahl:</p>
<p style="font-family: Monospace;"> <p style="font-family: Monospace;">
{<br/> {<br/>
"token" : "<%= $uid %>-<%= $token->{travel} // 'TOKEN' %>",<br/> "token" : "<%= $uid %>-<%= $token->{travel} // 'TOKEN' %>",<br/>
@ -116,6 +116,19 @@
"comment" : "Beliebiger Text" (optional, überschreibt vorherigen Kommentar)<br/> "comment" : "Beliebiger Text" (optional, überschreibt vorherigen Kommentar)<br/>
} }
</p> </p>
<p>Payload zum Einchecken per HAFAS-Backend (Nahverkehr und außerhalb DE/DB), optional mit Zielwahl. fromStation und toStation müssen mit den Unterwegshalten übereinstimmen, z.B. "Hauptbahnhof (U Gleis 2+4), Essen (Ruhr)" statt "Essen Hbf".</p>
<p style="font-family: Monospace;">
{<br/>
"token" : "<%= $uid %>-<%= $token->{travel} // 'TOKEN' %>",<br/>
"action" : "checkin",<br/>
"train" : {<br/>
"journeyID" : "1|1426396|4|80|19082023",<br/>
}<br/>
"fromStation" : 651806, (Name oder EVA-Nummer)<br/>
"toStation" : 654645, (optional, Name oder EVA-Nummer)<br/>
"comment" : "Beliebiger Text" (optional, überschreibt vorherigen Kommentar)<br/>
}
</p>
<p>Payload zur Wahl eines neuen Ziels, wenn bereits eingecheckt:</p> <p>Payload zur Wahl eines neuen Ziels, wenn bereits eingecheckt:</p>
<p style="font-family: Monospace;"> <p style="font-family: Monospace;">
{<br/> {<br/>