summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-04 17:27:23 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-04 17:27:23 +0200
commitb278d3a89da49ab9cd879a129e9734c19cdfee29 (patch)
treef4ec30901c3d5edb79d5ea0a7162d9a024797a91 /bin
parentadd kwalitee (diff)
downloadmoosex-net-api-b278d3a89da49ab9cd879a129e9734c19cdfee29.tar.gz
remove method; pretty output
Diffstat (limited to 'bin')
-rw-r--r--bin/http-console19
1 files changed, 14 insertions, 5 deletions
diff --git a/bin/http-console b/bin/http-console
index 25aaad8..3871c36 100644
--- a/bin/http-console
+++ b/bin/http-console
@@ -4,7 +4,7 @@ use 5.010;
use Term::ReadLine;
use Getopt::Long;
-use YAML::Syck;
+use JSON;
my $url = shift;
my $format_mode = 'append';
@@ -25,6 +25,8 @@ my ($content, $result);
my $term = Term::ReadLine->new("http::net::console");
my $prompt = $url . '> ';
while (defined(my $in = $term->readline($prompt))) {
+ map { http::net::console->meta->remove_net_api_method($_) }
+ http::net::console->meta->get_all_api_methods();
if ($in =~ /^(GET|DELETE)\s(.*)$/) {
my $http_console = http::net::console->new(
api_base_url => $url,
@@ -37,7 +39,7 @@ while (defined(my $in = $term->readline($prompt))) {
path => $2
);
($content, $result) = $http_console->anonymous;
- say $result->content;
+ say JSON->new->pretty->encode($content);
}
elsif ($in =~ /^(POST|PUT)\s(.*)(?:\s(.*))$/) {
my $method = $1;
@@ -60,22 +62,29 @@ while (defined(my $in = $term->readline($prompt))) {
}
);
($content, $result) = $http_console->anonymous;
- say $result->content;
+ say pretty_output($content);
}
elsif ($in eq 'show headers') {
if (defined $result) {
- say Dump $result->headers;
+ map { say $_ . ": " . $result->header($_) }
+ keys %{$result->headers};
+ say "";
}
else {
say "no headers to show";
}
+
}
elsif ($in eq 'show content') {
if (defined $content) {
- say Dump $result->content;
+ say pretty_output($content);
}
else {
say "no content to show";
}
}
}
+
+sub pretty_output {
+ JSON->new->pretty->encode(shift);
+}