Traewelling: Use API v1 for pull sync

API v0 has occasional performance issues and is not a preferable
maintenance target
This commit is contained in:
Daniel Friesel 2022-01-08 10:54:54 +01:00
parent 71fa446800
commit 1233796866
No known key found for this signature in database
GPG key ID: 100D5BFB5166E005
2 changed files with 18 additions and 20 deletions

View file

@ -2289,6 +2289,7 @@ sub startup {
}
}
else {
$self->log->debug("... train $traewelling->{line} not found");
$self->traewelling->log(
uid => $uid,
message =>

View file

@ -74,7 +74,8 @@ sub get_status_p {
};
$self->{user_agent}->request_timeout(20)
->get_p( "https://traewelling.de/api/v0/user/${username}" => $header )
->get_p(
"https://traewelling.de/api/v1/user/${username}/statuses" => $header )
->then(
sub {
my ($tx) = @_;
@ -84,33 +85,29 @@ sub get_status_p {
return;
}
else {
if ( my $status = $tx->result->json->{statuses}{data}[0] ) {
if ( my $status = $tx->result->json->{data}[0] ) {
my $status_id = $status->{id};
my $message = $status->{body};
my $checkin_at
= $self->parse_datetime( $status->{created_at} );
= $self->parse_datetime( $status->{createdAt} );
my $dep_dt = $self->parse_datetime(
$status->{train_checkin}{departure} );
$status->{train}{origin}{departurePlanned} );
my $arr_dt = $self->parse_datetime(
$status->{train_checkin}{arrival} );
$status->{train}{destination}{arrivalPlanned} );
my $dep_eva
= $status->{train_checkin}{origin}{ibnr};
= $status->{train}{origin}{rilIdentifier};
my $arr_eva
= $status->{train_checkin}{destination}{ibnr};
= $status->{train}{destination}{rilIdentifier};
my $dep_name
= $status->{train_checkin}{origin}{name};
= $status->{train}{origin}{name};
my $arr_name
= $status->{train_checkin}{destination}{name};
= $status->{train}{destination}{name};
my $category
= $status->{train_checkin}{hafas_trip}{category};
my $trip_id
= $status->{train_checkin}{hafas_trip}{trip_id};
my $linename
= $status->{train_checkin}{hafas_trip}{linename};
my $category = $status->{train}{category};
my $linename = $status->{train}{lineName};
my ( $train_type, $train_line ) = split( qr{ }, $linename );
$promise->resolve(
{
@ -123,7 +120,6 @@ sub get_status_p {
arr_dt => $arr_dt,
arr_eva => $arr_eva,
arr_name => $arr_name,
trip_id => $trip_id,
train_type => $train_type,
line => $linename,
line_no => $train_line,
@ -350,8 +346,9 @@ sub checkin {
}
$self->{user_agent}->request_timeout(20)
->post_p( "https://traewelling.de/api/v0/trains/checkin" =>
$header => json => $request )->then(
->post_p(
"https://traewelling.de/api/v0/trains/checkin" => $header => json =>
$request )->then(
sub {
my ($tx) = @_;
if ( my $err = $tx->error ) {