diff options
Diffstat (limited to 'lib/Travelynx/Controller/Api.pm')
| -rwxr-xr-x | lib/Travelynx/Controller/Api.pm | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm index f31195a..fa40e76 100755 --- a/lib/Travelynx/Controller/Api.pm +++ b/lib/Travelynx/Controller/Api.pm @@ -21,6 +21,9 @@ sub sanitize { if ( not defined $value ) { return undef; } + if ( not defined $type ) { + return $value ? ( '' . $value ) : undef; + } if ( $type eq '' ) { return '' . $value; } @@ -184,8 +187,16 @@ sub travel_v1 { my $from_station = sanitize( q{}, $payload->{fromStation} ); my $to_station = sanitize( q{}, $payload->{toStation} ); my $train_id; + my $dbris = sanitize( undef, $payload->{dbris} ); + my $efa = sanitize( undef, $payload->{efa} ); my $hafas = sanitize( undef, $payload->{hafas} ); - $hafas //= exists $payload->{train}{journeyID} ? 'DB' : undef; + my $motis = sanitize( undef, $payload->{motis} ); + + if ( not( $efa or $hafas or $motis ) + and exists $payload->{train}{journeyID} ) + { + $dbris //= 'bahn.de'; + } if ( not( @@ -208,7 +219,7 @@ sub travel_v1 { return; } - if ( not $hafas + if ( not( $dbris or $efa or $hafas or $motis ) and not $self->stations->search( $from_station, backend_id => 1 ) ) { $self->render( @@ -224,7 +235,7 @@ sub travel_v1 { } if ( $to_station - and not $hafas + and not( $dbris or $efa or $hafas or $motis ) and not $self->stations->search( $to_station, backend_id => 1 ) ) { $self->render( @@ -287,7 +298,10 @@ sub travel_v1 { station => $from_station, train_id => $train_id, uid => $uid, + dbris => $dbris, + efa => $efa, hafas => $hafas, + motis => $motis, ); } )->then( |
