NAME

Travel::Status::DE::DBRIS - Interface to bahn.de / bahnhof.de departure monitors

SYNOPSIS

Blocking variant:

use Travel::Status::DE::DBRIS;

my $status = Travel::Status::DE::DBRIS->new(station => 8000098);
for my $r ($status->results) {
    printf(
        "%s +%-3d %10s -> %s\n",
        $r->dep->strftime('%H:%M'),
        $r->delay,
        $r->line,
        $r->dest_name
    );
}

Non-blocking variant;

use Mojo::Promise;
use Mojo::UserAgent;
use Travel::Status::DE::DBRIS;

Travel::Status::DE::DBRIS->new_p(
    station => 8000098,
    promise => 'Mojo::Promise',
    user_agent => Mojo::UserAgent->new
)->then(sub {
    my ($status) = @_;
    for my $r ($status->results) {
        printf(
            "%s +%-3d %10s -> %s\n",
            $r->dep->strftime('%H:%M'),
            $r->delay,
            $r->line,
            $r->dest_name
        );
    }
})->wait;

VERSION

version 0.01

DESCRIPTION

Travel::Status::DE::DBRIS is an unofficial interface to bahn.de and bahnhof.de APIs.

METHODS

my $status = Travel::Status::DE::DBRIS->new(%opt)

Requests item(s) as specified by opt and returns a new Travel::Status::DE::DBRIS element with the results. Dies if the wrong opt were passed.

opt must contain either a station, geoSearch, or locationSearch flag:

station => station

Request station board (departures) for station, e.g. 8000080 for Dortmund Hbf. Results are available via $status->results.

geoSearch => { latitude => latitude, longitude => longitude }

Search for stations near latitude, longitude. Results are available via $status->results.

locationSearch => query

Search for stations whose name is equal or similar to query. Results are available via $status->results and include the station ID needed for station board requests.

The following optional flags may be set. Values in brackets indicate flags that are only relevant in certain request modes, e.g. geoSearch or station.

cache => $obj

A Cache::File(3pm) object used to cache realtime data requests. It should be configured for an expiry of one to two minutes.

lwp_options => \%hashref

Passed on to LWP::UserAgent->new. Defaults to { timeout => 10 }, you can use an empty hashref to unset the default.

my $promise = Travel::Status::DE::DBRIS->new_p(%opt)

Return a promise yielding a Travel::Status::DE::DBRIS instance ($status) on success, or an error message (same as $status->errstr) on failure.

In addition to the arguments of new, the following mandatory arguments must be set:

promise => promises module

Promises implementation to use for internal promises as well as new_p return value. Recommended: Mojo::Promise(3pm).

user_agent => user agent

User agent instance to use for asynchronous requests. The object must support promises (i.e., it must implement a get_p function). Recommended: Mojo::UserAgent(3pm).

$status->errstr

In case of a fatal HTTP request or backend error, returns a string describing it. Returns undef otherwise.

$status->results

Returns a list of Travel::Status::DE::DBRIS::Location(3pm) or Travel::Status::DE::DBRIS::JourneyAtStop(3pm) objects, depending on the arguments passed to new.

DIAGNOSTICS

None.

DEPENDENCIES

  • DateTime(3pm)

  • List::Util(3pm)

  • LWP::UserAgent(3pm)

BUGS AND LIMITATIONS

This module is very much work-in-progress.

REPOSITORY

https://github.com/derf/Travel-Status-DE-DBRIS

AUTHOR

Copyright (C) 2024-2025 Birte Kristina Friesel <derf@finalrewind.org>

LICENSE

This module is licensed under the same terms as Perl itself.