summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Controller/Wagenreihung.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-09-16 17:21:49 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-09-16 17:21:49 +0200
commit2ca4a50194108d378b961fb8ddc9a0455933d96d (patch)
treee9e7dee370b54f473bdfcaad543f085dd16a92d4 /lib/DBInfoscreen/Controller/Wagenreihung.pm
parent65aab8c7f827d0c0edf1249ea30c287c5f91ace8 (diff)
all requests but IRIS are async now
Diffstat (limited to 'lib/DBInfoscreen/Controller/Wagenreihung.pm')
-rw-r--r--lib/DBInfoscreen/Controller/Wagenreihung.pm43
1 files changed, 1 insertions, 42 deletions
diff --git a/lib/DBInfoscreen/Controller/Wagenreihung.pm b/lib/DBInfoscreen/Controller/Wagenreihung.pm
index 7b59227..ecdb129 100644
--- a/lib/DBInfoscreen/Controller/Wagenreihung.pm
+++ b/lib/DBInfoscreen/Controller/Wagenreihung.pm
@@ -4,53 +4,12 @@ use Mojo::Base 'Mojolicious::Controller';
# Copyright (C) 2011-2019 Daniel Friesel <derf+dbf@finalrewind.org>
# License: 2-Clause BSD
-use Encode qw(decode);
-use JSON;
-use Mojo::Promise;
use Travel::Status::DE::DBWagenreihung;
my $dbf_version = qx{git describe --dirty} || 'experimental';
chomp $dbf_version;
-sub get_wagenreihung_p {
- my ( $self, $train_no, $api_ts ) = @_;
-
- my $url
- = "https://www.apps-bahn.de/wr/wagenreihung/1.0/${train_no}/${api_ts}";
-
- my $cache = $self->app->cache_iris_rt;
-
- my $promise = Mojo::Promise->new;
-
- if ( my $content = $cache->thaw($url) ) {
- $promise->resolve($content);
- $self->app->log->debug("GET $url (cached)");
- return $promise;
- }
-
- $self->ua->request_timeout(10)
- ->get_p( $url, { 'User-Agent' => "dbf.finalrewind.org/${dbf_version}" } )
- ->then(
- sub {
- my ($tx) = @_;
- $self->app->log->debug("GET $url (OK)");
- my $body = decode( 'utf-8', $tx->res->body );
- my $json = JSON->new->decode($body);
-
- $cache->freeze( $url, $json );
- $promise->resolve($json);
- }
- )->catch(
- sub {
- my ($err) = @_;
- $self->app->log->debug("GET $url (error: $err)");
- $promise->reject($err);
- }
- )->wait;
- return $promise;
-}
-
sub wagenreihung {
my ($self) = @_;
my $train = $self->stash('train');
@@ -58,7 +17,7 @@ sub wagenreihung {
$self->render_later;
- $self->get_wagenreihung_p( $train, $departure )->then(
+ $self->wagonorder->get_p( $train, $departure )->then(
sub {
my ($json) = @_;
my $wr;