diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-12-24 10:01:08 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-12-24 10:01:08 +0100 |
commit | 9cb71f78d09b8dc6e7b431c31c2cfac7657d7682 (patch) | |
tree | 53531d309d9e5e71fa4d5a12d9fccbb6a7784331 /lib/Travel/Status/DE/DBRIS.pm | |
parent | e1535415b0ee257b0a475e7de5978612e6153ec3 (diff) |
add journey support
Diffstat (limited to 'lib/Travel/Status/DE/DBRIS.pm')
-rw-r--r-- | lib/Travel/Status/DE/DBRIS.pm | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/Travel/Status/DE/DBRIS.pm b/lib/Travel/Status/DE/DBRIS.pm index 2f17e90..66790b2 100644 --- a/lib/Travel/Status/DE/DBRIS.pm +++ b/lib/Travel/Status/DE/DBRIS.pm @@ -13,6 +13,7 @@ use DateTime::Format::Strptime; use Encode qw(decode encode); use JSON; use LWP::UserAgent; +use Travel::Status::DE::DBRIS::JourneyAtStop; use Travel::Status::DE::DBRIS::Journey; use Travel::Status::DE::DBRIS::Location; @@ -77,10 +78,16 @@ sub new { $req = "https://www.bahn.de/web/api/reiseloesung/orte?suchbegriff=${query}&typ=ALL&limit=10"; } - - # journey : https://www.bahn.de/web/api/reiseloesung/fahrt?journeyId=2%7C%23VN%231%23ST%231733779122%23PI%230%23ZI%23324190%23TA%230%23DA%23141224%231S%238000001%231T%231822%23LS%238000080%23LT%232050%23PU%2380%23RT%231%23CA%23DPN%23ZE%2326431%23ZB%23RE+26431%23PC%233%23FR%238000001%23FT%231822%23TO%238000080%23TT%232050%23&poly=true + elsif ( my $journey_id = $conf{journey} ) { + my $poly = $conf{with_polyline} ? 'true' : 'false'; + $journey_id =~ s{[#]}{%23}g; + $req + = "https://www.bahn.de/web/api/reiseloesung/fahrt?journeyId=${journey_id}&poly=${poly}"; + } else { - confess('station or geoSearch must be specified'); + confess( + 'station / geoSearch / locationSearch / journey must be specified' + ); } $self->{strptime_obj} //= DateTime::Format::Strptime->new( @@ -120,6 +127,9 @@ sub new { if ( $conf{station} ) { $self->parse_stationboard; } + elsif ( $conf{journey} ) { + $self->parse_journey; + } elsif ( $conf{geoSearch} or $conf{locationSearch} ) { $self->parse_search; } @@ -257,6 +267,15 @@ sub get_with_cache_p { return $promise; } +sub parse_journey { + my ($self) = @_; + + $self->{result} = Travel::Status::DE::DBRIS::Journey->new( + json => $self->{raw_json}, + strptime_obj => $self->{strptime_obj} + ); +} + sub parse_search { my ($self) = @_; @@ -273,7 +292,7 @@ sub parse_stationboard { # @{$self->{messages}} = map { Travel::Status::DE::DBRIS::Message->new(...) } @{$self->{raw_json}{globalMessages}/[]}; @{ $self->{results} } = map { - Travel::Status::DE::DBRIS::Journey->new( + Travel::Status::DE::DBRIS::JourneyAtStop->new( json => $_, strptime_obj => $self->{strptime_obj} ) @@ -440,7 +459,7 @@ it. Returns undef otherwise. =item $status->results -Returns a list of Travel::Status::DE::DBRIS::Location(3pm) or Travel::Status::DE::DBRIS::Journey(3pm) objects, depending on the arguments passed to B<new>. +Returns a list of Travel::Status::DE::DBRIS::Location(3pm) or Travel::Status::DE::DBRIS::JourneyAtStop(3pm) objects, depending on the arguments passed to B<new>. =back |