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:
parent
71fa446800
commit
1233796866
2 changed files with 18 additions and 20 deletions
|
@ -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 =>
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -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 ) {
|
||||||
|
|
Loading…
Reference in a new issue