New HTTP export for svc_acct and additional option for existing HTTP exports, RT10216
authorlevinse <levinse>
Thu, 4 Nov 2010 23:10:29 +0000 (23:10 +0000)
committerlevinse <levinse>
Thu, 4 Nov 2010 23:10:29 +0000 (23:10 +0000)
FS/FS/part_export/acct_http.pm [new file with mode: 0644]
FS/FS/part_export/http.pm

diff --git a/FS/FS/part_export/acct_http.pm b/FS/FS/part_export/acct_http.pm
new file mode 100644 (file)
index 0000000..d6b7d38
--- /dev/null
@@ -0,0 +1,41 @@
+package FS::part_export::acct_http;
+
+use vars qw( @ISA %info );
+use FS::part_export::http;
+use Tie::IxHash;
+
+@ISA = qw( FS::part_export::http );
+
+tie my %options, 'Tie::IxHash', %FS::part_export::http::options;
+
+$options{'insert_data'}->{'default'} = join("\n",
+  "action 'add'",
+  "username \$svc_x->username",
+  "password \$svc_x->_password",
+  "prismid \$cust_main->agent_custid ? \$cust_main->agent_custid : \$cust_main->custnum ",
+  "name \$cust_main->first.' '.\$cust_main->last",
+);
+$options{'delete_data'}->{'default'} = join("\n",
+  "action  'remove'",
+  "username \$svc_x->username",
+);
+$options{'replace_data'}->{'default'} = join("\n",
+  "action  'update'",
+  "username \$old->username",
+  "password \$new->_password",
+);
+
+%info = (
+  'svc'     => 'svc_acct',
+  'desc'    => 'Send an HTTP or HTTPS GET or POST request, for accounts.',
+  'options' => \%options,
+  'notes'   => <<'END'
+Send an HTTP or HTTPS GET or POST to the specified URL on account addition,
+modification and deletion.  For HTTPS support,
+<a href="http://search.cpan.org/dist/Crypt-SSLeay">Crypt::SSLeay</a>
+or <a href="http://search.cpan.org/dist/IO-Socket-SSL">IO::Socket::SSL</a>
+is required.
+END
+);
+
+1;
index e5e5a5c..3749224 100644 (file)
@@ -33,6 +33,10 @@ tie %options, 'Tie::IxHash',
     default => join("\n",
     ),
   },
     default => join("\n",
     ),
   },
+  'success_regexp' => {
+    label  => 'Success Regexp',
+    default => '',
+  },
 ;
 
 %info = (
 ;
 
 %info = (
@@ -71,6 +75,7 @@ sub _export_command {
   $self->http_queue( $svc_x->svcnum,
     $self->option('method'),
     $self->option('url'),
   $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 );
     map {
       /^\s*(\S+)\s+(.*)$/ or /()()/;
       my( $field, $value_expression ) = ( $1, $2 );
@@ -95,6 +100,7 @@ sub _export_replace {
   $self->http_queue( $new->svcnum,
     $self->option('method'),
     $self->option('url'),
   $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 );
     map {
       /^\s*(\S+)\s+(.*)$/ or /()()/;
       my( $field, $value_expression ) = ( $1, $2 );
@@ -114,7 +120,7 @@ sub http_queue {
 }
 
 sub http {
 }
 
 sub http {
-  my($method, $url, @data) = @_;
+  my($method, $url, $success_regexp, @data) = @_;
 
   $method = lc($method);
 
 
   $method = lc($method);
 
@@ -134,6 +140,11 @@ sub http {
 
   die $response->error_as_HTML if $response->is_error;
 
 
   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;
 }
 
 1;