1 package FS::part_export::netsapiens;
3 use vars qw(@ISA %info);
9 @ISA = qw(FS::part_export);
11 tie my %options, 'Tie::IxHash',
12 'login' => { label=>'NetSapiens tac2 API username' },
13 'password' => { label=>'NetSapiens tac2 API password' },
14 'url' => { label=>'NetSapiens tac2 URL' },
15 'domain' => { label=>'NetSapiens Domain' },
20 'desc' => 'Provision phone numbers to NetSapiens',
21 'options' => \%options,
23 Requires installation of
24 <a href="http://search.cpan.org/dist/REST-Client">REST::Client</a>
29 sub rebless { shift; }
32 my( $self, $method, $command, @args ) = @_;
34 eval 'use REST::Client';
37 my $ns = new REST::Client 'host'=>$self->option('url');
39 my $content = $method eq 'PUT' ? $ns->buildQuery( { @args } ) : '';
45 encode_base64( $self->option('login'). ':'. $self->option('password') );
47 $ns->$method( $command, $content, { 'Authorization' => "Basic $auth" } );
53 my($self, $svc_phone) = (shift, shift);
55 my $domain = $self->option('domain');
56 my $phonenum = $svc_phone->phonenum;
58 "/domains_config/$domain/subscriber_config/$phonenum";
61 sub ns_create_or_update {
62 my($self, $svc_phone, $dial_policy) = (shift, shift, shift);
64 my $domain = $self->option('domain');
65 my $phonenum = $svc_phone->phonenum;
67 my( $firstname, $lastname );
68 if ( $svc_phone->phone_name =~ /^\s*(\S+)\s+(\S.*\S)\s*$/ ) {
72 #deal w/unaudited netsapiens services?
73 my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main;
74 $firstname = $cust_main->get('first');
75 $lastname = $cust_main->get('last');
78 my $ns = $self->ns_command( 'PUT', $self->ns_subscriber($svc_phone),
79 'subscriber_login' => $phonenum.'@'.$domain,
80 'firstname' => $firstname, #4?
81 'lastname' => $lastname, #5?
82 'subscriber_pin' => $svc_phone->pin, #6?
83 'dial_plan' => 'Default', #config? #7?
84 'dial_policy' => $dial_policy, #8?
86 # simultaneous_ringyes
93 # last_update2008-10-01 12:19:01.0
102 # date_created2008-02-22 08:38:01
105 # directory_listingno
106 # time_zoneUS/Pacific
107 # forward_no_answeryes
110 # subscriber_groupn/a
118 # subscriber_login1007@vbox.netsapiens.com
126 if ( $ns->responseCode !~ /^2/ ) {
127 return $ns->responseCode. ' '.
128 join(', ', $self->ns_parse_response( $ns->responseContent ) );
135 my($self, $svc_phone) = (shift, shift);
137 my $ns = $self->ns_command( 'DELETE', $self->ns_subscriber($svc_phone) );
139 if ( $ns->responseCode !~ /^2/ ) {
140 return $ns->responseCode. ' '.
141 join(', ', $self->ns_parse_response( $ns->responseContent ) );
148 sub ns_parse_response {
149 my( $self, $content ) = ( shift, shift );
151 tie my %hash, Tie::IxHash;
152 #while ( $content =~ s/^.*?<p>\s*<b>(.+?)<\/b>\s*<(\w+)>(.+?)<\/\2><\/p>//i ) {
153 while ( $content =~ s/^.*?<p>\s*<b>(.+?)<\/b>\s*(.+?)\s*<\/p>//is ) {
154 ( $hash{$1} = $2 ) =~ s/^\s*<(\w+)>(.+?)<\/\1>/$2/is;
157 #warn $content; #probably useless
163 my($self, $svc_phone) = (shift, shift);
164 $self->ns_create_or_update($svc_phone, 'Permit All');
167 sub _export_replace {
168 my( $self, $new, $old ) = (shift, shift, shift);
169 return "can't change phonenum with NetSapiens (unprovision and reprovision?)"
170 if $old->phonenum ne $new->phonenum;
171 $self->_export_insert($new);
175 my( $self, $svc_phone ) = (shift, shift);
177 $self->ns_delete($svc_phone);
180 sub _export_suspend {
181 my( $self, $svc_phone ) = (shift, shift);
182 $self->ns_create_or_udpate($svc_phone, 'Deny');
185 sub _export_unsuspend {
186 my( $self, $svc_phone ) = (shift, shift);
187 #$self->ns_create_or_update($svc_phone, 'Permit All');
188 $self->_export_insert($svc_phone);
192 my($self, $svc_phone, $arrayref) = (shift, shift, shift);
193 #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_phone->username.
194 # qq!">!. $svc_phone->username. qq!</A>!;