[freeside-commits] freeside/FS/FS/part_export thirdlane.pm, 1.1, 1.2

Ivan,,, ivan at wavetail.420.am
Mon Jan 25 23:15:38 PST 2010


Update of /home/cvs/cvsroot/freeside/FS/FS/part_export
In directory wavetail.420.am:/tmp/cvs-serv743/FS/FS/part_export

Modified Files:
	thirdlane.pm 
Log Message:
figured out success/failure reporting, and wrote DID creation/deletion/assign/unassign, RT#7051

Index: thirdlane.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/thirdlane.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- thirdlane.pm	26 Jan 2010 06:15:34 -0000	1.1
+++ thirdlane.pm	26 Jan 2010 07:15:36 -0000	1.2
@@ -55,16 +55,32 @@
                                             \@what_to_clone,
                                           );
 
-    use Data::Dumper;
-    warn Dumper(\$result);
+    #use Data::Dumper;
+    #warn Dumper(\$result);
+    $result eq '0' ? '' : 'Thirdlane API failure';
 
-    #$result == 0 means okay??
+  } elsif ( $svc_x->isa('FS::svc_phone') ) {
 
-    #$error;
+    my $result = $self->_thirdlane_command(
+      'asterisk::rpc_did_create',
+      $svc_x->countrycode. $svc_x->phonenum,
+    );
 
-    '';
+    #use Data::Dumper;
+    #warn Dumper(\$result);
+    $result eq '0' or return 'Thirdlane API failure (rpc_did_create)';
 
-  } elsif ( $svc_x->isa('FS::svc_phone') ) {
+    return '' unless $svc_x->pbxsvc;
+
+    $result = $self->_thirdlane_command(
+      'asterisk::rpc_did_assign',
+      $svc_x->countrycode. $svc_x->phonenum,
+      $svc_x->pbx_title,
+    );
+
+    #use Data::Dumper;
+    #warn Dumper(\$result);
+    $result eq '0' ? '' : 'Thirdlane API failure (rpc_did_assign)';
 
   } else {
     die "guru meditation #10: $svc_x is not FS::svc_pbx or FS::svc_phone";
@@ -72,57 +88,105 @@
 
 }
 
-sub _export_insert {
-  my($self, $svc_x) = (shift, shift);
+sub _export_replace {
+  my($self, $new, $old) = (shift, shift, shift);
 
-  if ( $svc_x->isa('FS::svc_pbx') ) {
+#  #return "can't change username with thirdlane"
+#  #  if $old->username ne $new->username;
+#  #return '' unless $old->_password ne $new->_password;
+#  $err_or_queue = $self->thirdlane_queue( $new->svcnum,
+#    'replace', $new->username, $new->_password );
+#  ref($err_or_queue) ? '' : $err_or_queue;
 
-    my $result = $self->_thirdlane_command( 'asterisk::rpc_tenant_delete',
-                                            $svc_x->title,
+  if ( $new->isa('FS::svc_pbx') ) {
+
+    #need more info on how the API works for changing names.. can it?
+    return "can't change PBX name with thirdlane (yet?)"
+      if $old->title ne $new->title;
+
+    my $tenant = {
+      'tenant'   => $old->title,
+      'maxusers' => $new->max_extensions,
+      #others?  will they not clone?
+    };
+
+    my $result = $self->_thirdlane_command( 'asterisk::rpc_tenant_update',
+                                            $tenant
                                           );
 
-    use Data::Dumper;
-    warn Dumper(\$result);
+    #use Data::Dumper;
+    #warn Dumper(\$result);
+    $result eq '0' ? '' : 'Thirdlane API failure';
 
-    #$result == 0 means okay??
+  } elsif ( $new->isa('FS::svc_phone') ) {
 
-    #$error;
+    return "can't change DID countrycode with thirdlane"
+      if $old->countrycode ne $new->countrycode;
+    return "can't change DID number with thirdlane"
+      if $old->phonenum ne $new->phonenum;
 
-    '';
+    if ( $old->pbxsvc != $new->pbxsvc ) {
 
-  } elsif ( $svc_x->isa('FS::svc_phone') ) {
+      if ( $old->pbxsvc ) {
+        my $result = $self->_thirdlane_command(
+          'asterisk::rpc_did_unassign',
+          $new->countrycode. $new->phonenum,
+        );
+        $result eq '0' or return 'Thirdlane API failure (rpc_did_unassign)';
+      }
+
+      if ( $new->pbxsvc ) {
+        my $result = $self->_thirdlane_command(
+          'asterisk::rpc_did_assign',
+          $new->countrycode. $new->phonenum,
+          $new->pbx_title,
+        );
+        $result eq '0' or return 'Thirdlane API failure (rpc_did_assign)';
+      }
+
+
+    }
+
+    '';
 
   } else {
-    die "guru meditation #11: $svc_x is not FS::svc_pbx or FS::svc_phone";
+    die "guru meditation #11: $new is not FS::svc_pbx or FS::svc_phone";
   }
 
 }
 
-sub _export_replace {
+sub _export_delete {
   my($self, $svc_x) = (shift, shift);
+  #my( $self, $svc_something ) = (shift, shift);
+  #$err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
+  #  'delete', $svc_something->username );
+  #ref($err_or_queue) ? '' : $err_or_queue;
 
   if ( $svc_x->isa('FS::svc_pbx') ) {
 
-    my $tenant = {
-      'tenant'   => $svc_x->title,
-      'maxusers' => $svc_x->max_extensions,
-      #others?  will they not clone?
-    };
-
-    my $result = $self->_thirdlane_command( 'asterisk::rpc_tenant_update',
-                                            $tenant
+    my $result = $self->_thirdlane_command( 'asterisk::rpc_tenant_delete',
+                                            $svc_x->title,
                                           );
 
-    use Data::Dumper;
-    warn Dumper(\$result);
-
-    #$result == 0 means okay??
+    #use Data::Dumper;
+    #warn Dumper(\$result);
+    $result eq '0' ? '' : 'Thirdlane API failure';
 
-    #$error;
+  } elsif ( $svc_x->isa('FS::svc_phone') ) {
 
-    '';
+    if ( $svc_x->pbxsvc ) {
+      my $result = $self->_thirdlane_command(
+        'asterisk::rpc_did_unassign',
+        $svc_x->countrycode. $svc_x->phonenum,
+      );
+      $result eq '0' or return 'Thirdlane API failure (rpc_did_unassign)';
+    }
 
-  } elsif ( $svc_x->isa('FS::svc_phone') ) {
+    my $result = $self->_thirdlane_command(
+      'asterisk::rpc_did_delete',
+      $svc_x->countrycode. $svc_x->phonenum,
+    );
+    $result eq '0' ? '' : 'Thirdlane API failure (rpc_did_delete)';
 
   } else {
     die "guru meditation #11: $svc_x is not FS::svc_pbx or FS::svc_phone";
@@ -130,7 +194,6 @@
 
 }
 
-
 sub _thirdlane_command {
   my($self, @param) = @_;
 
@@ -150,46 +213,33 @@
   
 }
 
-sub _export_replace {
-  my( $self, $new, $old ) = (shift, shift, shift);
-  #return "can't change username with thirdlane"
-  #  if $old->username ne $new->username;
-  #return '' unless $old->_password ne $new->_password;
-  $err_or_queue = $self->thirdlane_queue( $new->svcnum,
-    'replace', $new->username, $new->_password );
-  ref($err_or_queue) ? '' : $err_or_queue;
-}
-
-sub _export_delete {
-  '';
   #my( $self, $svc_something ) = (shift, shift);
   #$err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
   #  'delete', $svc_something->username );
   #ref($err_or_queue) ? '' : $err_or_queue;
-}
 
 #these three are optional
-# fallback for svc_acct will change and restore password
-sub _export_suspend {
-  my( $self, $svc_something ) = (shift, shift);
-  $err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
-    'suspend', $svc_something->username );
-  ref($err_or_queue) ? '' : $err_or_queue;
-}
-
-sub _export_unsuspend {
-  my( $self, $svc_something ) = (shift, shift);
-  $err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
-    'unsuspend', $svc_something->username );
-  ref($err_or_queue) ? '' : $err_or_queue;
-}
-
-sub export_links {
-  my($self, $svc_something, $arrayref) = (shift, shift, shift);
-  #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_something->username.
-  #                 qq!">!. $svc_something->username. qq!</A>!;
-  '';
-}
+## fallback for svc_acct will change and restore password
+#sub _export_suspend {
+#  my( $self, $svc_something ) = (shift, shift);
+#  $err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
+#    'suspend', $svc_something->username );
+#  ref($err_or_queue) ? '' : $err_or_queue;
+#}
+#
+#sub _export_unsuspend {
+#  my( $self, $svc_something ) = (shift, shift);
+#  $err_or_queue = $self->thirdlane_queue( $svc_something->svcnum,
+#    'unsuspend', $svc_something->username );
+#  ref($err_or_queue) ? '' : $err_or_queue;
+#}
+#
+#sub export_links {
+#  my($self, $svc_something, $arrayref) = (shift, shift, shift);
+#  #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_something->username.
+#  #                 qq!">!. $svc_something->username. qq!</A>!;
+#  '';
+#}
 
 ####
 #



More information about the freeside-commits mailing list