diff options
Diffstat (limited to 'lib/Travel/Status/DE/EFA.pm')
-rw-r--r-- | lib/Travel/Status/DE/EFA.pm | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm index f6f4151..be08b9a 100644 --- a/lib/Travel/Status/DE/EFA.pm +++ b/lib/Travel/Status/DE/EFA.pm @@ -5,7 +5,7 @@ use warnings; use 5.010; use utf8; -our $VERSION = '3.04'; +our $VERSION = '3.13'; use Carp qw(confess cluck); use DateTime; @@ -45,7 +45,7 @@ sub new_p { $self->check_for_ambiguous(); if ( $self->{errstr} ) { - $promise->reject( $self->{errstr} ); + $promise->reject( $self->{errstr}, $self ); return; } @@ -54,7 +54,7 @@ sub new_p { } )->catch( sub { - my ($err) = @_; + my ( $err, $self ) = @_; $promise->reject($err); return; } @@ -206,6 +206,7 @@ sub new { stop => $opt{stopseq}{stop_id}, tripCode => $opt{stopseq}{key}, date => $opt{stopseq}{date}, + time => $opt{stopseq}{time}, coordOutputFormat => 'WGS84[DD.DDDDD]', outputFormat => 'rapidJson', useRealtime => '1', @@ -412,15 +413,37 @@ sub check_for_ambiguous { for my $m ( @{ $json->{dm}{message} // [] } ) { if ( $m->{name} eq 'error' and $m->{value} eq 'name list' ) { - $self->{errstr} = "ambiguous name parameter"; - $self->{name_candidates} - = [ map { $_->{name} } @{ $json->{dm}{points} // [] } ]; + $self->{errstr} = "ambiguous name parameter"; + $self->{name_candidates} = []; + for my $point ( @{ $json->{dm}{points} // [] } ) { + my $place = $point->{ref}{place}; + push( + @{ $self->{name_candidates} }, + Travel::Status::DE::EFA::Stop->new( + place => $place, + full_name => $point->{name}, + name => $point->{name} =~ s{\Q$place\E,? ?}{}r, + id_num => $point->{ref}{id}, + ) + ); + } return; } if ( $m->{name} eq 'error' and $m->{value} eq 'place list' ) { - $self->{errstr} = "ambiguous name parameter"; - $self->{place_candidates} - = [ map { $_->{name} } @{ $json->{dm}{points} // [] } ]; + $self->{errstr} = "ambiguous name parameter"; + $self->{place_candidates} = []; + for my $point ( @{ $json->{dm}{points} // [] } ) { + my $place = $point->{ref}{place}; + push( + @{ $self->{place_candidates} }, + Travel::Status::DE::EFA::Stop->new( + place => $place, + full_name => $point->{name}, + name => $point->{name} =~ s{\Q$place\E,? ?}{}r, + id_num => $point->{ref}{id}, + ) + ); + } return; } } @@ -441,7 +464,8 @@ sub stop { place => $place, full_name => $point->{name}, name => $point->{name} =~ s{\Q$place\E,? ?}{}r, - id => $point->{stateless}, + id_num => $point->{ref}{id}, + id_code => $point->{ref}{gid}, ); return $self->{stop}; @@ -468,7 +492,8 @@ sub stops { place => $stop->{place}, name => $stop->{name}, full_name => $stop->{nameWithPlace}, - id => $stop->{stopID}, + id_num => $stop->{stopID}, + id_code => $stop->{gid}, ) ); } @@ -522,7 +547,7 @@ sub parse_line { mot => $mode->{product}, operator => $mode->{diva}{operator}, identifier => $mode->{diva}{globalId}, - , + ); } @@ -557,7 +582,7 @@ sub results_coord { full_name => $stop->{properties}{STOP_NAME_WITH_PLACE}, distance_m => $stop->{properties}{distance}, name => $stop->{name}, - id => $stop->{id}, + id_code => $stop->{id}, ) ); } @@ -588,8 +613,8 @@ sub results_stopfinder { place => $stop->{ref}{place}, full_name => $stop->{name}, name => $stop->{object}, - id => $stop->{stateless}, - stop_id => $stop->{ref}{gid}, + id_num => $stop->{ref}{id}, + id_code => $stop->{ref}{gid}, ) ); } @@ -603,6 +628,11 @@ sub results_dm { my ($self) = @_; my $json = $self->{response}; + # Oh EFA, you so silly + if ( $json->{departureList} and ref( $json->{departureList} ) eq 'HASH' ) { + $json->{departureList} = [ $json->{departureList}{departure} ]; + } + my @results; for my $departure ( @{ $json->{departureList} // [] } ) { push( @@ -678,7 +708,7 @@ Travel::Status::DE::EFA - unofficial EFA departure monitor =head1 VERSION -version 3.04 +version 3.13 =head1 DESCRIPTION @@ -769,8 +799,14 @@ Default: 10 seconds. Set to 0 or a negative value to disable it. =item my $status_p = Travel::Status::DE::EFA->new_p(I<%opt>) Returns a promise that resolves into a Travel::Status::DE::EFA instance -($status) on success and rejects with an error message on failure. In addition -to the arguments of B<new>, the following mandatory arguments must be set. +($status) on success and rejects with an error message on failure. In case +the error occured after construction of the Travel::Status::DE::EFA object +(e.g. due to an ambiguous name/place parameter), the second argument of the +rejected promise holds a Travel::Status::DE::EFA instance that can be used +to query place/name candidates (see name_candidates and place_candidates). + +In addition to the arguments of B<new>, the following mandatory arguments must +be set. =over @@ -902,7 +938,7 @@ efa-m(1), Travel::Status::DE::EFA::Departure(3pm). =head1 AUTHOR -Copyright (C) 2011-2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2011-2025 Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE |