diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-10-04 12:59:08 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-10-04 12:59:08 +0200 |
commit | c56d126d89c21c09b731a4e24378e325e93125b5 (patch) | |
tree | 909d4634f7469ccbf1281034da2b4d6afda2a2e6 /lib/Travelynx/Helper/Traewelling.pm | |
parent | 0b6df3859c69835c24fe78549cf1f079c386f7b3 (diff) |
Traewelling: Add missing "Accept: application/json" header to API requests
Diffstat (limited to 'lib/Travelynx/Helper/Traewelling.pm')
-rw-r--r-- | lib/Travelynx/Helper/Traewelling.pm | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/lib/Travelynx/Helper/Traewelling.pm b/lib/Travelynx/Helper/Traewelling.pm index 48fc16d..92a7e88 100644 --- a/lib/Travelynx/Helper/Traewelling.pm +++ b/lib/Travelynx/Helper/Traewelling.pm @@ -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 |