1 package FS::part_export::fibernetics_did;
2 use base qw( FS::part_export );
5 use vars qw( %info $DEBUG );
8 #use Locale::SubCountry;
9 #use FS::Record qw(qsearch dbh);
11 #use Net::HTTPS::Any qw( 0.10 https_get );
13 use HTTP::Request::Common;
17 tie my %options, 'Tie::IxHash',
18 'country' => { 'label' => 'Country', 'default' => 'CA', size=>2, },
23 'desc' => 'Provision phone numbers to Fibernetics web services API',
24 'options' => \%options,
28 sub rebless { shift; }
30 sub can_get_dids { 1; }
31 sub get_dids_can_tollfree { 0; };
32 sub get_dids_can_manual { 1; };
33 sub get_dids_can_edit { 1; };
34 sub get_dids_npa_select { 0; };
36 # i guess we could get em from the API, but since its returning states without
37 # availability, there's no advantage
38 # not really needed, we maintain our own list of provinces, but would
39 # help to hide the ones without availability (need to fix the selector too)
55 my %opt = ref($_[0]) ? %{$_[0]} : @_;
57 if ( $opt{'tollfree'} ) {
58 warn 'Fibernetics DID provisioning does not yet support toll-free numbers';
64 #ratecenter + state: return numbers (more structured names, npa selection)
65 #areacode + exchange: return numbers
66 #areacode: return city/ratecenter/whatever
67 #state: return areacodes
69 #region + state: return numbers (arbitrary names, no npa selection)
70 #state: return regions
72 # if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers
74 # $query_hash{'region'} = $opt{'exchange'};
76 # } elsif ( $opt{'areacode'} ) {
78 # $query_hash{'npa'} = $opt{'areacode'};
80 #if ( $opt{'state'} && $opt{'region'} ) { #return numbers
81 if ( $opt{'region'} ) { #return numbers
83 #$query_hash{'province'} = $country->full_name($opt{'state'});
84 $query_hash{'region'} = $opt{'region'}
86 } elsif ( $opt{'state'} ) { #return regions
88 #my $country = new Locale::SubCountry( $self->option('country') );
89 #$query_hash{'province'} = $country->full_name($opt{'state'});
90 $query_hash{'province'} = $opt{'state'};
91 $query_hash{'listregion'} = 1;
93 } else { #nothing passed, return states (provinces)
100 my $url = 'http://'. $self->machine. '/porta/cgi-bin/porta_query.cgi';
101 if ( keys %query_hash ) {
102 $url .= '?'. join('&', map "$_=". uri_escape($query_hash{$_}),
108 #my( $page, $response, %reply_headers) = https_get(
109 # 'host' => $self->machine,
112 my $ua = LWP::UserAgent->new;
113 #my $response = $ua->$method(
115 # 'Content-Type'=>'application/x-www-form-urlencoded'
117 my $req = HTTP::Request::Common::GET( $url );
118 my $response = $ua->request($req);
120 die $response->error_as_HTML if $response->is_error;
122 my $page = $response->content;
124 my $data = XMLin( $page );
126 warn Dumper($data) if $DEBUG;
128 # if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers
130 # [ map $_->{'number'}, @{ $data->{'item'} } ];
132 # } elsif ( $opt{'areacode'} ) {
134 # [ map $_->{'region'}, @{ $data->{'item'} } ];
136 # } elsif ( $opt{'state'} ) { #return areacodes
138 # [ map $_->{'npa'}, @{ $data->{'item'} } ];
140 #if ( $opt{'state'} && $opt{'region'} ) { #return numbers
141 if ( $opt{'region'} ) { #return numbers
143 [ map { $_ =~ /^(\d?)(\d{3})(\d{3})(\d{4})$/
144 #? ($1 ? "$1 " : ''). "$2 $3 $4"
153 } elsif ( $opt{'state'} ) { #return regions
155 #[ map $_->{'region'}, @{ $data->{'item'} } ];
156 my %regions = map { $_ => 1 } map $_->{'region'}, @{ $data->{'item'} };
157 [ sort keys %regions ];
159 #} else { #nothing passed, return states (provinces)
160 # not really needed, we maintain our own list of provinces, but would
161 # help to hide the ones without availability (need to fix the selector too)
167 #insert, delete, etc... handled with shellcommands
170 #my( $self, $svc_phone ) = (shift, shift);
173 #my( $self, $svc_phone ) = (shift, shift);
176 sub _export_replace { ''; }
177 sub _export_suspend { ''; }
178 sub _export_unsuspend { ''; }