From 661f3d079c7643acac16ffa372c20d80ee42244b Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 20 Jul 2019 14:30:31 +0200 Subject: Add support for MM and TfL URA backends Closes #2 --- index.pl | 37 +++++++++++++++++++++++++++++++------ templates/main.html.ep | 9 ++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/index.pl b/index.pl index 4a8af70..504803a 100644 --- a/index.pl +++ b/index.pl @@ -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-Objekte, siehe die Dokumentation zu ::Result % } -% elsif (param('backend') and param('backend') eq 'aseag') { +% elsif (param('backend') and param('backend') =~ m{ ^ura }x) { Serialisierte Travel::Status::DE::URA-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]
-- cgit v1.2.3