Use proper json encoding for new API methods
Change-Id: I3a7ee7168b196fbbd7e38b09b67d10994dda3568
diff --git a/script/derekovecs-server b/script/derekovecs-server
index ef99ff6..6861f14 100755
--- a/script/derekovecs-server
+++ b/script/derekovecs-server
@@ -278,24 +278,34 @@
$self->render(data => $calendar, format=>'text');
};
+any '/getVocabSize' => sub {
+ my $self = shift;
+ $self->render(data => getVocabSize(), format=>'json');
+};
+
+any '*/getVocabSize' => sub {
+ my $self = shift;
+ $self->render(data => getVocabSize(), format=>'json');
+};
+
any '/getVersion' => sub {
my $self = shift;
- $self->render(data => $VERSION, format=>'text');
+ $self->render(data => to_json($VERSION), format=>'json');
};
any '*/getVersion' => sub {
my $self = shift;
- $self->render(data => $VERSION, format=>'text');
+ $self->render(data => to_json($VERSION), format=>'json');
};
any '/getModelName' => sub {
my $self = shift;
- $self->render(data => $title, format=>'text');
+ $self->render(data => to_json($title), format=>'json');
};
any '*/getModelName' => sub {
my $self = shift;
- $self->render(data => $title, format=>'text');
+ $self->render(data => to_json($title), format=>'json');
};
get '*/img/*' => sub {
diff --git a/t/server-test.t b/t/server-test.t
index 851c1a8..6ed4c57 100644
--- a/t/server-test.t
+++ b/t/server-test.t
@@ -37,11 +37,12 @@
$client->GET('http://localhost:3000/getVersion');
$res = $client->responseContent();
-like($res, qr/\d+\.?\d*\.?\d*/, "version ok");
+like($res, qr/^"\d+\.?\d*\.?\d*"$/, "version ok");
$client->GET('http://localhost:3000/getModelName');
$res = $client->responseContent();
-is($res, "wpd19_10000", "model name ok");
+is($res, '"wpd19_10000"', "model name ok");
+
for (my $i=0; $i<4; $i++) {
$pid++;