summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/part_export/thirdlane.pm188
1 files changed, 119 insertions, 69 deletions
diff --git a/FS/FS/part_export/thirdlane.pm b/FS/FS/part_export/thirdlane.pm
index 7b1d706d5..cbcf98a26 100644
--- a/FS/FS/part_export/thirdlane.pm
+++ b/FS/FS/part_export/thirdlane.pm
@@ -55,16 +55,32 @@ sub _export_insert {
\@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 {
}
-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 _export_replace {
}
-
sub _thirdlane_command {
my($self, @param) = @_;
@@ -150,46 +213,33 @@ sub _thirdlane_command {
}
-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>!;
+# '';
+#}
####
#