summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Helper
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-09-20 10:43:16 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-09-20 10:43:16 +0200
commit93256284a230bda3c8f04e4a9d3ae689a5fe7ff1 (patch)
treee7cc9cb3ecd765ffdc58d63d505f62bc2bb12a51 /lib/DBInfoscreen/Helper
parentc8f5ba2493b6d9bcceab871d41b7ec5692d41058 (diff)
show direction of travel if available
Diffstat (limited to 'lib/DBInfoscreen/Helper')
-rw-r--r--lib/DBInfoscreen/Helper/Wagonorder.pm39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/DBInfoscreen/Helper/Wagonorder.pm b/lib/DBInfoscreen/Helper/Wagonorder.pm
index 5f0555d..1e9324a 100644
--- a/lib/DBInfoscreen/Helper/Wagonorder.pm
+++ b/lib/DBInfoscreen/Helper/Wagonorder.pm
@@ -142,4 +142,43 @@ sub get_p {
return $promise;
}
+sub get_stationinfo_p {
+ my ( $self, $eva ) = @_;
+
+ my $url = "https://lib.finalrewind.org/dbdb/s/${eva}.json";
+
+ 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 ) {
+ $cache->freeze( $url, {} );
+ $promise->reject("HTTP $err->{code} $err->{message}");
+ return;
+ }
+
+ my $json = $tx->result->json;
+ $cache->freeze( $url, $json );
+ $promise->resolve($json);
+ return;
+ }
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $cache->freeze( $url, {} );
+ $promise->reject($err);
+ return;
+ }
+ )->wait;
+ return $promise;
+}
+
1;