export host selection per service, RT#17914
[freeside.git] / FS / FS / part_export / http.pm
index 9a216c1..c35c89f 100644 (file)
@@ -33,12 +33,17 @@ tie %options, 'Tie::IxHash',
     default => join("\n",
     ),
   },
+  'success_regexp' => {
+    label  => 'Success Regexp',
+    default => '',
+  },
 ;
 
 %info = (
   'svc'     => 'svc_domain',
   'desc'    => 'Send an HTTP or HTTPS GET or POST request',
   'options' => \%options,
+  'no_machine' => 1,
   'notes'   => <<'END'
 Send an HTTP or HTTPS GET or POST to the specified URL.  For HTTPS support,
 <a href="http://search.cpan.org/dist/Crypt-SSLeay">Crypt::SSLeay</a>
@@ -71,6 +76,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 );
@@ -90,13 +96,16 @@ sub _export_replace {
   my $new_cust_main = $new->table eq 'cust_main'
                         ? $new
                         : $new->cust_svc->cust_pkg->cust_main;
+  my $cust_main = $new_cust_main; #so folks can use $new_cust_main or $cust_main
 
-  $self->http_queue( $svc_x->svcnum,
+  $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 );
+      my $value = eval $value_expression;
       die $@ if $@;
       ( $field, $value );
     } split(/\n/, $self->option('replace_data') )
@@ -112,7 +121,7 @@ sub http_queue {
 }
 
 sub http {
-  my($method, $url, @data) = @_;
+  my($method, $url, $success_regexp, @data) = @_;
 
   $method = lc($method);
 
@@ -132,6 +141,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;