diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-04-04 22:42:08 +0200 | 
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-04-04 22:42:08 +0200 | 
| commit | f830f5d4f514c72b6e4b5a9d5237ce8657ab0914 (patch) | |
| tree | 2ebb291cf90d908c81310326e89b02a284ceaab8 /lib/DBInfoscreen | |
| parent | 6f0b3e5436ca0787776bab985061f6306e0cdae2 (diff) | |
add DBRIS helper4.36.5
Diffstat (limited to 'lib/DBInfoscreen')
| -rw-r--r-- | lib/DBInfoscreen/Helper/DBRIS.pm | 67 | 
1 files changed, 67 insertions, 0 deletions
| diff --git a/lib/DBInfoscreen/Helper/DBRIS.pm b/lib/DBInfoscreen/Helper/DBRIS.pm new file mode 100644 index 0000000..39d1cb0 --- /dev/null +++ b/lib/DBInfoscreen/Helper/DBRIS.pm @@ -0,0 +1,67 @@ +package DBInfoscreen::Helper::DBRIS; + +# Copyright (C) 2025 Birte Kristina Friesel +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +use strict; +use warnings; +use 5.020; + +use DateTime; +use Encode qw(decode encode); +use Travel::Status::DE::DBRIS; +use Mojo::JSON qw(decode_json); +use Mojo::Promise; + +sub new { +	my ( $class, %opt ) = @_; + +	my $version = $opt{version}; + +	$opt{header} +	  = { 'User-Agent' => +"dbf/${version} on $opt{root_url} +https://finalrewind.org/projects/db-fakedisplay" +	  }; + +	return bless( \%opt, $class ); + +} + +# Input: TripID +# Output: Promise returning a Travel::Status::DE::DBRIS::Journey instance on success +sub get_polyline_p { +	my ( $self, %opt ) = @_; + +	my $trip_id = $opt{id}; +	my $promise = Mojo::Promise->new; + +	my $agent = $self->{user_agent}; + +	Travel::Status::DE::DBRIS->new_p( +		journey       => $trip_id, +		with_polyline => 1, +		cache         => $self->{realtime_cache}, +		promise       => 'Mojo::Promise', +		user_agent    => $agent->request_timeout(10) +	)->then( +		sub { +			my ($dbris) = @_; +			my $journey = $dbris->result; + +			$promise->resolve($journey); +			return; +		} +	)->catch( +		sub { +			my ($err) = @_; +			$self->{log}->debug("DBRIS->new_p($trip_id) error: $err"); +			$promise->reject($err); +			return; +		} +	)->wait; + +	return $promise; +} + +1; | 
