desc
[Net-VoIP_Innovations.git] / lib / Net / VoIP_Innovations.pm
index bd56c8b..288ac15 100644 (file)
@@ -3,37 +3,36 @@ package Net::VoIP_Innovations;
 use warnings;
 use strict;
 use Data::Dumper;
-use XML::Simple;
-use XML::Writer;
-use Net::HTTPS::Any qw( 0.10 https_post );
+use SOAP::Lite;
+#SOAP::Lite->import(+trace=>'debug');
 
 =head1 NAME
 
-Net::VoIP_Innovations - Interface to VoIP_Innovations API
+Net::VoIP_Innovations - Interface to VoIP Innovations API
 
 =cut
 
-our $VERSION = '2.00';
-our $URL     = 'https://www.loginto.us/VOIP/api2.pl';
-#could be parsed from URL, if it mattered...
-our $HOST    = 'www.loginto.us';
-our $PATH    = '/VOIP/api2.pl';
-our $PORT    = 443; #to allow testing to override
+our $VERSION = '3.00_01';
+our $URI     = 'http://dev.voipinnovations.com/VOIP/Services/APIService.asmx';
+our $NS      = 'http://tempuri.org'; #nice one
 
 our $AUTOLOAD;
 our $errstr = '';
 
 =head1 SYNOPSIS
 
-    use Net::VoIP_Innovations;
+    use Net::VoIP_Innovations 3;
 
-    my $handle = Net::VoIP_Innovations->new(
+    my $voip_innovations = Net::VoIP_Innovations->new(
         'login'    => 'tofu',
-        'password' => 'beast',
-        'debug'    => 1,
+        'password' => 'beast', #secret
     );
 
-    #DID functions
+
+    ##
+    # DID functions
+    ##
+
     #auditDIDs
     #queryDID
     #reserveDID
@@ -41,9 +40,53 @@ our $errstr = '';
     #configDID
     #releaseDID
 
-    #911 Functions
 
-    #Locator Functions
+    ###
+    # 911 Functions
+    ###
+
+    #insert911
+    my $response = $voip_innovations->insert911(
+      'did'        => '4155551212',
+      'address1'   => '1234 Test Lane',
+      'address2'   => '',
+      'city'       => 'Testington',
+      'state'      => 'CA',
+      'zip'        => '95454',
+      'plusFour'   => '',
+      'callerName' => 'Joe Caller',
+    );
+    if ( $response->{'responseCode'} != 100 ) {
+      die $response->{'responseMessage'};
+    }
+
+    #update911
+    my $response = $voip_innovations->update911(
+      'did'        => '4155551212',
+      'address1'   => '1234 Test Lane',
+      'address2'   => '',
+      'city'       => 'Testington',
+      'state'      => 'CA',
+      'zip'        => '95454',
+      'plusFour'   => '',
+      'callerName' => 'Joe Caller',
+    );
+    if ( $response->{'responseCode'} != 100 ) {
+      die $response->{'responseMessage'};
+    }
+
+    #remove911
+    my $response = $voip_innovations->remove911(
+      'did'        => '4155551212',
+    );
+    if ( $response->{'responseCode'} != 100 ) {
+      die $response->{'responseMessage'};
+    }
+
+
+    ###
+    # Locator Functions
+    ###
 
     ...
 
@@ -58,9 +101,7 @@ as a hash reference or a flat list of names and values.
 
 =item login (required)
 
-=item password (required)
-
-=item login (required)
+=item password (secret) (required)
 
 =back
 
@@ -74,7 +115,6 @@ sub new {
   my $proto = shift;
   my $class = ref($proto) || $proto;
   my $self = ref($_[0]) ? shift : { @_ };
-  $self->{'debug'} ||= 0;
   bless($self, $class);
 }
 
@@ -101,86 +141,18 @@ sub AUTOLOAD {
   $AUTOLOAD =~ /(^|::)(\w+)$/ or die "unparsable AUTOLOAD: $AUTOLOAD";
   my $function = $2;
 
-  my $output;
-  my $w = new XML::Writer(OUTPUT => \$output, DATA_MODE => 1, DATA_INDENT => 3);
-
-  $w->xmlDecl('ISO-8859-1');
-  $w->doctype('request', undef, $URL);
-
-  $w->startTag('request', 'id' => '');  #XXX request ID???
-    $w->startTag('header');
-      $w->startTag('sender');
-
-        if ( $self->{'sessionid'} ) {
-
-          #$w->dataElement( 'login'     => ''                   );
-          #$w->dataElement( 'password'  => ''                   );
-          $w->dataElement( 'sessionid' => $self->{'sessionid'} );
-
-        } else {
-
-          $w->dataElement( 'login'     => $self->{'login'}     );
-          $w->dataElement( 'password'  => $self->{'password'}  );
-          #$w->dataElement( 'sessionid' => ''                   );
-
-        }
-
-      $w->endTag('sender');
-    $w->endTag('header');
+  $opts->{'login'}  ||= $self->{'login'};
+  $opts->{'secret'} ||= $self->{'password'};
+  my @soap_opts = map { SOAP::Data->name($_)->value( $opts->{$_} ) }
+                    keys %$opts;
 
-    $w->startTag('body');
-
-      $w->dataElement( 'requesttype' => $function );
-
-      if ( keys %$opts ) {
-        $w->startTag('item');
-          foreach my $opt ( keys %$opts ) {
-            $w->dataElement( $opt => $opts->{$opt} );
-          }
-        $w->endTag('item');
-      }
-
-    $w->endTag('body');
-
-  $w->endTag('request');
-
-  #$output =~ s/\n+/\n/g;
-
-  warn "XML Request for $function function:\n$output"
-    if $self->{'debug'} > 1;
-
-  my( $page, $response, %reply_headers ) = https_post(
-    'host'         => $HOST,
-    'port'         => $PORT,
-    'path'         => ($PATH||443),
-    'args'         => { 'apidata' => $output, },
-    #'content'      => $output,
-    #'Content-Type' => 'text/plain',
-    #'Content-Type' => 'text/xml',
-    'Content-Type' => 'application/xml',
-    #'headers' => {},
-    'debug'        => ( $self->{'debug'} > 1 ? 1 : 0 ),
-  );
-
-  unless ( $response =~ /^200/i ) {
-    $self->{'errstr'} = $response;
-    return '';
-  }
-
-  warn "XML Response for $function function:\n: $page"
-    if $self->{'debug'} > 1;
-
-  my $hashref = XMLin( $page );
-
-  warn "Parsed response for $function funtion:\n". Dumper($hashref)
-    if $self->{'debug'} > 1;
-
-  my $return = $hashref->{'body'};
-
-  warn "Returning data:\n". Dumper($return)
-    if $self->{'debug'} > 1;
-
-  $return;
+  SOAP::Lite
+    ->proxy($URI)
+    #->uri($NS)
+    ->default_ns($NS)
+    ->on_action( sub { join '/', @_ } )
+    ->$function( @soap_opts )
+    ->result();
 
 }
 
@@ -195,8 +167,6 @@ the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-VoIP_I
 automatically be notified of progress on your bug as I make changes.
 
 
-
-
 =head1 SUPPORT
 
 You can find documentation for this module with the perldoc command.
@@ -227,12 +197,9 @@ L<http://search.cpan.org/dist/Net-VoIP_Innovations>
 =back
 
 
-=head1 ACKNOWLEDGEMENTS
-
-
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2008-2012 Freeside Internet Services, Inc. (http://freeside.biz/)
+Copyright 2008-2014 Freeside Internet Services, Inc. (http://freeside.biz/)
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.
@@ -245,8 +212,8 @@ The Freeside software includes support for VoIP Innovations integration, CDR
 rating, invoicing, credit card and electronic check processing, integrated
 trouble ticketing, and customer signup and self-service web interfaces.
 
-http://freeside.biz/freeside/
+L<http://freeside.biz/freeside/>
 
 =cut
 
-1; # End of Net::VoIP_Innovations
+1;