diff options
Diffstat (limited to 'lib/Travel/Status/DE/DBRIS.pm')
-rw-r--r-- | lib/Travel/Status/DE/DBRIS.pm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/DBRIS.pm b/lib/Travel/Status/DE/DBRIS.pm index 5fd7a2e..fe03809 100644 --- a/lib/Travel/Status/DE/DBRIS.pm +++ b/lib/Travel/Status/DE/DBRIS.pm @@ -13,6 +13,8 @@ use DateTime::Format::Strptime; use Encode qw(decode encode); use JSON; use LWP::UserAgent; + +use Travel::Status::DE::DBRIS::Formation; use Travel::Status::DE::DBRIS::JourneyAtStop; use Travel::Status::DE::DBRIS::Journey; use Travel::Status::DE::DBRIS::Location; @@ -87,6 +89,22 @@ sub new { $req = "https://www.bahn.de/web/api/reiseloesung/fahrt?journeyId=${journey_id}&poly=${poly}"; } + elsif ( my $cf = $conf{formation} ) { + my $datetime = $cf->{departure}->clone->set_time_zone('UTC'); + my $date = $datetime->strftime('%Y-%m-%d'); + my $time = $datetime->rfc3339 =~ s{(?=Z)}{.000}r; + my %param = ( + administrationId => 80, + category => $cf->{train_type}, + date => $date, + evaNumber => $cf->{eva}, + number => $cf->{train_number}, + time => $time + ); + $req + = 'https://www.bahn.de/web/api/reisebegleitung/wagenreihung/vehicle-sequence?' + . join( '&', map { $_ . '=' . $param{$_} } sort keys %param ); + } else { confess( 'station / geoSearch / locationSearch / journey must be specified' @@ -141,6 +159,9 @@ sub new { elsif ( $conf{geoSearch} or $conf{locationSearch} ) { $self->parse_search; } + elsif ( $conf{formation} ) { + $self->parse_formation( $conf{formation} ); + } return $self; } @@ -310,6 +331,15 @@ sub parse_stationboard { return $self; } +sub parse_formation { + my ( $self, $conf ) = @_; + + $self->{result} = Travel::Status::DE::DBRIS::Formation->new( + json => $self->{raw_json}, + train_type => $conf->{train_type} + ); +} + # }}} # {{{ Public Functions |