summaryrefslogtreecommitdiff
path: root/lib/Travelynx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx')
-rw-r--r--lib/Travelynx/Helper/HAFAS.pm89
1 files changed, 0 insertions, 89 deletions
diff --git a/lib/Travelynx/Helper/HAFAS.pm b/lib/Travelynx/Helper/HAFAS.pm
index fbca740..5253a4e 100644
--- a/lib/Travelynx/Helper/HAFAS.pm
+++ b/lib/Travelynx/Helper/HAFAS.pm
@@ -111,95 +111,6 @@ sub get_polyline_p {
return $promise;
}
-sub get_tripid_p {
- my ( $self, $train ) = @_;
-
- my $promise = Mojo::Promise->new;
- my $cache = $self->{main_cache};
- my $eva = $train->station_uic;
-
- my $dep_ts = DateTime->now( time_zone => 'Europe/Berlin' );
- my $url
- = "https://2.db.transport.rest/stations/${eva}/departures?duration=5&when=$dep_ts";
-
- if ( $train->sched_departure ) {
- $dep_ts = $train->sched_departure->epoch;
- $url
- = "https://2.db.transport.rest/stations/${eva}/departures?duration=5&when=$dep_ts";
- }
- elsif ( $train->sched_arrival ) {
- $dep_ts = $train->sched_arrival->epoch;
- $url
- = "https://2.db.transport.rest/stations/${eva}/arrivals?duration=5&when=$dep_ts";
- }
-
- $self->get_rest_p($url)->then(
- sub {
- my ($json) = @_;
-
- for my $result ( @{$json} ) {
- if ( $result->{line}
- and $result->{line}{fahrtNr} == $train->train_no )
- {
- my $trip_id = $result->{tripId};
- $promise->resolve($trip_id);
- return;
- }
- }
- $promise->reject( 'hafas->get_tripid_p: train '
- . $train->train_no
- . ' not found' );
- return;
- }
- )->catch(
- sub {
- my ($err) = @_;
- $promise->reject($err);
- return;
- }
- )->wait;
-
- return $promise;
-}
-
-sub get_rest_p {
- my ( $self, $url ) = @_;
-
- my $cache = $self->{main_cache};
- my $promise = Mojo::Promise->new;
-
- if ( my $content = $cache->thaw($url) ) {
- return $promise->resolve($content);
- }
-
- $self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
- ->then(
- sub {
- my ($tx) = @_;
-
- if ( my $err = $tx->error ) {
- $promise->reject(
-"hafas->get_rest_p($url) returned HTTP $err->{code} $err->{message}"
- );
- return;
- }
-
- my $json = JSON->new->decode( $tx->res->body );
- $cache->freeze( $url, $json );
- $promise->resolve($json);
- return;
- }
- )->catch(
- sub {
- my ($err) = @_;
- $self->{log}->info("hafas->get_rest_p($url): $err");
- $promise->reject("hafas->get_rest_p($url): $err");
- return;
- }
- )->wait;
- return $promise;
-}
-
sub get_json_p {
my ( $self, $url ) = @_;