diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-07-20 14:30:31 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-07-20 14:30:31 +0200 |
commit | 661f3d079c7643acac16ffa372c20d80ee42244b (patch) | |
tree | ae03da37d5aa9e15b71276a48114fc474e31379a | |
parent | 07d01219fc91e82f5ab87da6ef6926f260cef8a4 (diff) |
Add support for MM and TfL URA backends1.4.0
Closes #2
-rw-r--r-- | index.pl | 37 | ||||
-rw-r--r-- | templates/main.html.ep | 9 |
2 files changed, 37 insertions, 9 deletions
@@ -11,7 +11,7 @@ use List::MoreUtils qw(); use App::VRR::Fakedisplay; use Travel::Status::DE::HAFAS; -use Travel::Status::DE::ASEAG; +use Travel::Status::DE::URA; use Travel::Status::DE::EFA; no warnings 'uninitialized'; @@ -34,6 +34,9 @@ my @efa_services my @hafas_services = map { $_->{shortname} } Travel::Status::DE::HAFAS::get_services(); +my @ura_services + = map { $_->{shortname} } Travel::Status::DE::URA::get_services(); + sub log_api_access { my $counter = 1; if ( -r $ENV{VRRFAKEDISPLAY_STATS} ) { @@ -55,6 +58,9 @@ sub get_results { if ( $backend and $backend eq 'db' ) { $backend = 'hafas.DB'; } + if ( $backend and $backend eq 'aseag' ) { + $backend = 'ura.ASEAG'; + } if ( $backend =~ s{ [.] (.+) $ }{}x ) { $sub_backend = $1; @@ -71,6 +77,12 @@ sub get_results { errstr => "hafas sub-backend '$sub_backend' not supported" }; } + if ( $backend eq 'ura' and not $sub_backend ~~ \@ura_services ) { + return { + results => [], + errstr => "ura sub-backend '$sub_backend' not supported" + }; + } } if ( $backend eq 'hafas' ) { @@ -103,11 +115,18 @@ sub get_results { service => $sub_backend, ); } - elsif ( $backend eq 'aseag' ) { - $status = Travel::Status::DE::ASEAG->new( - stop => ( $city ? "${city} ${stop}" : $stop ), - calculate_routes => 1, - ); + elsif ( $backend eq 'ura' ) { + my $service + = first { lc( $_->{shortname} ) eq lc($sub_backend) } + Travel::Status::DE::URA::get_services(); + if ($service) { + $status = Travel::Status::DE::URA->new( + ura_base => $service->{ura_base}, + ura_version => $service->{ura_version}, + stop => ( $city ? "${city} ${stop}" : $stop ), + calculate_routes => 1, + ); + } } else { my $efa_url = 'http://efa.vrr.de/vrr/XSLT_DM_REQUEST'; @@ -587,6 +606,12 @@ helper 'hafas_service_list' => sub { return @hafas_services; }; +helper 'ura_service_list' => sub { + my $self = shift; + + return @ura_services; +}; + helper 'handle_no_results' => sub { }; diff --git a/templates/main.html.ep b/templates/main.html.ep index 4d843d1..1c539fb 100644 --- a/templates/main.html.ep +++ b/templates/main.html.ep @@ -55,7 +55,7 @@ Serialisierte Travel::Status::DE::HAFAS</a>-Objekte, siehe die Dokumentation zu <a href="http://man.finalrewind.org/3/Travel-Status-DE-HAFAS-Result/">::Result</a> % } -% elsif (param('backend') and param('backend') eq 'aseag') { +% elsif (param('backend') and param('backend') =~ m{ ^ura }x) { Serialisierte <a href="http://finalrewind.org/projects/Travel-Status-DE-URA/"> Travel::Status::DE::URA</a>-Objekte, siehe die Dokumentation zu @@ -150,8 +150,11 @@ Alle Angaben ohne Gewähr. % map { [$_->[0], $_] } @efa_backends; % my @hafas_backends = map { ["$_ (HAFAS)" => "hafas.$_"] } hafas_service_list(); % @hafas_backends = map { $_->[1] } sort { $a->[0] cmp $b->[0] } - % map { [$_->[0], $_] } @hafas_backends; - %= select_field backend => [['EFA / VRR' => 'vrr'], ['DB (HAFAS)' => 'db'], ['ASEAG (URA)' => 'aseag'], @efa_backends, @hafas_backends] + % map { [$_->[0], $_] } @hafas_backends; + % my @ura_backends = map { ["$_ (URA)" => "ura.$_"] } ura_service_list(); + % @ura_backends = map { $_->[1] } sort { $a->[0] cmp $b->[0] } + % map { [$_->[0], $_] } @ura_backends; + %= select_field backend => [['EFA / VRR' => 'vrr'], @efa_backends, @hafas_backends, @ura_backends] </div> </div> <div class="field"> |