Skip to content
Snippets Groups Projects
Commit c56d126d authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Traewelling: Add missing "Accept: application/json" header to API requests

parent 0b6df385
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,11 @@ 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment