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

@ -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{ ^ (?<id> \d+ ) - (?<token> .* ) $ }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
}
);
}

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>