diff options
author | ivan <ivan> | 2008-06-28 23:03:10 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-06-28 23:03:10 +0000 |
commit | 9c7dee35f91a386fcce14cb6c3e9d23ba3eee8af (patch) | |
tree | b21b3ca250947289caaecdeba659bc37257bf464 /FS | |
parent | a1871d3d13c1dafa93b956762c0d23728d261da7 (diff) |
get DIDs from globalpops
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Record.pm | 5 | ||||
-rw-r--r-- | FS/FS/part_export/globalpops_voip.pm | 175 | ||||
-rw-r--r-- | FS/FS/part_svc.pm | 13 |
3 files changed, 191 insertions, 2 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index cc485a8f1..cd54b849f 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -6,6 +6,7 @@ use vars qw( $AUTOLOAD @ISA @EXPORT_OK $DEBUG %virtual_fields_cache $nowarn_identical $no_update_diff ); use Exporter; use Carp qw(carp cluck croak confess); +use Scalar::Util qw( blessed ); use File::CounterFile; use Locale::Country; use DBI qw(:sql_types); @@ -665,11 +666,11 @@ sub AUTOLOAD { $field =~ s/.*://; if ( defined($value) ) { confess "errant AUTOLOAD $field for $self (arg $value)" - unless ref($self) && $self->can('setfield'); + unless blessed($self) && $self->can('setfield'); $self->setfield($field,$value); } else { confess "errant AUTOLOAD $field for $self (no args)" - unless ref($self) && $self->can('getfield'); + unless blessed($self) && $self->can('getfield'); $self->getfield($field); } } diff --git a/FS/FS/part_export/globalpops_voip.pm b/FS/FS/part_export/globalpops_voip.pm index c641e0404..13c263b9a 100644 --- a/FS/FS/part_export/globalpops_voip.pm +++ b/FS/FS/part_export/globalpops_voip.pm @@ -24,6 +24,181 @@ END sub rebless { shift; } +sub get_dids { + my $self = shift; + my %opt = ref($_[0]) ? %{$_[0]} : @_; + + my %search = (); + # 'orderby' => 'npa', #but it doesn't seem to work :/ + + if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers + %getdids = ( 'npa' => $opt{'areacode'}, + 'nxx' => $opt{'exchange'}, + ); + } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX) + %getdids = ( 'npa' => $opt{'areacode'} ); + } elsif ( $opt{'state'} ) { + %getdids = ( 'state' => $opt{'state'} ); + } + + my $dids = $self->gp_command('getDIDs', %getdids); + + #use Data::Dumper; + #warn Dumper($dids); + + my $search = $dids->{'search'}; + + #warn Dumper($search); + + if ( $search->{'statuscode'} == 302200 ) { + return []; + } elsif ( $search->{'statuscode'} != 100 ) { + die "Error running globalpop getDIDs: ". + $search->{'statuscode'}. ': '. $search->{'status'}; #die?? + } + + my @return = (); + + #my $latas = $search->{state}{lata}; + + my %latas; + if ( grep $search->{state}{lata}{$_}, qw(name rate_center) ) { + %latas = map $search->{state}{lata}{$_}, + qw(name rate_center); + } else { + %latas = %{ $search->{state}{lata} }; + } + + foreach my $lata ( keys %latas ) { + + #warn "LATA $lata"; + + #my $l = $latas{$lata}; + #$l = $l->{rate_center} if exists $l->{rate_center}; + + 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?? + } + + my $l = $lata_search->{state}{lata}{'rate_center'}; + + #use Data::Dumper; + #warn Dumper($l); + + my %rate_center; + if ( grep $l->{$_}, qw(name friendlyname) ) { + %rate_center = map $l->{$_}, + qw(name friendlyname); + } else { + %rate_center = %$l; + } + + foreach my $rate_center ( keys %rate_center ) { + + #warn "rate center $rate_center"; + + my $rc = $rate_center{$rate_center}; + $rc = $rc->{friendlyname} if exists $rc->{friendlyname}; + + my @r = (); + if ( exists($rc->{npa}) ) { + @r = ($rc); + } else { + @r = map { { 'name'=>$_, %{ $rc->{$_} } }; } keys %$rc + } + + foreach my $r (@r) { + + my @npa = (); + if ( exists($r->{npa}{name}) ) { + @npa = ($r->{npa}) + } else { + @npa = map { { 'name'=>$_, %{ $r->{npa}{$_} } } } keys %{ $r->{npa} }; + } + + foreach my $npa (@npa) { + + if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers + + #warn Dumper($npa); + + my $tn = $npa->{nxx}{tn} || $npa->{nxx}{$opt{'exchange'}}{tn}; + + my @tn = ref($tn) ? @$tn : ($tn); + #push @return, @tn; + push @return, map { + if ( /^\s*(\d{3})(\d{3})(\d{4})\s*$/ ) { + "$1-$2-$3"; + } else { + $_; + } + } + @tn; + + } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX) + + if ( $npa->{nxx}{name} ) { + @nxx = ( $npa->{nxx}{name} ); + } else { + @nxx = keys %{ $npa->{nxx} }; + } + + push @return, map { $r->{name}. ' ('. $npa->{name}. "-$_-XXXX)"; } + @nxx; + + } elsif ( $opt{'state'} ) { #and not other things, then return areacode + #my $ac = $npa->{name}; + #use Data::Dumper; + #warn Dumper($r) unless length($ac) == 3; + + push @return, $npa->{name} + unless grep { $_ eq $npa->{name} } @return; + + } else { + warn "WARNING: returning nothing for get_dids without known options"; #? + } + + } #foreach my $npa + + } #foreach my $r + + } #foreach my $rate_center + + } #foreach my $lata + + if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers + @return = sort { $a cmp $b } @return; #string comparison actually dwiw + } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX) + @return = sort { lc($a) cmp lc($b) } @return; + } elsif ( $opt{'state'} ) { #and not other things, then return areacode + #@return = sort { (split(' ', $a))[0] <=> (split(' ', $b))[0] } @return; + @return = sort { $a <=> $b } @return; + } else { + warn "WARNING: returning nothing for get_dids without known options"; #? + } + + \@return; + +} + +sub gp_command { + my( $self, $command, @args ) = @_; + + eval "use Net::GlobalPOPs::MediaServicesAPI;"; + die $@ if $@; + + my $gp = Net::GlobalPOPs::MediaServicesAPI->new( + 'login' => $self->option('login'), + 'password' => $self->option('password'), + #'debug' => $debug, + ); + + $gp->$command(@args); +} + + sub _export_insert { my( $self, $svc_phone ) = (shift, shift); #we want to provision and catch errors now, not queue diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm index 4fae457e2..580038be2 100644 --- a/FS/FS/part_svc.pm +++ b/FS/FS/part_svc.pm @@ -425,6 +425,19 @@ sub part_export_usage { grep $_->can('usage_sessions'), $self->part_export; } +=item part_export_did + +Returns a list of any exports (see L<FS::part_export>) for this service that +are capable of returing available DID (phone number) information. + +=cut + +sub part_export_did { + my $self = shift; + grep $_->can('get_dids'), $self->part_export; +} + + =item cust_svc [ PKGPART ] Returns a list of associated customer services (FS::cust_svc records). |