summary refs log tree commit diff
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
parentadd kwalitee (diff)
downloadmoosex-net-api-b278d3a89da49ab9cd879a129e9734c19cdfee29.tar.gz
remove method; pretty output
-rw-r--r--bin/http-console19
-rw-r--r--lib/MooseX/Net/API/Meta/Method/APIMethod.pm9
2 files changed, 22 insertions, 6 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);
+}
diff --git a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm b/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
index 0f6a6e8..ac57edf 100644
--- a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
+++ b/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
@@ -9,7 +9,7 @@ use MooseX::Types::Moose qw/Str ArrayRef/;
 
 has local_api_methods => (
     traits     => ['Array'],
-    is         => 'ro',
+    is         => 'rw',
     isa        => ArrayRef [Str],
     required   => 1,
     default    => sub { [] },
@@ -60,6 +60,13 @@ after add_net_api_method => sub {
     );
 };
 
+sub remove_net_api_method {
+    my ($meta, $name) = @_;
+    my @methods = grep { !/$name/ } $meta->get_all_api_methods;
+    $meta->local_api_methods(\@methods);
+    $meta->remove_method($name);
+}
+
 1;
 
 =head1 SYNOPSIS