From c31254e996a0b2ddc03fdecdb27ab262b88911d1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 26 Jan 2020 10:47:51 +0100 Subject: import API: Add deprecated field, remove development check --- lib/Travelynx/Controller/Api.pm | 62 ++++++++++++++++++------------------- templates/api_documentation.html.ep | 2 ++ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm index 96817fb..e55b2b2 100755 --- a/lib/Travelynx/Controller/Api.pm +++ b/lib/Travelynx/Controller/Api.pm @@ -354,19 +354,9 @@ sub import_v1 { if ( not $payload or ref($payload) ne 'HASH' ) { $self->render( json => { - success => \0, - error => 'Malformed JSON', - }, - ); - return; - } - - if ( $self->app->mode ne 'development' ) { - $self->render( - json => { - success => \0, - error => -'This feature is incomplete and only available in development mode', + success => \0, + deprecated => \0, + error => 'Malformed JSON', }, ); return; @@ -377,8 +367,9 @@ sub import_v1 { if ( $api_token !~ qr{ ^ (? \d+ ) - (? .* ) $ }x ) { $self->render( json => { - success => \0, - error => 'Malformed token', + success => \0, + deprecated => \0, + error => 'Malformed token', }, ); return; @@ -389,19 +380,21 @@ sub import_v1 { if ( $uid > 2147483647 ) { $self->render( json => { - success => \0, - error => 'Malformed token', + success => \0, + deprecated => \0, + error => 'Malformed token', }, ); return; } my $token = $self->get_api_token($uid); - if ( $api_token ne $token->{'import'} ) { + if ( not $token->{'import'} or $api_token ne $token->{'import'} ) { $self->render( json => { - success => \0, - error => 'Invalid token', + success => \0, + deprecated => \0, + error => 'Invalid token', }, ); return; @@ -412,8 +405,9 @@ sub import_v1 { { $self->render( json => { - success => \0, - error => 'missing fromStation or toStation', + success => \0, + deprecated => \0, + error => 'missing fromStation or toStation', }, ); return; @@ -480,8 +474,9 @@ sub import_v1 { my ($first_line) = split( qr{\n}, $@ ); $self->render( json => { - success => \0, - error => $first_line + success => \0, + deprecated => \0, + error => $first_line } ); return; @@ -508,17 +503,19 @@ sub import_v1 { if ($error) { $self->render( json => { - success => \0, - error => $error + success => \0, + deprecated => \0, + error => $error } ); } elsif ( $payload->{dryRun} ) { $self->render( json => { - success => \1, - id => $journey_id, - result => $journey + success => \1, + deprecated => \0, + id => $journey_id, + result => $journey } ); } @@ -527,9 +524,10 @@ sub import_v1 { $tx->commit; $self->render( json => { - success => \1, - id => $journey_id, - result => $journey + success => \1, + deprecated => \0, + id => $journey_id, + result => $journey } ); } diff --git a/templates/api_documentation.html.ep b/templates/api_documentation.html.ep index 0c8c534..c20d37c 100644 --- a/templates/api_documentation.html.ep +++ b/templates/api_documentation.html.ep @@ -203,6 +203,7 @@

{
"success" : true,
+ "deprecated" : true / false, (falls true: Diese API-Version wird irgendwann abgeschaltet, bitte auf eine neue umsteigen)
"id" : 1234, (ID der eingetragenen Zugfahrt)
"result" : { ... } (Eingetragene Daten, Datenformat nicht näher spezifiziert und beliebig variabel)
} @@ -213,6 +214,7 @@

{
"success" : false,
+ "deprecated" : true / false, (falls true: Diese API-Version wird irgendwann abgeschaltet, bitte auf eine neue umsteigen)
"error" : "Begründung"
}

-- cgit v1.2.3