diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-10-11 22:32:41 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-10-11 22:32:41 +0200 |
commit | db263b06a197ea6b949d0fbbc06c4012921a7842 (patch) | |
tree | 284d9e4cba88e984567abc598f0818ade5537189 | |
parent | 717b01728d0cbc65a665ae6cc411d3938dfc0dfb (diff) |
new_p: support journey argument
-rw-r--r-- | lib/Travel/Status/DE/HAFAS.pm | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 1da0ee8..bdcaff8 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -188,7 +188,7 @@ sub new { } if ( not $conf{station} and not $conf{journey} ) { - confess('You need to specify a station'); + confess('station or journey must be specified'); } if ( not defined $service ) { @@ -363,8 +363,8 @@ sub new_p { my ( $obj, %conf ) = @_; my $promise = $conf{promise}->new; - if ( not $conf{station} ) { - return $promise->reject('station flag must be passed'); + if ( not $conf{station} and not $conf{journey} ) { + return $promise->reject('station or journey flag must be passed'); } my $self = $obj->new( %conf, async => 1 ); @@ -375,8 +375,18 @@ sub new_p { my ($content) = @_; $self->{raw_json} = $self->{json}->decode($content); $self->check_mgate; - $self->parse_board; - $promise->resolve($self); + if ( $conf{journey} ) { + $self->parse_journey; + } + else { + $self->parse_board; + } + if ( $self->errstr ) { + $promise->reject( $self->errstr ); + } + else { + $promise->resolve($self); + } return; } )->catch( |