import API: Add deprecated field, remove development check

This commit is contained in:
Daniel Friesel 2020-01-26 10:47:51 +01:00
parent 1723f8c1fb
commit c31254e996
2 changed files with 32 additions and 32 deletions

View file

@ -355,29 +355,20 @@ sub import_v1 {
$self->render(
json => {
success => \0,
deprecated => \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',
},
);
return;
}
my $api_token = $payload->{token} // '';
if ( $api_token !~ qr{ ^ (?<id> \d+ ) - (?<token> .* ) $ }x ) {
$self->render(
json => {
success => \0,
deprecated => \0,
error => 'Malformed token',
},
);
@ -390,6 +381,7 @@ sub import_v1 {
$self->render(
json => {
success => \0,
deprecated => \0,
error => 'Malformed token',
},
);
@ -397,10 +389,11 @@ sub import_v1 {
}
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,
deprecated => \0,
error => 'Invalid token',
},
);
@ -413,6 +406,7 @@ sub import_v1 {
$self->render(
json => {
success => \0,
deprecated => \0,
error => 'missing fromStation or toStation',
},
);
@ -481,6 +475,7 @@ sub import_v1 {
$self->render(
json => {
success => \0,
deprecated => \0,
error => $first_line
}
);
@ -509,6 +504,7 @@ sub import_v1 {
$self->render(
json => {
success => \0,
deprecated => \0,
error => $error
}
);
@ -517,6 +513,7 @@ sub import_v1 {
$self->render(
json => {
success => \1,
deprecated => \0,
id => $journey_id,
result => $journey
}
@ -528,6 +525,7 @@ sub import_v1 {
$self->render(
json => {
success => \1,
deprecated => \0,
id => $journey_id,
result => $journey
}

View file

@ -203,6 +203,7 @@
<p style="font-family: Monospace;">
{<br/>
"success" : true,<br/>
"deprecated" : true / false, (falls true: Diese API-Version wird irgendwann abgeschaltet, bitte auf eine neue umsteigen)<br/>
"id" : 1234, (ID der eingetragenen Zugfahrt)<br/>
"result" : { ... } (Eingetragene Daten, Datenformat nicht näher spezifiziert und beliebig variabel)<br/>
}
@ -213,6 +214,7 @@
<p style="font-family: Monospace;">
{<br/>
"success" : false,<br/>
"deprecated" : true / false, (falls true: Diese API-Version wird irgendwann abgeschaltet, bitte auf eine neue umsteigen)<br/>
"error" : "Begründung"<br/>
}
</p>