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 { else {
$self->log->debug("... train $traewelling->{line} not found");
$self->traewelling->log( $self->traewelling->log(
uid => $uid, uid => $uid,
message => message =>

View file

@ -74,7 +74,8 @@ sub get_status_p {
}; };
$self->{user_agent}->request_timeout(20) $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( ->then(
sub { sub {
my ($tx) = @_; my ($tx) = @_;
@ -84,33 +85,29 @@ sub get_status_p {
return; return;
} }
else { else {
if ( my $status = $tx->result->json->{statuses}{data}[0] ) { if ( my $status = $tx->result->json->{data}[0] ) {
my $status_id = $status->{id}; my $status_id = $status->{id};
my $message = $status->{body}; my $message = $status->{body};
my $checkin_at my $checkin_at
= $self->parse_datetime( $status->{created_at} ); = $self->parse_datetime( $status->{createdAt} );
my $dep_dt = $self->parse_datetime( my $dep_dt = $self->parse_datetime(
$status->{train_checkin}{departure} ); $status->{train}{origin}{departurePlanned} );
my $arr_dt = $self->parse_datetime( my $arr_dt = $self->parse_datetime(
$status->{train_checkin}{arrival} ); $status->{train}{destination}{arrivalPlanned} );
my $dep_eva my $dep_eva
= $status->{train_checkin}{origin}{ibnr}; = $status->{train}{origin}{rilIdentifier};
my $arr_eva my $arr_eva
= $status->{train_checkin}{destination}{ibnr}; = $status->{train}{destination}{rilIdentifier};
my $dep_name my $dep_name
= $status->{train_checkin}{origin}{name}; = $status->{train}{origin}{name};
my $arr_name my $arr_name
= $status->{train_checkin}{destination}{name}; = $status->{train}{destination}{name};
my $category my $category = $status->{train}{category};
= $status->{train_checkin}{hafas_trip}{category}; my $linename = $status->{train}{lineName};
my $trip_id
= $status->{train_checkin}{hafas_trip}{trip_id};
my $linename
= $status->{train_checkin}{hafas_trip}{linename};
my ( $train_type, $train_line ) = split( qr{ }, $linename ); my ( $train_type, $train_line ) = split( qr{ }, $linename );
$promise->resolve( $promise->resolve(
{ {
@ -123,7 +120,6 @@ sub get_status_p {
arr_dt => $arr_dt, arr_dt => $arr_dt,
arr_eva => $arr_eva, arr_eva => $arr_eva,
arr_name => $arr_name, arr_name => $arr_name,
trip_id => $trip_id,
train_type => $train_type, train_type => $train_type,
line => $linename, line => $linename,
line_no => $train_line, line_no => $train_line,
@ -341,7 +337,7 @@ sub checkin {
destination => q{} . $opt{arr_eva}, destination => q{} . $opt{arr_eva},
departure => $departure_ts, departure => $departure_ts,
arrival => $arrival_ts, arrival => $arrival_ts,
toot => $opt{data}{toot} ? \1 : \0, toot => $opt{data}{toot} ? \1 : \0,
tweet => $opt{data}{tweet} ? \1 : \0, tweet => $opt{data}{tweet} ? \1 : \0,
}; };
@ -350,8 +346,9 @@ sub checkin {
} }
$self->{user_agent}->request_timeout(20) $self->{user_agent}->request_timeout(20)
->post_p( "https://traewelling.de/api/v0/trains/checkin" => ->post_p(
$header => json => $request )->then( "https://traewelling.de/api/v0/trains/checkin" => $header => json =>
$request )->then(
sub { sub {
my ($tx) = @_; my ($tx) = @_;
if ( my $err = $tx->error ) { if ( my $err = $tx->error ) {
@ -363,7 +360,7 @@ sub checkin {
$self->{log}->debug("Traewelling checkin error: $err_msg"); $self->{log}->debug("Traewelling checkin error: $err_msg");
} }
$self->{model}->log( $self->{model}->log(
uid => $opt{uid}, uid => $opt{uid},
message => message =>
"Fehler bei $opt{train_type} $opt{train_no}: $err_msg", "Fehler bei $opt{train_type} $opt{train_no}: $err_msg",
is_error => 1 is_error => 1