summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-03-28 17:36:25 -0700
committerMark Wells <mark@freeside.biz>2016-03-28 17:59:20 -0700
commit75159fa6df40171b78d19c1edaeb15d815b0b68b (patch)
treeae8acfc896bec564f228a2df759b385ec67b569d /FS/FS
parent6e2d51d0825c6dbb92fe7fb4c4e15868fdd6b611 (diff)
slightly better error reporting for DID selector, from #39914
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/part_export.pm2
-rw-r--r--FS/FS/part_export/bandwidth_com.pm45
-rw-r--r--FS/FS/part_export/test.pm78
3 files changed, 104 insertions, 21 deletions
diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm
index 21feee41d..0bffa0c4f 100644
--- a/FS/FS/part_export.pm
+++ b/FS/FS/part_export.pm
@@ -728,6 +728,8 @@ will return an array of actual DID numbers.
Passing 'tollfree' with a true value will override the whole hierarchy and
return an array of tollfree numbers.
+C<get_dids> methods should report errors via die().
+
=cut
# no stub; can('get_dids') should return false by default
diff --git a/FS/FS/part_export/bandwidth_com.pm b/FS/FS/part_export/bandwidth_com.pm
index 6c69fe356..4fbc2de21 100644
--- a/FS/FS/part_export/bandwidth_com.pm
+++ b/FS/FS/part_export/bandwidth_com.pm
@@ -151,43 +151,46 @@ sub can_get_dids { 1 }
sub get_dids_npa_select { 1 }
sub get_dids {
- local $SIG{__DIE__};
my $self = shift;
my %opt = @_;
my ($exportnum) = $self->exportnum =~ /^(\d+)$/;
- return [] if $opt{'tollfree'}; # we'll come back to this
+ try {
+ return [] if $opt{'tollfree'}; # we'll come back to this
- my ($state, $npa, $nxx) = @opt{'state', 'areacode', 'exchange'};
+ my ($state, $npa, $nxx) = @opt{'state', 'areacode', 'exchange'};
- if ( $nxx ) {
+ if ( $nxx ) {
- die "areacode required\n" unless $npa;
- my $limit = $self->option('num_dids') || 20;
- my $result = $self->api_get('availableNumbers', [
- 'npaNxx' => $npa.$nxx,
- 'quantity' => $limit,
- 'LCA' => 'false',
- # find only those that match the NPA-NXX, not those thought to be in
- # the same local calling area. though that might be useful.
- ]);
- return [ $result->findnodes('//TelephoneNumber')->to_literal_list ];
+ die "areacode required\n" unless $npa;
+ my $limit = $self->option('num_dids') || 20;
+ my $result = $self->api_get('availableNumbers', [
+ 'npaNxx' => $npa.$nxx,
+ 'quantity' => $limit,
+ 'LCA' => 'false',
+ # find only those that match the NPA-NXX, not those thought to be in
+ # the same local calling area. though that might be useful.
+ ]);
+ return [ $result->findnodes('//TelephoneNumber')->to_literal_list ];
- } elsif ( $npa ) {
+ } elsif ( $npa ) {
- return $self->npanxx_cache($npa);
+ return $self->npanxx_cache($npa);
- } elsif ( $state ) {
+ } elsif ( $state ) {
- return $self->npa_cache($state);
+ return $self->npa_cache($state);
- } else { # something's wrong
+ } else { # something's wrong
- warn "get_dids called with no arguments";
- return [];
+ warn "get_dids called with no arguments";
+ return [];
+ }
+ } catch {
+ die "$me $_\n";
}
}
diff --git a/FS/FS/part_export/test.pm b/FS/FS/part_export/test.pm
index 126897c0b..392fc4feb 100644
--- a/FS/FS/part_export/test.pm
+++ b/FS/FS/part_export/test.pm
@@ -18,6 +18,7 @@ tie %options, 'Tie::IxHash',
'replace' => { label => 'Replace',type => 'checkbox', default => 1, },
'suspend' => { label => 'Suspend',type => 'checkbox', default => 1, },
'unsuspend'=>{ label => 'Unsuspend', type => 'checkbox', default => 1, },
+ 'get_dids_npa_select' => { label => 'DIDs by NPA', type => 'checkbox' },
;
%info = (
@@ -31,6 +32,8 @@ or always dies, according to the "Result" option. It does nothing else; the
purpose is purely to simulate success or failure within an export module.</P>
<P>The checkbox options can be used to turn the export off for certain
actions, if this is needed.</P>
+<P>This export will produce a small set of DIDs, in either Alabama (if the
+"DIDs by NPA" option is on) or California (if not).</P>
END
);
@@ -72,4 +75,79 @@ sub run {
}
}
+sub can_get_dids { 1 }
+
+sub get_dids_npa_select {
+ my $self = shift;
+ $self->option('get_dids_npa_select') ? 1 : 0;
+}
+
+# we don't yet have tollfree
+
+my $dids_by_npa = {
+ 'states' => [ 'AK', 'AL' ],
+ # states
+ 'AK' => [],
+ 'AL' => [ '205', '998', '999' ],
+ # NPAs
+ '205' => [ 'ALABASTER (205-555-XXXX)', # an NPA-NXX
+ 'EMPTY (205-998-XXXX)',
+ 'INVALID (205-999-XXXX)',
+ 'ALBERTVILLE, AL', # a ratecenter
+ ],
+ '998' => [],
+ '999' => undef,
+ # exchanges
+ '205555' =>
+ [
+ '2055550101',
+ '2055550102'
+ ],
+ '205998' => [],
+ '205999' => undef,
+ # ratecenters
+ 'ALBERTVILLE' => [
+ '2055550111',
+ '2055550112',
+ ],
+},
+
+my $dids_by_region = {
+ 'states' => [ 'CA', 'CO' ],
+ 'CA' => [ 'CALIFORNIA',
+ 'EMPTY',
+ 'INVALID'
+ ],
+ 'CO' => [],
+ # regions
+ 'CALIFORNIA' => [
+ '4155550200',
+ '4155550201',
+ ],
+ 'EMPTY' => [],
+ 'INVALID' => undef,
+};
+
+sub get_dids {
+ my $self = shift;
+ my %opt = @_;
+ my $data = $self->get_dids_npa_select ? $dids_by_npa : $dids_by_region;
+
+ my $key;
+ if ( $opt{'exchange'} ) {
+ $key = $opt{'areacode'} . $opt{'exchange'};
+ } else {
+ $key = $opt{'ratecenter'}
+ || $opt{'areacode'}
+ || $opt{'region'}
+ || $opt{'state'}
+ || 'states';
+ }
+ if ( defined $data->{ $key } ) {
+ return $data->{ $key };
+ } else {
+ die "[test] '$key' is invalid\n";
+ }
+}
+
1;