summaryrefslogtreecommitdiff
path: root/lib/POE/Filter/VNDBAPI.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-11-13 16:36:04 +0100
committerYorhel <git@yorhel.nl>2009-11-13 16:36:04 +0100
commit8578b87b8367a2f297a369cb3143627a4b37a4b0 (patch)
tree2c7e7e5968aaef16e577c903bcf63927c62a9523 /lib/POE/Filter/VNDBAPI.pm
parent997d1752ff1b1d2b1cf425b2c05dc180abc2243a (diff)
API: Added sorting and pagination
Diffstat (limited to 'lib/POE/Filter/VNDBAPI.pm')
-rw-r--r--lib/POE/Filter/VNDBAPI.pm21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/POE/Filter/VNDBAPI.pm b/lib/POE/Filter/VNDBAPI.pm
index 0eca3eb2..24188a2f 100644
--- a/lib/POE/Filter/VNDBAPI.pm
+++ b/lib/POE/Filter/VNDBAPI.pm
@@ -6,10 +6,11 @@
# C: login <json-object>
# [ 'login', {object} ]
#
-# C: get <type> <info> <filters>
-# [ 'get', <type>, <info>[ split ',', $2 ], [ filters ] ]
+# C: get <type> <info> <filters> <options>
+# [ 'get', <type>, <info>[ split ',', $2 ], [ filters ], { options } ]
# <type> must match /[a-z\/_]+/
# <info> as string: /[a-z_]+(,[a-z_]+)*/, in perl: [ /[a-z_]+/, .. ]
+# <options> is optional, must be JSON-object otherwise
#
# S: ok
# [ 'ok' ]
@@ -129,7 +130,7 @@ sub get_one {
if(!defined $json) {
my $err = $@;
$err =~ s/,? at .+ line [0-9]+[\.\r\n ]*$//;
- return _err "JSON-decode: $err" if !defined $json;
+ return _err "JSON-decode: $err";
}
return _err qq|"$cmd" command requires a JSON object| if ref($json) ne 'HASH';
return [[ $cmd, $json ]];
@@ -137,11 +138,19 @@ sub get_one {
# C: get
if($self->{type} eq 'server' && $str =~ /^$WS*get$WS+($GET_TYPE)$WS+($GET_INFO)$WS+(.+)$/s) {
- my($type, $info) = ($1, $2);
+ my($type, $info, $options) = ($1, $2, {});
my($filters, $rest) = decode_filters($3);
return _err $filters if !ref $filters;
- return _err 'Leading characters' if length $rest && $rest !~ /^$WS+$/;
- return [[ 'get', $type, [ split /,/, $info ], $filters ]];
+ if($rest !~ /^$WS*$/) {
+ $options = eval { JSON::XS->new->decode($rest) };
+ if(!defined $options) {
+ my $err = $@;
+ $err =~ s/,? at .+ line [0-9]+[\.\r\n ]*$//;
+ return _err "JSON-decode: $err";
+ }
+ return _err 'options argument must be a JSON object' if ref($options) ne 'HASH';
+ }
+ return [[ 'get', $type, [ split /,/, $info ], $filters, $options ]];
}
# S: ok