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 get_dids_can_tollfree { 0; };
31 sub get_dids_can_manual { 1; };
32 sub get_dids_can_edit { 1; };
33 sub get_dids_npa_select { 0; };
35 # i guess we could get em from the API, but since its returning states without
36 # availability, there's no advantage
37 # not really needed, we maintain our own list of provinces, but would
38 # help to hide the ones without availability (need to fix the selector too)
54 my %opt = ref($_[0]) ? %{$_[0]} : @_;
56 if ( $opt{'tollfree'} ) {
57 warn 'Fibernetics DID provisioning does not yet support toll-free numbers';
63 #ratecenter + state: return numbers (more structured names, npa selection)
64 #areacode + exchange: return numbers
65 #areacode: return city/ratecenter/whatever
66 #state: return areacodes
68 #region + state: return numbers (arbitrary names, no npa selection)
69 #state: return regions
71 # if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers
73 # $query_hash{'region'} = $opt{'exchange'};
75 # } elsif ( $opt{'areacode'} ) {
77 # $query_hash{'npa'} = $opt{'areacode'};
79 #if ( $opt{'state'} && $opt{'region'} ) { #return numbers
80 if ( $opt{'region'} ) { #return numbers
82 #$query_hash{'province'} = $country->full_name($opt{'state'});
83 $query_hash{'region'} = $opt{'region'}
85 } elsif ( $opt{'state'} ) { #return regions
87 #my $country = new Locale::SubCountry( $self->option('country') );
88 #$query_hash{'province'} = $country->full_name($opt{'state'});
89 $query_hash{'province'} = $opt{'state'};
90 $query_hash{'listregion'} = 1;
92 } else { #nothing passed, return states (provinces)
99 my $url = 'http://'. $self->machine. '/porta/cgi-bin/porta_query.cgi';
100 if ( keys %query_hash ) {
101 $url .= '?'. join('&', map "$_=". uri_escape($query_hash{$_}),
107 #my( $page, $response, %reply_headers) = https_get(
108 # 'host' => $self->machine,
111 my $ua = LWP::UserAgent->new;
112 #my $response = $ua->$method(
114 # 'Content-Type'=>'application/x-www-form-urlencoded'
116 my $req = HTTP::Request::Common::GET( $url );
117 my $response = $ua->request($req);
119 die $response->error_as_HTML if $response->is_error;
121 my $page = $response->content;
123 my $data = XMLin( $page );
125 warn Dumper($data) if $DEBUG;
127 # if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers
129 # [ map $_->{'number'}, @{ $data->{'item'} } ];
131 # } elsif ( $opt{'areacode'} ) {
133 # [ map $_->{'region'}, @{ $data->{'item'} } ];
135 # } elsif ( $opt{'state'} ) { #return areacodes
137 # [ map $_->{'npa'}, @{ $data->{'item'} } ];
139 #if ( $opt{'state'} && $opt{'region'} ) { #return numbers
140 if ( $opt{'region'} ) { #return numbers
142 [ map { $_ =~ /^(\d?)(\d{3})(\d{3})(\d{4})$/
143 #? ($1 ? "$1 " : ''). "$2 $3 $4"
152 } elsif ( $opt{'state'} ) { #return regions
154 #[ map $_->{'region'}, @{ $data->{'item'} } ];
155 my %regions = map { $_ => 1 } map $_->{'region'}, @{ $data->{'item'} };
156 [ sort keys %regions ];
158 #} else { #nothing passed, return states (provinces)
159 # not really needed, we maintain our own list of provinces, but would
160 # help to hide the ones without availability (need to fix the selector too)
166 #insert, delete, etc... handled with shellcommands
169 #my( $self, $svc_phone ) = (shift, shift);
172 #my( $self, $svc_phone ) = (shift, shift);
175 sub _export_replace { ''; }
176 sub _export_suspend { ''; }
177 sub _export_unsuspend { ''; }