Traewelling: Add missing "Accept: application/json" header to API requests
This commit is contained in:
parent
0b6df3859c
commit
c56d126d89
1 changed files with 12 additions and 19 deletions
|
@ -13,9 +13,10 @@ sub new {
|
|||
|
||||
my $version = $opt{version};
|
||||
|
||||
$opt{header}
|
||||
= { 'User-Agent' =>
|
||||
"travelynx/${version} on $opt{root_url} +https://finalrewind.org/projects/travelynx"
|
||||
$opt{header} = {
|
||||
'User-Agent' =>
|
||||
"travelynx/${version} on $opt{root_url} +https://finalrewind.org/projects/travelynx",
|
||||
'Accept' => 'application/json',
|
||||
};
|
||||
|
||||
return bless( \%opt, $class );
|
||||
|
@ -30,6 +31,7 @@ sub get_status_p {
|
|||
|
||||
my $header = {
|
||||
'User-Agent' => $self->{header}{'User-Agent'},
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => "Bearer $token",
|
||||
};
|
||||
|
||||
|
@ -119,6 +121,7 @@ sub get_user_p {
|
|||
|
||||
my $header = {
|
||||
'User-Agent' => $self->{header}{'User-Agent'},
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => "Bearer $token",
|
||||
};
|
||||
my $promise = Mojo::Promise->new;
|
||||
|
@ -173,8 +176,9 @@ sub login_p {
|
|||
my $token;
|
||||
|
||||
$ua->post_p(
|
||||
"https://traewelling.de/api/v0/auth/login" => $self->{header} =>
|
||||
json => $request )->then(
|
||||
"https://traewelling.de/api/v0/auth/login" => $self->{header},
|
||||
json => $request
|
||||
)->then(
|
||||
sub {
|
||||
my ($tx) = @_;
|
||||
if ( my $err = $tx->error ) {
|
||||
|
@ -240,6 +244,7 @@ sub logout_p {
|
|||
|
||||
my $header = {
|
||||
'User-Agent' => $self->{header}{'User-Agent'},
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => "Bearer $token",
|
||||
};
|
||||
my $request = {};
|
||||
|
@ -279,6 +284,7 @@ sub checkin {
|
|||
|
||||
my $header = {
|
||||
'User-Agent' => $self->{header}{'User-Agent'},
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => "Bearer $opt{token}",
|
||||
};
|
||||
|
||||
|
@ -323,19 +329,6 @@ sub checkin {
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# Work around https://github.com/Traewelling/traewelling/issues/128
|
||||
if ( $tx->res->code == 302 ) {
|
||||
my $err_msg = "Der Login-Token wurde nicht akzeptiert";
|
||||
$self->{log}->debug("... error: $err_msg");
|
||||
$self->{model}->log(
|
||||
uid => $opt{uid},
|
||||
message =>
|
||||
"Fehler bei $opt{train_type} $opt{train_no}: $err_msg",
|
||||
is_error => 1
|
||||
);
|
||||
return;
|
||||
}
|
||||
$self->{log}->debug( "... success! " . $tx->res->body );
|
||||
|
||||
# As of 2020-10-04, traewelling.de checkins do not yet return
|
||||
|
|
Loading…
Reference in a new issue