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
<a href="http://search.cpan.org/dist/Net-GlobalPOPs-MediaServicesAPI">Net::GlobalPOPs::MediaServicesAPI</a>
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
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 = ();
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'};
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)
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'),
sub _export_insert {
my( $self, $svc_phone ) = (shift, shift);
+
+ return '' if $self->option('dry_run');
+
#we want to provision and catch errors now, not queue
my $r = $self->gp_command('reserveDID',
my $rdid = $r->{did};
if ( $rdid->{'statuscode'} != 100 ) {
- return "Error running globalpop reserveDID: ".
+ return "Error running VoIP Innovations reserveDID: ".
$rdid->{'statuscode'}. ': '. $rdid->{'status'};
}
my $adid = $a->{did};
if ( $adid->{'statuscode'} != 100 ) {
- return "Error running globalpop assignDID: ".
+ return "Error running VoIP Innovations assignDID: ".
$adid->{'statuscode'}. ': '. $adid->{'status'};
}
sub _export_delete {
my( $self, $svc_phone ) = (shift, shift);
+ return '' if $self->option('dry_run');
+
#probably okay to queue the deletion...?
#but hell, let's do it inline anyway, who wants phone numbers hanging around
my $rdid = $r->{did};
if ( $rdid->{'statuscode'} != 100 ) {
- return "Error running globalpop releaseDID: ".
+ return "Error running VoIP Innovations releaseDID: ".
$rdid->{'statuscode'}. ': '. $rdid->{'status'};
}
}
#hmm, might forgo queueing entirely for most things, data is too much of a pita
-
-sub globalpops_voip_queue {
- my( $self, $svcnum, $method ) = (shift, shift, shift);
- my $queue = new FS::queue {
- 'svcnum' => $svcnum,
- 'job' => 'FS::part_export::globalpops_voip::globalpops_voip_command',
- };
- $queue->insert(
- $self->option('login'),
- $self->option('password'),
- $method,
- @_,
- );
-}
+#sub globalpops_voip_queue {
+# my( $self, $svcnum, $method ) = (shift, shift, shift);
+# my $queue = new FS::queue {
+# 'svcnum' => $svcnum,
+# 'job' => 'FS::part_export::globalpops_voip::globalpops_voip_command',
+# };
+# $queue->insert(
+# $self->option('login'),
+# $self->option('password'),
+# $method,
+# @_,
+# );
+#}
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