summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Net/HTTP/Spore/Meta/Method.pm51
1 files changed, 42 insertions, 9 deletions
diff --git a/lib/Net/HTTP/Spore/Meta/Method.pm b/lib/Net/HTTP/Spore/Meta/Method.pm
index 54967e9..8a1e0a4 100644
--- a/lib/Net/HTTP/Spore/Meta/Method.pm
+++ b/lib/Net/HTTP/Spore/Meta/Method.pm
@@ -50,12 +50,20 @@ has path   => ( is => 'ro', isa => 'UriPath', required => 1 );
 has method => ( is => 'ro', isa => 'Method',  required => 1 );
 has description => ( is => 'ro', isa => 'Str', predicate => 'has_description' );
 
+has required_payload => (
+    is        => 'ro',
+    isa       => 'Boolean',
+    predicate => 'payload_is_required',
+    lazy      => 1,
+    default   => 0,
+    coerce    => 1,
+);
 has authentication => (
     is        => 'ro',
     isa       => 'Boolean',
     predicate => 'has_authentication',
     default   => 0,
-    coerce => 1,
+    coerce    => 1,
 );
 has base_url => (
     is        => 'ro',
@@ -77,17 +85,24 @@ has expected_status => (
     handles    => { find_expected_status => 'grep', },
 );
 has optional_params => (
-    traits  => ['Array'],
-    is      => 'ro',
-    isa     => ArrayRef [Str],
-    predicate => 'has_optional_params',
+    traits     => ['Array'],
+    is         => 'ro',
+    isa        => ArrayRef [Str],
+    predicate  => 'has_optional_params',
     auto_deref => 1,
 );
 has required_params => (
-    traits  => ['Array'],
-    is      => 'ro',
-    isa     => ArrayRef [Str],
-    predicate => 'has_required_params',
+    traits     => ['Array'],
+    is         => 'ro',
+    isa        => ArrayRef [Str],
+    predicate  => 'has_required_params',
+    auto_deref => 1,
+);
+has form_data => (
+    traits     => ['Hash'],
+    is         => 'ro',
+    isa        => 'HashRef',
+    predicate  => 'has_form_data',
     auto_deref => 1,
 );
 has documentation => (
@@ -123,6 +138,24 @@ sub wrap {
           ? delete $method_args{spore_payload}
           : delete $method_args{payload};
 
+        if ( $payload
+            && ( $method->method ne 'POST' || $method->method ne 'PUT' ) )
+        {
+            die Net::HTTP::Spore::Response->new( 599, [],
+                { error => "payload requires a PUT or POST method" },
+            );
+        }
+
+        if ( $method->payload_is_required && !$payload ) {
+            die Net::HTTP::Spore::Response->new(
+                599,
+                [],
+                {
+                    error => "this method require a payload, and no payload is provided",
+                }
+            );
+        }
+
         if ($method->has_required_params) {
             foreach my $required ( $method->required_params ) {
                 if ( !grep { $required eq $_ } keys %method_args ) {