summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Helper
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-01-11 22:33:54 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-01-11 22:33:54 +0100
commitfa21ea4bce78edbf3649d656b98d96f88b0b0aaf (patch)
tree1855ddf34c1ee70e5fcc7d521f3ecfccd119926e /lib/DBInfoscreen/Helper
parentdcdea4247b6457202ce746814ff44d249c32d8b5 (diff)
Wagonorder: refactor dbdb requests
Diffstat (limited to 'lib/DBInfoscreen/Helper')
-rw-r--r--lib/DBInfoscreen/Helper/Wagonorder.pm52
1 files changed, 12 insertions, 40 deletions
diff --git a/lib/DBInfoscreen/Helper/Wagonorder.pm b/lib/DBInfoscreen/Helper/Wagonorder.pm
index 5904d86..d303d18 100644
--- a/lib/DBInfoscreen/Helper/Wagonorder.pm
+++ b/lib/DBInfoscreen/Helper/Wagonorder.pm
@@ -57,12 +57,11 @@ sub is_available_p {
return $promise;
}
-sub has_umlauf_p {
- my ( $self, $train_no ) = @_;
+sub head_dbdb_p {
+ my ( $self, $url ) = @_;
my $promise = Mojo::Promise->new;
- my $url = "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png";
my $cache = $self->{main_cache};
if ( my $content = $cache->get($url) ) {
@@ -98,46 +97,19 @@ sub has_umlauf_p {
return $promise;
}
-sub check_wagonorder_p {
- my ( $self, $train_no, $wr_link ) = @_;
-
- my $promise = Mojo::Promise->new;
+sub has_cycle_p {
+ my ( $self, $train_no ) = @_;
- my $url
- = "https://lib.finalrewind.org/dbdb/has_wagonorder/${train_no}/${wr_link}";
- my $cache = $self->{main_cache};
+ return $self->head_dbdb_p(
+ "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png");
+}
- if ( my $content = $cache->get($url) ) {
- if ( $content eq 'y' ) {
- return $promise->resolve;
- }
- else {
- return $promise->reject;
- }
- }
+sub check_wagonorder_p {
+ my ( $self, $train_no, $wr_link ) = @_;
- $self->{user_agent}->request_timeout(5)->head_p( $url => $self->{header} )
- ->then(
- sub {
- my ($tx) = @_;
- if ( $tx->result->is_success ) {
- $cache->set( $url, 'y' );
- $promise->resolve;
- }
- else {
- $cache->set( $url, 'n' );
- $promise->reject;
- }
- return;
- }
- )->catch(
- sub {
- $cache->set( $url, 'n' );
- $promise->reject;
- return;
- }
- )->wait;
- return $promise;
+ return $self->head_dbdb_p(
+ "https://lib.finalrewind.org/dbdb/has_wagonorder/${train_no}/${wr_link}"
+ );
}
sub get_p {