Travel::Status::DE::DBRIS - Interface to bahn.de / bahnhof.de departure monitors
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 0.01
Travel::Status::DE::DBRIS is an unofficial interface to bahn.de and bahnhof.de APIs.
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:
Request station board (departures) for station, e.g. 8000080 for Dortmund
Hbf. Results are available via $status->results
.
Search for stations near latitude, longitude.
Results are available via $status->results
.
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.
A Cache::File(3pm) object used to cache realtime data requests. It should be configured for an expiry of one to two minutes.
Passed on to LWP::UserAgent->new
. Defaults to { timeout => 10 }
,
you can use an empty hashref to unset the default.
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:
Promises implementation to use for internal promises as well as new_p return value. Recommended: Mojo::Promise(3pm).
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).
In case of a fatal HTTP request or backend error, returns a string describing it. Returns undef otherwise.
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.
None.
This module is very much work-in-progress.
Copyright (C) 2024-2025 Birte Kristina Friesel <derf@finalrewind.org>
This module is licensed under the same terms as Perl itself.