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_npa_select { 0; };
33 # i guess we could get em from the API, but since its returning states without
34 # availability, there's no advantage
35 # not really needed, we maintain our own list of provinces, but would
36 # help to hide the ones without availability (need to fix the selector too)
52 my %opt = ref($_[0]) ? %{$_[0]} : @_;
54 if ( $opt{'tollfree'} ) {
55 warn 'Fibernetics DID provisioning does not yet support toll-free numbers';
61 #ratecenter + state: return numbers (more structured names, npa selection)
62 #areacode + exchange: return numbers
63 #areacode: return city/ratecenter/whatever
64 #state: return areacodes
66 #region + state: return numbers (arbitrary names, no npa selection)
67 #state: return regions
69 # if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers
71 # $query_hash{'region'} = $opt{'exchange'};
73 # } elsif ( $opt{'areacode'} ) {
75 # $query_hash{'npa'} = $opt{'areacode'};
77 #if ( $opt{'state'} && $opt{'region'} ) { #return numbers
78 if ( $opt{'region'} ) { #return numbers
80 #$query_hash{'province'} = $country->full_name($opt{'state'});
81 $query_hash{'region'} = $opt{'region'}
83 } elsif ( $opt{'state'} ) { #return regions
85 #my $country = new Locale::SubCountry( $self->option('country') );
86 #$query_hash{'province'} = $country->full_name($opt{'state'});
87 $query_hash{'province'} = $opt{'state'};
88 $query_hash{'listregion'} = 1;
90 } else { #nothing passed, return states (provinces)
97 my $url = 'http://'. $self->machine. '/porta/cgi-bin/porta_query.cgi';
98 if ( keys %query_hash ) {
99 $url .= '?'. join('&', map "$_=". uri_escape($query_hash{$_}),
105 #my( $page, $response, %reply_headers) = https_get(
106 # 'host' => $self->machine,
109 my $ua = LWP::UserAgent->new;
110 #my $response = $ua->$method(
112 # 'Content-Type'=>'application/x-www-form-urlencoded'
114 my $req = HTTP::Request::Common::GET( $url );
115 my $response = $ua->request($req);
117 die $response->error_as_HTML if $response->is_error;
119 my $page = $response->content;
121 my $data = XMLin( $page );
123 warn Dumper($data) if $DEBUG;
125 # if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers
127 # [ map $_->{'number'}, @{ $data->{'item'} } ];
129 # } elsif ( $opt{'areacode'} ) {
131 # [ map $_->{'region'}, @{ $data->{'item'} } ];
133 # } elsif ( $opt{'state'} ) { #return areacodes
135 # [ map $_->{'npa'}, @{ $data->{'item'} } ];
137 #if ( $opt{'state'} && $opt{'region'} ) { #return numbers
138 if ( $opt{'region'} ) { #return numbers
140 [ map { $_ =~ /^(\d?)(\d{3})(\d{3})(\d{4})$/
141 #? ($1 ? "$1 " : ''). "$2 $3 $4"
150 } elsif ( $opt{'state'} ) { #return regions
152 #[ map $_->{'region'}, @{ $data->{'item'} } ];
153 my %regions = map { $_ => 1 } map $_->{'region'}, @{ $data->{'item'} };
154 [ sort keys %regions ];
156 #} else { #nothing passed, return states (provinces)
157 # not really needed, we maintain our own list of provinces, but would
158 # help to hide the ones without availability (need to fix the selector too)
164 #insert, delete, etc... handled with shellcommands
167 #my( $self, $svc_phone ) = (shift, shift);
170 #my( $self, $svc_phone ) = (shift, shift);
173 sub _export_replace { ''; }
174 sub _export_suspend { ''; }
175 sub _export_unsuspend { ''; }