summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Helper
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-07-30 15:14:24 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-07-30 15:14:24 +0200
commitc74b91b09f8888b5d4a35b7b2cb49d313db342d9 (patch)
tree7df5071dcd31070150a7a869053ce027aab84d78 /lib/DBInfoscreen/Helper
parent1db9406711673beee6bf76555851e73b447c44d8 (diff)
Switch to new bahn.de carriage formation API (WiP)
Diffstat (limited to 'lib/DBInfoscreen/Helper')
-rw-r--r--lib/DBInfoscreen/Helper/Wagonorder.pm28
1 files changed, 23 insertions, 5 deletions
diff --git a/lib/DBInfoscreen/Helper/Wagonorder.pm b/lib/DBInfoscreen/Helper/Wagonorder.pm
index 5cdee40..33c7272 100644
--- a/lib/DBInfoscreen/Helper/Wagonorder.pm
+++ b/lib/DBInfoscreen/Helper/Wagonorder.pm
@@ -25,10 +25,28 @@ sub new {
}
sub get_p {
- my ( $self, $train_no, $api_ts ) = @_;
+ my ( $self, %opt ) = @_;
- my $url
- = "https://ist-wr.noncd.db.de/wagenreihung/1.0/${train_no}/${api_ts}";
+ my %param;
+
+ if ( $opt{param} ) {
+ %param = %{ $opt{param} };
+ }
+ else {
+ my $datetime = $opt{datetime}->clone->set_time_zone('UTC');
+ %param = (
+ administrationId => 80,
+ category => $opt{train_type},
+ date => $datetime->strftime('%Y-%m-%d'),
+ evaNumber => $opt{eva},
+ number => $opt{train_number},
+ time => $datetime->rfc3339 =~ s{(?=Z)}{.000}r
+ );
+ }
+
+ my $url = sprintf( '%s?%s',
+'https://www.bahn.de/web/api/reisebegleitung/wagenreihung/vehicle-sequence',
+ join( '&', map { $_ . '=' . $param{$_} } keys %param ) );
my $cache = $self->{realtime_cache};
@@ -39,7 +57,7 @@ sub get_p {
if ( $content->{error} ) {
return $promise->reject($content);
}
- return $promise->resolve($content);
+ return $promise->resolve( $content, \%param );
}
$self->{user_agent}->request_timeout(10)->get_p( $url => $self->{header} )
@@ -66,7 +84,7 @@ sub get_p {
my $json = $tx->res->json;
$cache->freeze( $url, $json );
- $promise->resolve($json);
+ $promise->resolve( $json, \%param );
return;
}
)->catch(