From 1ed8df25cb58e83f7470c714062a946b8d19ae07 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 16 Jun 2008 07:07:35 +0000 Subject: [PATCH] initial import... --- .cvsignore | 10 ++ Changes | 5 + MANIFEST | 12 ++ Makefile.PL | 18 +++ README | 56 ++++++++ lib/Net/GlobalPOPs/MediaServicesAPI.pm | 240 +++++++++++++++++++++++++++++++++ t/00-load.t | 9 ++ t/01-login.t | 17 +++ t/41-auditDIDs.t | 26 ++++ t/61-getDID.t | 29 ++++ t/lib/test_account.pl | 22 +++ t/pod-coverage.t | 18 +++ t/pod.t | 12 ++ 13 files changed, 474 insertions(+) create mode 100644 .cvsignore create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/Net/GlobalPOPs/MediaServicesAPI.pm create mode 100644 t/00-load.t create mode 100644 t/01-login.t create mode 100644 t/41-auditDIDs.t create mode 100644 t/61-getDID.t create mode 100644 t/lib/test_account.pl create mode 100644 t/pod-coverage.t create mode 100644 t/pod.t diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..8871aab --- /dev/null +++ b/.cvsignore @@ -0,0 +1,10 @@ +blib* +Makefile +Makefile.old +Build +_build* +pm_to_blib* +*.tar.gz +.lwpcookies +Net-GlobalPOPs-MediaServicesAPI-* +cover_db diff --git a/Changes b/Changes new file mode 100644 index 0000000..dc6e0b1 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for Net-GlobalPOPs-MediaServicesAPI + +0.01 unreleased + First version, released on an unsuspecting world. + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..ab70e40 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,12 @@ +Changes +MANIFEST +Makefile.PL +README +lib/Net/GlobalPOPs/MediaServicesAPI.pm +t/00-load.t +t/01-login.t +t/41-auditDIDs.t +t/61-getDID.t +t/pod-coverage.t +t/pod.t +t/lib/test_account.pl diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..a866c34 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,18 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'Net::GlobalPOPs::MediaServicesAPI', + AUTHOR => 'Ivan Kohler ', + VERSION_FROM => 'lib/Net/GlobalPOPs/MediaServicesAPI.pm', + ABSTRACT_FROM => 'lib/Net/GlobalPOPs/MediaServicesAPI.pm', + PL_FILES => {}, + PREREQ_PM => { + 'Test::More' => 0, + 'XML::Simple' => 0, + 'XML::Writer' => 0, + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'Net-GlobalPOPs-MediaServicesAPI-*' }, +); diff --git a/README b/README new file mode 100644 index 0000000..672c3c5 --- /dev/null +++ b/README @@ -0,0 +1,56 @@ +Net-GlobalPOPs-MediaServicesAPI + +This is an interface to the GlobalPOPs Media Services API for wholesale +DID (phone number) provisioning. It is only useful if you have an account +with GlobalPOPs wholesale VoIP service. + + +INSTALLATION + +To install this module, run the following commands: + + perl Makefile.PL + make + make test + make install + + +SUPPORT AND DOCUMENTATION + +After installing, you can find documentation for this module with the +perldoc command. + + perldoc Net::GlobalPOPs::MediaServicesAPI + +You can also look for information at: + + RT, CPAN's request tracker + http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-GlobalPOPs-MediaServicesAPI + + AnnoCPAN, Annotated CPAN documentation + http://annocpan.org/dist/Net-GlobalPOPs-MediaServicesAPI + + CPAN Ratings + http://cpanratings.perl.org/d/Net-GlobalPOPs-MediaServicesAPI + + Search CPAN + http://search.cpan.org/dist/Net-GlobalPOPs-MediaServicesAPI + + +COPYRIGHT AND LICENCE + +Copyright (C) 2008 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. + + +ADVERTISEMENT + +Need a complete, open-source back-office and customer self-service solution? +The Freeside software includes support for GlobalPOPs 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/ + diff --git a/lib/Net/GlobalPOPs/MediaServicesAPI.pm b/lib/Net/GlobalPOPs/MediaServicesAPI.pm new file mode 100644 index 0000000..0f0a940 --- /dev/null +++ b/lib/Net/GlobalPOPs/MediaServicesAPI.pm @@ -0,0 +1,240 @@ +package Net::GlobalPOPs::MediaServicesAPI; + +use warnings; +use strict; +use Data::Dumper; +use XML::Simple; +use XML::Writer; +use Net::HTTPS::Any qw(https_post); + +=head1 NAME + +Net::GlobalPOPs::MediaServicesAPI - Interface to GlobalPOPs Media Services API + +=head1 VERSION + +Version 0.01 + +=cut + +our $VERSION = '0.01'; +our $URL = 'https://www.loginto.us/VOIP/api.pl'; +#could be parsed from URL, if it mattered... +our $HOST = 'www.loginto.us'; +our $PATH = '/VOIP/api.pl'; + +our $AUTOLOAD; +our $errstr = ''; + +=head1 SYNOPSIS + + use Net::GlobalPOPs::MediaServicesAPI; + + my $handle = Net::GlobalPOPs::MediaServicesAPI->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::GlobalPOPs::MediaServicesAPI 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 +#class method. + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = ref($_[0]) ? shift : { @_ }; + bless($self, $class); +} + +=head2 errstr + +=cut + +sub errstr { + my $class = shift; + + return $errstr + unless ref($class) && $class->isa('Net::GlobalPOPs::MediaServicesAPI'); + + 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' => '1'); #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 ); + + foreach my $opt ( keys %$opts ) { + + $w->dataElement( $opt => $opts->{$opt} ); + + } + + $w->endTag('body'); + + $w->endTag('request'); + + $output =~ s/\n\n/\n/g; + + warn "XML Request for $function function:\n$output" + if $self->{'debug'}; + + my( $page, $response, %reply_headers ) = https_post( + 'host' => $HOST, + 'path' => $PATH, + 'content' => $output, + 'Content-Type' => 'text/plain', + 'headers' => {}, + 'debug' => $self->{'debug'}, + ); + + unless ( $response =~ /^HTTP\/[\d\.]+\s+200/i ) { + $self->{'errstr'} = $response; + return ''; + } + + warn "XML Response for $function function:\n: $page" + if $self->{'debug'}; + + my $hashref = XMLin $page; + + warn "Parsed response for $function funtion:\n: ". Dumper($hashref) + if $self->{'debug'} + + %$hashref; + +} + +=head1 AUTHOR + +Ivan Kohler, C<< >> + +=head1 BUGS + +Please report any bugs or feature requests to C, or through +the web interface at L. 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::GlobalPOPs::MediaServicesAPI + + +You can also look for information at: + +=over 4 + +=item * RT: CPAN's request tracker + +L + +=item * AnnoCPAN: Annotated CPAN documentation + +L + +=item * CPAN Ratings + +L + +=item * Search CPAN + +L + +=back + + +=head1 ACKNOWLEDGEMENTS + + +=head1 COPYRIGHT & LICENSE + +Copyright 2008 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 + +Open-source billing, trouble ticketing and automation for VoIP providers: + +http://freeside.biz/freeside/ + +=cut + +1; # End of Net::GlobalPOPs::MediaServicesAPI diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..7195e1e --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,9 @@ +#!perl -T + +use Test::More tests => 1; + +BEGIN { + use_ok( 'Net::GlobalPOPs::MediaServicesAPI' ); +} + +diag( "Testing Net::GlobalPOPs::MediaServicesAPI $Net::GlobalPOPs::MediaServicesAPI::VERSION, Perl $], $^X" ); diff --git a/t/01-login.t b/t/01-login.t new file mode 100644 index 0000000..5a92d6c --- /dev/null +++ b/t/01-login.t @@ -0,0 +1,17 @@ +#!/usr/bin/perl -w + +use Test::More; +require 't/lib/test_account.pl'; + +my($login, $password) = test_account_or_skip; +plan tests => 2; + +use_ok 'Net::GlobalPOPs::MediaServicesAPI'; + +my $gp = Net::GlobalPOPs::MediaServicesAPI->new('login' => $login, + 'password' => $password ); + +#eww. what is the right, TEST_VERBOSE-aware way to do this +warn Net::GlobalPOPs::MediaServicesAPI->errstr unless $gp; + +ok( $gp, 'Login sucessful' ); diff --git a/t/41-auditDIDs.t b/t/41-auditDIDs.t new file mode 100644 index 0000000..4bb8907 --- /dev/null +++ b/t/41-auditDIDs.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w +# +$Net::SSLeay::ssl_version = 10; + +use Test::More; # skip_all => 'wtf'; + +require 't/lib/test_account.pl'; + +my($login, $password) = test_account_or_skip(); +plan tests => 2; + +use_ok 'Net::GlobalPOPs::MediaServicesAPI'; + +my $debug = $ENV{TEST_VERBOSE}; + +my $gp = Net::GlobalPOPs::MediaServicesAPI->new( 'login' => $login, + 'password' => $password, + 'debug' => $debug, + ); +my $return = $gp->auditDIDs(); + +use Data::Dumper; +diag( Dumper($return) ) if $debug; + +#XXX test some things about the return... +ok( $return, 'auditDIDs returned something' ); diff --git a/t/61-getDID.t b/t/61-getDID.t new file mode 100644 index 0000000..e2d9a0e --- /dev/null +++ b/t/61-getDID.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl -w + +#BEGIN { +# $Net::HTTPS::Any::skip_NetSSLeay = 1; +# $Net::HTTPS::Any::skip_NetSSLeay = 1; +#} + +use Test::More; + +require 't/lib/test_account.pl'; + +my($login, $password) = test_account_or_skip(); +plan tests => 2; + +use_ok 'Net::GlobalPOPs::MediaServicesAPI'; + +my $debug = $ENV{TEST_VERBOSE}; + +my $gp = Net::GlobalPOPs::MediaServicesAPI->new( 'login' => $login, + 'password' => $password, + 'debug' => $debug, + ); +my $return = $gp->getDID(); + +use Data::Dumper; +diag( Dumper($return) ) if $debug; + +#XXX test some things about the return... +ok( $return, 'auditDIDs returned something' ); diff --git a/t/lib/test_account.pl b/t/lib/test_account.pl new file mode 100644 index 0000000..4b316db --- /dev/null +++ b/t/lib/test_account.pl @@ -0,0 +1,22 @@ +use Test::More; + +sub test_account_or_skip { + my($login, $password) = test_account(); + + unless( defined $login ) { + plan skip_all => "No test account"; + } + + return($login, $password); +} + +sub test_account { + open TEST_ACCOUNT, "t/test_account" or return; + my($login, $password) = ; + chomp $login; + chomp $password; + + return($login, $password); +} + +1; diff --git a/t/pod-coverage.t b/t/pod-coverage.t new file mode 100644 index 0000000..fc40a57 --- /dev/null +++ b/t/pod-coverage.t @@ -0,0 +1,18 @@ +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod::Coverage +my $min_tpc = 1.08; +eval "use Test::Pod::Coverage $min_tpc"; +plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" + if $@; + +# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, +# but older versions don't recognize some common documentation styles +my $min_pc = 0.18; +eval "use Pod::Coverage $min_pc"; +plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" + if $@; + +all_pod_coverage_ok(); diff --git a/t/pod.t b/t/pod.t new file mode 100644 index 0000000..ee8b18a --- /dev/null +++ b/t/pod.t @@ -0,0 +1,12 @@ +#!perl -T + +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod +my $min_tp = 1.22; +eval "use Test::Pod $min_tp"; +plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; + +all_pod_files_ok(); -- 2.11.0