diff options
author | Ivan Kohler <ivan@freeside.biz> | 2012-12-12 16:31:06 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2012-12-12 16:31:06 -0800 |
commit | 1d339ad33855e8df8c1f466b494acbfd0e0907da (patch) | |
tree | a4a609605840d1ebf666e651efd41663d8f7da83 /lib/Net |
initial commit
Diffstat (limited to 'lib/Net')
-rw-r--r-- | lib/Net/VoIP_Innovations.pm | 252 |
1 files changed, 252 insertions, 0 deletions
diff --git a/lib/Net/VoIP_Innovations.pm b/lib/Net/VoIP_Innovations.pm new file mode 100644 index 0000000..bd56c8b --- /dev/null +++ b/lib/Net/VoIP_Innovations.pm @@ -0,0 +1,252 @@ +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 ); + +=head1 NAME + +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 $AUTOLOAD; +our $errstr = ''; + +=head1 SYNOPSIS + + use Net::VoIP_Innovations; + + my $handle = Net::VoIP_Innovations->new( + 'login' => 'tofu', + 'password' => 'beast', + 'debug' => 1, + ); + + #DID functions + #auditDIDs + #queryDID + #reserveDID + #assignDID + #configDID + #releaseDID + + #911 Functions + + #Locator Functions + + ... + +=head1 METHODS + +=head2 new HASHREF | OPTION, VALUE ... + +Creates a new Net::VoIP_Innovations object. Options may be passed +as a hash reference or a flat list of names and values. + +=over 4 + +=item login (required) + +=item password (required) + +=item login (required) + +=back + +=cut + +# If there is an error, +#returns false and sets an error string which may be queried with the I<errstr> +#class method. + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = ref($_[0]) ? shift : { @_ }; + $self->{'debug'} ||= 0; + bless($self, $class); +} + +=head2 errstr + +=cut + +sub errstr { + my $class = shift; + + return $errstr + unless ref($class) && $class->isa('Net::VoIP_Innovations'); + + my $self = $class; + $self->{errstr}; +} + +sub DESTROY { }; # no-op + +sub AUTOLOAD { + my $self = shift; + my $opts = ref($_[0]) ? shift : { @_ }; + + $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'); + + $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; + +} + +=head1 AUTHOR + +Ivan Kohler, C<< <ivan-net-voipinnovations at freeside.biz> >> + +=head1 BUGS + +Please report any bugs or feature requests to C<bug-net-voip_innovations at rt.cpan.org>, or through +the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-VoIP_Innovations>. I will be notified, and then you'll +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. + + perldoc Net::VoIP_Innovations + + +You can also look for information at: + +=over 4 + +=item * RT: CPAN's request tracker + +L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-VoIP_Innovations> + +=item * AnnoCPAN: Annotated CPAN documentation + +L<http://annocpan.org/dist/Net-VoIP_Innovations> + +=item * CPAN Ratings + +L<http://cpanratings.perl.org/d/Net-VoIP_Innovations> + +=item * Search CPAN + +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/) + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + + +=head1 ADVERTISEMENT + +Need a complete, open-source back-office and customer self-service solution? +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/ + +=cut + +1; # End of Net::VoIP_Innovations |