diff options
| author | jeff <jeff> | 2010-03-31 15:48:55 +0000 | 
|---|---|---|
| committer | jeff <jeff> | 2010-03-31 15:48:55 +0000 | 
| commit | 65f0f73df04de553919ee50145376955da20b315 (patch) | |
| tree | a2d91d05e9eb4f667619ac4094729bce0cf574a4 | |
| parent | 4ca83488cafd75e2612358672e0f416918d951cf (diff) | |
add dash carrier services e911 support RT7103
| -rw-r--r-- | FS/FS/part_export/dashcs_e911.pm | 153 | ||||
| -rw-r--r-- | FS/MANIFEST | 1 | 
2 files changed, 154 insertions, 0 deletions
| diff --git a/FS/FS/part_export/dashcs_e911.pm b/FS/FS/part_export/dashcs_e911.pm new file mode 100644 index 000000000..a0c3a6d6a --- /dev/null +++ b/FS/FS/part_export/dashcs_e911.pm @@ -0,0 +1,153 @@ +package FS::part_export::dashcs_e911; + +use strict; +use vars qw(@ISA %info $me $DEBUG); +use Tie::IxHash; +use FS::part_export; + +$DEBUG = 0; +$me = '['.__PACKAGE__.']'; + +@ISA = qw(FS::part_export); + +tie my %options, 'Tie::IxHash', +  'username'  => { label=>'Dash username', }, +  '_password' => { label=>'Dash password', }, +  'staging' => { label=>'Staging (test mode)', type=>'checkbox', }, +; + +%info = ( +  'svc'     => 'svc_phone', +  'desc'    => 'Provision e911 services via Dash Carrier Services', +  'notes'   => 'Provision e911 services via Dash Carrier Services', +  'options' => \%options, +); + +sub rebless { shift; } + +sub _export_insert { +  my($self, $svc_phone) = (shift, shift); +  return 'invalid phonenum' unless $svc_phone->phonenum; +   +  my $opts = { map{ $_ => $self->option($_) } keys %options }; +  $opts->{wantreturn} = 1; + +  my %location_hash = $svc_phone->location_hash; +  my $location = {  +    'address1'   => $location_hash{address1}, +    'address2'   => $location_hash{address2}, +    'community'  => $location_hash{city}, +    'state'      => $location_hash{state}, +    'postalcode' => $location_hash{zip}, +  }; +   +  my $error_or_ref = +   dash_command($opts, 'validateLocation', { 'location' => $location } ); +  return $error_or_ref unless ref($error_or_ref); + +  my $status = $error_or_ref->get_Location->get_status; # hate +  return $status->get_description unless $status->get_code eq 'GEOCODED'; +   +  my $cust_pkg = $svc_phone->cust_svc->cust_pkg; +  my $cust_main = $cust_pkg->cust_main if $cust_pkg; +  my $caller_name = $cust_main ? $cust_main->name_short : 'unknown'; + +  my $arg = { +    'uri' => { +               'uri' => 'tel:'. $svc_phone->countrycode. $svc_phone->phonenum, +               'callername' => $caller_name, +             }, +    'location' => $location, +  }; + +  my $error_or_ref = dash_command($opts, 'addLocation', $arg ); +  return $error_or_ref unless ref($error_or_ref); + +  my $id = $error_or_ref->get_Location->get_locationid; +  $self->_export_command('provisionLocation', { 'locationid' => $id }); +} + +sub _export_delete { +  my($self, $svc_phone) = (shift, shift); +  return '' unless $svc_phone->phonenum; +   +  my $arg = { 'uri' => 'tel:'. $svc_phone->countrycode. $svc_phone->phonenum }; +  $self->_export_queue('removeURI', $arg); +} + +sub _export_suspend { +  my($self) = shift; +  ''; +} + +sub _export_unsuspend { +  my($self) = shift; +  ''; +} + +sub _export_command { +  my $self = shift; + +  my $opts = { map{ $_ => $self->option($_) } keys %options }; + +  dash_command($opts, @_); + +} + +sub _export_replace { +  my($self, $new, $old ) = (shift, shift, shift); + +  # this could succeed in unprovision but fail to provision +  my $arg = { 'uri' => 'tel:'. $old->countrycode. $old->phonenum }; +  $self->_export_command('removeURI', $arg) || $self->_export_insert($new);   +} + +#a good idea to queue anything that could fail or take any time +sub _export_queue { +  my $self = shift; + +  my $opts = { map{ $_ => $self->option($_) } keys %options }; + +  my $queue = new FS::queue { +    'job'    => "FS::part_export::dashcs_e911::dash_command", +  }; +  $queue->insert( $opts, @_ ); +} + +sub dash_command { +  my ( $opt, $method, $arg ) = (shift, shift, shift); + +  warn "$me: dash_command called with method $method\n" if $DEBUG; + +  my @module = qw( +    Net::DashCS::Interfaces::EmergencyProvisioningService::EmergencyProvisioningPort +    SOAP::Lite +  ); + +  foreach my $module ( @module ) { +    eval "use $module;"; +    die $@ if $@; +  } + +  local *SOAP::Transport::HTTP::Client::get_basic_credentials = sub { +    return ($opt->{'username'}, $opt->{'_password'}); +  }; + +  my $service = new Net::DashCS::Interfaces::EmergencyProvisioningService::EmergencyProvisioningPort( +      { deserializer_args => { strict => 0 } } +  ); + +  $service->set_proxy('https://staging-service.dashcs.com/dash-api/soap/emergencyprovisioning/v1') +    if $opt->{'staging'}; + +  my $result = $service->$method($arg); + +  if (not $result) { +    warn "returning fault: ". $result->get_faultstring if $DEBUG; +    return ''.$result->get_faultstring; +  } + +  warn "returning ok: $result\n" if $DEBUG; +  return $result if $opt->{wantreturn}; +  ''; +} diff --git a/FS/MANIFEST b/FS/MANIFEST index 997bd7723..b3415178b 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -99,6 +99,7 @@ FS/part_export/communigate_pro.pm  FS/part_export/communigate_pro_singledomain.pm  FS/part_export/cp.pm  FS/part_export/cyrus.pm +FS/part_export/dashcs_e911.pm  FS/part_export/domain_shellcommands.pm  FS/part_export/forward_shellcommands.pm  FS/part_export/http.pm | 
