forward_sql export, RT#13247
[freeside.git] / FS / FS / part_export / netsapiens.pm
index 332edcc..285db7e 100644 (file)
@@ -1,7 +1,8 @@
 package FS::part_export::netsapiens;
 
 use vars qw(@ISA $me %info);
-use URI;
+use URI; #needed?
+use URI::Escape;
 use MIME::Base64;
 use Tie::IxHash;
 use FS::part_export;
@@ -21,7 +22,7 @@ tie my %options, 'Tie::IxHash',
 ;
 
 %info = (
-  'svc'      => 'svc_phone',
+  'svc'      => [ 'svc_phone', ], # 'part_device',
   'desc'     => 'Provision phone numbers to NetSapiens',
   'options'  => \%options,
   'notes'    => <<'END'
@@ -72,10 +73,15 @@ sub _ns_command {
   $ns;
 }
 
+sub ns_domain {
+  my($self, $svc_phone) = (shift, shift);
+  $svc_phone->domain || $self->option('domain');
+}
+
 sub ns_subscriber {
   my($self, $svc_phone) = (shift, shift);
 
-  my $domain = $self->option('domain');
+  my $domain = $self->ns_domain($svc_phone);
   my $phonenum = $svc_phone->phonenum;
 
   "/domains_config/$domain/subscriber_config/$phonenum";
@@ -85,13 +91,13 @@ sub ns_registrar {
   my($self, $svc_phone) = (shift, shift);
 
   $self->ns_subscriber($svc_phone).
-    '/registrar_config/'. $self->ns_devicename($svc_phone);
+    '/registrar_config/'. uri_escape($self->ns_devicename($svc_phone));
 }
 
 sub ns_devicename {
   my( $self, $svc_phone ) = (shift, shift);
 
-  my $domain = $self->option('domain');
+  my $domain = $self->ns_domain($svc_phone);
   #my $countrycode = $svc_phone->countrycode;
   my $phonenum    = $svc_phone->phonenum;
 
@@ -106,7 +112,7 @@ sub ns_dialplan {
   my $phonenum    = $svc_phone->phonenum;
 
   #"/dialplans/DID+Table/dialplan_config/sip:$countrycode$phonenum\@*"
-  "/dialplans/DID+Table/dialplan_config/sip:$phonenum\@*"
+  "/dialplans/DID+Table/dialplan_config/". uri_escape("sip:$phonenum\@*")
 }
 
 sub ns_device {
@@ -121,7 +127,7 @@ sub ns_device {
 sub ns_create_or_update {
   my($self, $svc_phone, $dial_policy) = (shift, shift, shift);
 
-  my $domain = $self->option('domain');
+  my $domain = $self->ns_domain($svc_phone);
   #my $countrycode = $svc_phone->countrycode;
   my $phonenum    = $svc_phone->phonenum;
 
@@ -238,11 +244,10 @@ sub _export_unsuspend {
 sub export_device_insert {
   my( $self, $svc_phone, $phone_device ) = (shift, shift, shift);
 
-  #my $domain = $self->option('domain');
+  my $domain = $self->ns_domain($svc_phone);
   my $countrycode = $svc_phone->countrycode;
   my $phonenum    = $svc_phone->phonenum;
-
-  my $device = $self->ns_devicename($svc_phone);
+  #my $device = $self->ns_devicename($svc_phone);
 
   my $ns = $self->ns_device_command(
     'PUT', $self->ns_device($svc_phone, $phone_device),
@@ -256,7 +261,7 @@ sub export_device_insert {
 
       #'notes' => 
       'server'       => 'SiPbx',
-      'domain'       => $self->option('domain'),
+      'domain'       => $domain,
 
       'brand'        => $phone_device->part_device->devicename,