X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fglobalpops_voip.pm;h=5eee13f340d44f29b6842a0e2fcb3ec98995257d;hp=3bd5783269b49f0717328598f3f72ab6d5c641fc;hb=5372897f367498972c96f5494e142e6e11b29eb8;hpb=f9befdcb5ce8cf5dc5b9cacb6fe04ce29ed3cb80 diff --git a/FS/FS/part_export/globalpops_voip.pm b/FS/FS/part_export/globalpops_voip.pm index 3bd578326..5eee13f34 100644 --- a/FS/FS/part_export/globalpops_voip.pm +++ b/FS/FS/part_export/globalpops_voip.pm @@ -5,20 +5,22 @@ use Tie::IxHash; use FS::Record qw(qsearch dbh); use FS::part_export; use FS::phone_avail; +use Data::Dumper; @ISA = qw(FS::part_export); tie my %options, 'Tie::IxHash', - 'login' => { label=>'GlobalPOPs Media Services API login' }, - 'password' => { label=>'GlobalPOPs Media Services API password' }, - 'endpointgroup' => { label=>'GlobalPOPs endpoint group number' }, + 'login' => { label=>'VoIP Innovations API login' }, + 'password' => { label=>'VoIP Innovations API password' }, + 'endpointgroup' => { label=>'VoIP Innovations endpoint group number' }, 'dry_run' => { label=>"Test mode - don't actually provision" }, ; %info = ( 'svc' => 'svc_phone', - 'desc' => 'Provision phone numbers to GlobalPOPs VoIP', + 'desc' => 'Provision phone numbers to VoIP Innovations (formerly GlobalPOPs VoIP)', 'options' => \%options, + 'no_machine' => 1, 'notes' => <<'END' Requires installation of Net::GlobalPOPs::MediaServicesAPI @@ -28,11 +30,13 @@ END sub rebless { shift; } +sub can_get_dids { 1; } + sub get_dids { my $self = shift; my %opt = ref($_[0]) ? %{$_[0]} : @_; - my %search = (); + my %getdids = (); # 'orderby' => 'npa', #but it doesn't seem to work :/ if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers @@ -61,16 +65,27 @@ sub get_dids { my $dids = $self->gp_command('getDIDs', %getdids); - #use Data::Dumper; - #warn Dumper($dids); + if ( $dids->{'type'} eq 'Error' ) { + my $error = "Error running VoIP Innovations getDIDs: ". + $dids->{'statuscode'}. ': '. $dids->{'status'}. "\n"; + warn $error; + die $error; + } my $search = $dids->{'search'}; if ( $search->{'statuscode'} == 302200 ) { return []; } elsif ( $search->{'statuscode'} != 100 ) { - die "Error running globalpop getDIDs: ". - $search->{'statuscode'}. ': '. $search->{'status'}; #die?? + + my $error = "Error running VoIP Innovations getDIDs: "; + if ( $search->{'statuscode'} || $search->{'status'} ) { + $error .= $search->{'statuscode'}. ': '. $search->{'status'}. "\n"; + } else { + $error .= Dumper($search); + } + warn $error; + die $error; } my @return = (); @@ -94,7 +109,7 @@ sub get_dids { my $lata_dids = $self->gp_command('getDIDs', %getdids, 'lata'=>$lata); my $lata_search = $lata_dids->{'search'}; unless ( $lata_search->{'statuscode'} == 100 ) { - die "Error running globalpop getDIDs: ". $lata_search->{'status'}; #die?? + die "Error running VoIP Innovations getDIDs: ". $lata_search->{'status'}; #die?? } my $l = $lata_search->{state}{lata}{'rate_center'}; @@ -141,16 +156,18 @@ sub get_dids { my $tn = $npa->{nxx}{tn} || $npa->{nxx}{$opt{'exchange'}}{tn}; - my @tn = ref($tn) ? @$tn : ($tn); + my @tn = ref($tn) eq 'ARRAY' ? @$tn : ($tn); #push @return, @tn; - push @return, map { - if ( /^\s*(\d{3})(\d{3})(\d{4})\s*$/ ) { - "$1-$2-$3"; - } else { - $_; - } - } - @tn; + push @return, + map { + if ( /^\s*(\d{3})(\d{3})(\d{4})\s*$/ ) { + "$1-$2-$3"; + } else { + $_; + } + } + map { ref($_) eq 'HASH' ? $_->{'content'} : $_ } #tier always 2? + @tn; } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX) @@ -239,8 +256,11 @@ sub get_dids { sub gp_command { my( $self, $command, @args ) = @_; - eval "use Net::GlobalPOPs::MediaServicesAPI;"; - die $@ if $@; + eval "use Net::GlobalPOPs::MediaServicesAPI 0.03;"; + if ( $@ ) { + warn $@; + die $@; + } my $gp = Net::GlobalPOPs::MediaServicesAPI->new( 'login' => $self->option('login'), @@ -268,7 +288,7 @@ sub _export_insert { my $rdid = $r->{did}; if ( $rdid->{'statuscode'} != 100 ) { - return "Error running globalpop reserveDID: ". + return "Error running VoIP Innovations reserveDID: ". $rdid->{'statuscode'}. ': '. $rdid->{'status'}; } @@ -282,7 +302,7 @@ sub _export_insert { my $adid = $a->{did}; if ( $adid->{'statuscode'} != 100 ) { - return "Error running globalpop assignDID: ". + return "Error running VoIP Innovations assignDID: ". $adid->{'statuscode'}. ': '. $adid->{'status'}; } @@ -311,7 +331,7 @@ sub _export_delete { my $rdid = $r->{did}; if ( $rdid->{'statuscode'} != 100 ) { - return "Error running globalpop releaseDID: ". + return "Error running VoIP Innovations releaseDID: ". $rdid->{'statuscode'}. ': '. $rdid->{'status'}; } @@ -348,7 +368,7 @@ sub _export_unsuspend { sub globalpops_voip_command { my($login, $password, $method, @args) = @_; - eval "use Net::GlobalPOPs::MediaServicesAPI;"; + eval "use Net::GlobalPOPs::MediaServicesAPI 0.03;"; die $@ if $@; my $gp = new Net::GlobalPOPs