From 3c0333278581fec8998ebe485c70778084c20b5a Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 19 Nov 2023 16:52:36 +0100 Subject: Implement journeyMatch requests --- lib/Travel/Status/DE/HAFAS.pm | 82 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'lib/Travel/Status/DE/HAFAS.pm') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index c085f4a..c49551a 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -198,12 +198,14 @@ sub new { if ( not( $conf{station} or $conf{journey} + or $conf{journeyMatch} or $conf{geoSearch} or $conf{locationSearch} ) ) { confess( - 'station / journey / geoSearch / locationSearch must be specified'); +'station / journey / journeyMatch / geoSearch / locationSearch must be specified' + ); } if ( not defined $service ) { @@ -248,6 +250,27 @@ sub new { %{ $hafas_instance{$service}{request} } }; } + elsif ( $conf{journeyMatch} ) { + $req = { + svcReqL => [ + { + meth => 'JourneyMatch', + req => { + date => ( $conf{datetime} // $now )->strftime('%Y%m%d'), + input => $conf{journeyMatch}, + jnyFltrL => [ + { + type => "PROD", + mode => "INC", + value => $self->mot_mask + } + ] + }, + } + ], + %{ $hafas_instance{$service}{request} } + }; + } elsif ( $conf{geoSearch} ) { $req = { svcReqL => [ @@ -406,6 +429,9 @@ sub new { if ( $conf{journey} ) { $self->parse_journey; } + elsif ( $conf{journeyMatch} ) { + $self->parse_journey_match; + } elsif ( $conf{geoSearch} or $conf{locationSearch} ) { $self->parse_search; } @@ -423,11 +449,14 @@ sub new_p { if ( not( $conf{station} or $conf{journey} + or $conf{journeyMatch} or $conf{geoSearch} or $conf{locationSearch} ) ) { - return $promise->reject('station or journey flag must be passed'); + return $promise->reject( +'station / journey / journeyMatch / geoSearch / locationSearch flag must be passed' + ); } my $self = $obj->new( %conf, async => 1 ); @@ -441,6 +470,9 @@ sub new_p { if ( $conf{journey} ) { $self->parse_journey; } + elsif ( $conf{journeyMatch} ) { + $self->parse_journey_match; + } elsif ( $conf{geoSearch} or $conf{locationSearch} ) { $self->parse_search; } @@ -700,6 +732,34 @@ sub parse_journey { return $self; } +sub parse_journey_match { + my ($self) = @_; + + $self->{results} = []; + + if ( $self->{errstr} ) { + return $self; + } + + my @locL = map { Travel::Status::DE::HAFAS::Location->new( loc => $_ ) } + @{ $self->{raw_json}{svcResL}[0]{res}{common}{locL} // [] }; + + my @jnyL = @{ $self->{raw_json}{svcResL}[0]{res}{jnyL} // [] }; + + for my $result (@jnyL) { + push( + @{ $self->{results} }, + Travel::Status::DE::HAFAS::Journey->new( + common => $self->{raw_json}{svcResL}[0]{res}{common}, + locL => \@locL, + journey => $result, + hafas => $self, + ) + ); + } + return $self; +} + sub parse_board { my ($self) = @_; @@ -950,6 +1010,14 @@ Results are available via C<< $status->results >>. Request details about the journey identified by I and I. The result is available via C<< $status->result >>. +=item B => I + +Request journeys that match I (e.g. "ICE 205" or "S 31111"). +Results are available via C<< $status->results >>. +In contrast to B, the results typically only contain a minimal amount +of information: trip ID, train/line identifier, and first and last stop. There +is no real-time data. + =back The following optional flags may be set. @@ -973,14 +1041,14 @@ minutes. Date and time to report for. Defaults to now. -=item B => [I, I, ...] (geoSearch, station) +=item B => [I, I, ...] (geoSearch, station, journeyMatch) By default, all modes of transport (trains, trams, buses etc.) are returned. If this option is set, all modes appearing in I, I, ... will be excluded. The supported modes depend on B, use B or B to get the supported values. -=item B => [I, I, ...] (geoSearch, station) +=item B => [I, I, ...] (geoSearch, station, journeyMatch) If this option is set, only the modes of transport appearing in I, I, ... will be returned. The supported modes depend on B, use @@ -1069,6 +1137,12 @@ Travel::Status::DE::HAFAS::Journey(3pm) object. If no matching results were found or the parser / http request failed, returns undef. +=item $status->results (journeyMatch) + +Returns a list of Travel::Status::DE::HAFAS::Journey(3pm) object that describe +matching journeys. In general, these objects lack real-time data, +intermediate stops, and more. + =item $status->result (journey) Returns a single Travel::Status::DE::HAFAS::Journey(3pm) object that describes -- cgit v1.2.3