summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-03 08:34:13 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-03 08:34:13 +0200
commitfdb180a73f97d5a1456d5ac3d0a5a844e22d0ea9 (patch)
tree6ed25ba47d0407ed4dbacdc14711fffa90aa9060
parentupdate tests (diff)
downloadmoosex-net-api-fdb180a73f97d5a1456d5ac3d0a5a844e22d0ea9.tar.gz
http-console: a simple http console to do REST query (like http://github.com/cloudhead/http-console)
-rw-r--r--bin/http-console46
-rw-r--r--lib/MooseX/Net/API/Meta/Method.pm2
-rw-r--r--lib/MooseX/Net/API/Meta/Method/APIMethod.pm1
3 files changed, 48 insertions, 1 deletions
diff --git a/bin/http-console b/bin/http-console
new file mode 100644
index 0000000..6f0e1f8
--- /dev/null
+++ b/bin/http-console
@@ -0,0 +1,46 @@
+use strict;
+use warnings;
+use 5.010;
+use Term::ReadLine;
+
+use Getopt::Long;
+use YAML::Syck;
+
+my $url = shift;
+my $format_mode = 'append';
+my $format = 'json';
+
+GetOptions(
+    'm=s' => \$format_mode,
+    'f=s'      => \$format,
+);
+
+package http::net::console;
+use MooseX::Net::API;
+
+package main;
+
+my ($content, $result);
+
+my $term   = Term::ReadLine->new("http::net::console");
+my $prompt = $url . '> ';
+while (defined(my $in = $term->readline($prompt))) {
+    if ($in =~ /^(GET|PUT|POST|DELETE)\s(.*)$/) {
+        my $http_console =
+          http::net::console->new(api_base_url => $url, api_format => $format, api_format_mode => $format_mode);
+        $http_console->meta->add_net_api_method(
+            'anonymous',
+            method => $1,
+            path   => $2
+        );
+        ($content, $result) = $http_console->anonymous;
+        say $result->content;
+    }
+    if ($in eq 'show headers') {
+        if (defined $result) {
+            say Dump $result->headers;
+        }else{
+            say "no headers to show";
+        }
+    }
+}
diff --git a/lib/MooseX/Net/API/Meta/Method.pm b/lib/MooseX/Net/API/Meta/Method.pm
index 3f77d08..bb29a97 100644
--- a/lib/MooseX/Net/API/Meta/Method.pm
+++ b/lib/MooseX/Net/API/Meta/Method.pm
@@ -99,7 +99,7 @@ sub wrap {
 
             die MooseX::Net::API::Error->new(
                 http_error => $result,
-                reason     => $result->reason,
+                reason     => $result->message,
             );
         };
         $args{body} = $code;
diff --git a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm b/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
index b1d0777..8185522 100644
--- a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
+++ b/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
@@ -30,6 +30,7 @@ before add_net_api_method => sub {
 sub add_net_api_method {
     my ($meta, $name, %options) = @_;
 
+    # accept blessed method
     my $code = delete $options{code};
     $meta->add_method(
         $name,