summaryrefslogtreecommitdiff
path: root/lib/Net/HTTP/Console/Dispatcher/HTTPRequest.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-08 13:18:38 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-08 13:18:38 +0200
commit548f1a38f43a1b5da435b3a7c778f5ec3471f2f2 (patch)
tree4b36535807ec253033bc6f4ba0f259e62c74d1f6 /lib/Net/HTTP/Console/Dispatcher/HTTPRequest.pm
parentupdate name of api methods; fetch doc from method (diff)
downloadnet-http-console-548f1a38f43a1b5da435b3a7c778f5ec3471f2f2.tar.gz
update regex; modify http methods; ..
Diffstat (limited to '')
-rw-r--r--lib/Net/HTTP/Console/Dispatcher/HTTPRequest.pm37
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/Net/HTTP/Console/Dispatcher/HTTPRequest.pm b/lib/Net/HTTP/Console/Dispatcher/HTTPRequest.pm
index fd429b4..ec8892f 100644
--- a/lib/Net/HTTP/Console/Dispatcher/HTTPRequest.pm
+++ b/lib/Net/HTTP/Console/Dispatcher/HTTPRequest.pm
@@ -3,10 +3,7 @@ package Net::HTTP::Console::Dispatcher::HTTPRequest;
use Moose;
use Try::Tiny;
-with qw/
- Net::HTTP::Console::Dispatcher
- Net::HTTP::Console::Role::HTTP
- /;
+with qw/ Net::HTTP::Console::Dispatcher /;
sub _clean_http_lib {
my $self = shift;
@@ -27,11 +24,12 @@ sub dispatch {
elsif ($input =~ /^(POST|PUT)\s(.*)(?:\s(.*))$/) {
$self->_do_request_with_body($1, $2, $3);
}
- elsif($input =~ /^show\s(headers|content)$/) {
+ elsif ($input =~ /^show\s(headers|content)$/) {
my $method = "_show_last_$1";
- $self->$method;
+ $self->application->$method;
}
else {
+
# XXX unsupporter method
}
return 1;
@@ -39,30 +37,39 @@ sub dispatch {
sub pattern {
my ($self, $input) = @_;
- $input =~ /^(?:GET|POST|PUT|DELETE|HEAD|show)/ ? return $input : return 0;
+ $input =~ /^(?:GET|POST|PUT|DELETE|HEAD|show)\s/ ? return $input : return 0;
}
sub _do_request {
my ($self, $http_method, $path) = @_;
- my $http_console = $self->application->new_lib($http_method, $path);
+ $self->application->new_anonymous_method($http_method, $path);
try {
- my ($content, $result) = $http_console->anonymous;
- $self->_set_and_show($content, $result);
+ my ($content, $result) = $self->application->api_object->anonymous;
+ $self->application->_set_and_show($content, $result);
+ }catch{
+ warn $_;
};
}
sub _do_request_with_body {
my ($self, $http_method, $path, $body) = @_;
- my $http_console = $self->application->new_lib($http_method, $path);
- $http_console->api_useragent->add_handler(
+ $self->application->new_anonymous_method($http_method, $path);
+
+ # XXX clean handlers
+ $self->application->api_object->api_useragent->add_handler(
request_prepare => sub {
my $request = shift;
- $request->content($body);
+ $request->header('Content-Type' => 'application/json');
+ $request->content('{"foof":"bar"}');
}
);
try {
- my ($content, $result) = $http_console->anonymous;
- $self->_set_and_show($content, $result);
+ my ($content, $result) = $self->application->api_object->anonymous;
+ $self->application->_set_and_show($content, $result);
+ }catch{
+ warn $_;
+ use YAML::Syck;
+ warn Dump $_->http_error;
};
}