add suspend/unsuspend to http exports, RT#20054
[freeside.git] / FS / FS / part_export / http.pm
index e5e5a5c..96d49f0 100644 (file)
@@ -33,6 +33,22 @@ tie %options, 'Tie::IxHash',
     default => join("\n",
     ),
   },
+  'suspend_data' => {
+    label   => 'Suspend data',
+    type    => 'textarea',
+    default => join("\n",
+    ),
+  },
+  'unsuspend_data' => {
+    label   => 'Unsuspend data',
+    type    => 'textarea',
+    default => join("\n",
+    ),
+  },
+  'success_regexp' => {
+    label  => 'Success Regexp',
+    default => '',
+  },
 ;
 
 %info = (
@@ -59,6 +75,16 @@ sub _export_delete {
   $self->_export_command('delete', @_);
 }
 
+sub _export_suspend {
+  my $self = shift;
+  $self->_export_command('suspend', @_);
+}
+
+sub _export_unsuspend {
+  my $self = shift;
+  $self->_export_command('unsuspend', @_);
+}
+
 sub _export_command {
   my( $self, $action, $svc_x ) = ( shift, shift, shift );
 
@@ -71,6 +97,7 @@ sub _export_command {
   $self->http_queue( $svc_x->svcnum,
     $self->option('method'),
     $self->option('url'),
+    $self->option('success_regexp'),
     map {
       /^\s*(\S+)\s+(.*)$/ or /()()/;
       my( $field, $value_expression ) = ( $1, $2 );
@@ -95,6 +122,7 @@ sub _export_replace {
   $self->http_queue( $new->svcnum,
     $self->option('method'),
     $self->option('url'),
+    $self->option('success_regexp'),
     map {
       /^\s*(\S+)\s+(.*)$/ or /()()/;
       my( $field, $value_expression ) = ( $1, $2 );
@@ -114,7 +142,7 @@ sub http_queue {
 }
 
 sub http {
-  my($method, $url, @data) = @_;
+  my($method, $url, $success_regexp, @data) = @_;
 
   $method = lc($method);
 
@@ -134,6 +162,11 @@ sub http {
 
   die $response->error_as_HTML if $response->is_error;
 
+  if(length($success_regexp) > 1) {
+    my $response_content = $response->content;
+    die $response_content unless $response_content =~ /$success_regexp/;
+  }
+
 }
 
 1;