-sub print_entry {
- my $entry = shift;
- #TODO: handle objects/hashes as well
- foreach my $item (sort keys %$entry) {
- if (ref($entry->{$item}) eq 'ARRAY'){
- printf "%s: [ %s ]\n", $item, join(", ", @{$entry->{$item}});
+sub print_api_result {
+ my ($format, $data, $result_schema, $props_to_print, $sort_key) = @_;
+
+ return if $result_schema->{type} eq 'null';
+
+ if ($format eq 'json') {
+ print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1, pretty => 1 });
+ } elsif ($format eq 'text') {
+ my $type = $result_schema->{type};
+ if ($type eq 'object') {
+ if (defined($props_to_print)) {
+ foreach my $key (@$props_to_print) {
+ print $key . ": " . data_to_text($data->{$key}) . "\n";
+ }
+ } else {
+ foreach my $key (sort keys %$data) {
+ print $key . ": " . data_to_text($data->{$key}) . "\n";
+ }
+ }
+ } elsif ($type eq 'array') {
+ return if !scalar(@$data);
+ my $item_type = $result_schema->{items}->{type};
+ if ($item_type eq 'object') {
+ print_api_list($data, $result_schema, $props_to_print, $sort_key);
+ } else {
+ foreach my $entry (@$data) {
+ print data_to_text($entry) . "\n";
+ }
+ }