summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Helper
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-10-28 22:51:15 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-10-28 22:51:15 +0200
commit3f4fc57ba097ce969031ab1a1398d4bb657ca056 (patch)
tree1181e470a81b29755be3a4a4ad392c872939f84c /lib/DBInfoscreen/Helper
parent1d2cdb99fd41f0bb2c53c0aeaf928d0ca412b5ee (diff)
Use T-S-DE-HAFAS rather than transport.rest for map4.12.0
Squashed commit of the following: commit ebba74fa1f732c12a4323a7b58df56e02bcb7953 Author: Daniel Friesel <derf@finalrewind.org> Date: Fri Oct 28 22:50:52 2022 +0200 update cpanfile.snapshot commit a6248cca63a96cb6a94723d017e58c7064b5fa73 Author: Daniel Friesel <derf@finalrewind.org> Date: Fri Oct 28 22:30:38 2022 +0200 cpanfile: requires T-S-DE-HAFAS commit c4b8357736976f54b2c32343210dd3612a7d60fe Author: Daniel Friesel <derf@finalrewind.org> Date: Fri Oct 28 22:28:41 2022 +0200 map: handle cancelled arrivals / stops commit 70bbd2bd1270ca10cb2f72aad333d265d0936a18 Author: Daniel Friesel <derf@finalrewind.org> Date: Thu Oct 27 23:01:24 2022 +0200 transport.rest is no longer in use commit d43e985785759b3eecfd0f6912e6e0266de24ba4 Author: Daniel Friesel <derf@finalrewind.org> Date: Thu Oct 27 22:59:28 2022 +0200 about: map is now served via T-S-DE-HAFAS commit 382262e29f00b8b0425366fa847d4d07c59ce0a1 Author: Daniel Friesel <derf@finalrewind.org> Date: Wed Oct 26 22:44:36 2022 +0200 map: update T-S-DE-HAFAS API commit 7e5f1e5c7d1ffaa5bdbbbf61124983e6c6e7fdd8 Author: Daniel Friesel <derf@finalrewind.org> Date: Tue Oct 25 21:19:16 2022 +0200 Use Travel::Status::DE::HAFAS 4.00 (unreleased) instead of transport.rest commit 706179018143d0cad4c1d5c05f110ff084dd5bc7 Author: Daniel Friesel <derf@finalrewind.org> Date: Sun Oct 16 22:44:22 2022 +0200 remove unused and unmaintained train intersection code
Diffstat (limited to 'lib/DBInfoscreen/Helper')
-rw-r--r--lib/DBInfoscreen/Helper/HAFAS.pm66
1 files changed, 16 insertions, 50 deletions
diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm
index 48632c0..a13fd4a 100644
--- a/lib/DBInfoscreen/Helper/HAFAS.pm
+++ b/lib/DBInfoscreen/Helper/HAFAS.pm
@@ -10,6 +10,7 @@ use 5.020;
use DateTime;
use Encode qw(decode encode);
+use Travel::Status::DE::HAFAS;
use Mojo::JSON qw(decode_json);
use Mojo::Promise;
use XML::LibXML;
@@ -438,68 +439,33 @@ sub get_route_timestamps_p {
}
# Input: (HAFAS TripID, line number)
-# Output: Promise returning a
-# https://github.com/public-transport/hafas-client/blob/4/docs/trip.md instance
-# on success
+# Output: Promise returning a Travel::Status::DE::HAFAS::Journey instance on success
sub get_polyline_p {
my ( $self, $trip_id, $line ) = @_;
- my $api = $self->{api};
- my $url = "${api}/trips/${trip_id}?lineName=${line}&polyline=true";
- my $log_url = $url;
- my $cache = $self->{realtime_cache};
my $promise = Mojo::Promise->new;
- $log_url =~ s{://\K[^:]+:[^@]+\@}{***@};
-
- if ( my $content = $cache->thaw($url) ) {
- $promise->resolve($content);
- $self->{log}->debug("GET $log_url (cached)");
- return $promise;
- }
-
- $self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
- ->then(
+ Travel::Status::DE::HAFAS->new_p(
+ journey => {
+ id => $trip_id,
+ name => $line,
+ },
+ with_polyline => 1,
+ cache => $self->{realtime_cache},
+ promise => 'Mojo::Promise',
+ user_agent => $self->{user_agent}->request_timeout(5)
+ )->then(
sub {
- my ($tx) = @_;
+ my ($hafas) = @_;
+ my $journey = $hafas->result;
- if ( my $err = $tx->error ) {
- $self->{log}->warn(
-"hafas->get_polyline_p($log_url): HTTP $err->{code} $err->{message}"
- );
- $promise->reject(
- "GET $log_url returned HTTP $err->{code} $err->{message}");
- return;
- }
-
- $self->{log}->debug("GET $log_url (OK)");
- my $json = decode_json( $tx->res->body );
- my @coordinate_list;
-
- for my $feature ( @{ $json->{polyline}{features} } ) {
- if ( exists $feature->{geometry}{coordinates} ) {
- push( @coordinate_list, $feature->{geometry}{coordinates} );
- }
-
- #if ($feature->{type} eq 'Feature') {
- # say "Feature " . $feature->{properties}{name};
- #}
- }
-
- my $ret = {
- name => $json->{line}{name} // '?',
- polyline => [@coordinate_list],
- raw => $json,
- };
-
- $cache->freeze( $url, $ret );
- $promise->resolve($ret);
+ $promise->resolve($journey);
return;
}
)->catch(
sub {
my ($err) = @_;
- $self->{log}->debug("GET $log_url (error: $err)");
+ $self->{log}->debug("HAFAS->new_p($trip_id, $line) error: $err");
$promise->reject($err);
return;
}