1 package Net::GlobalPOPs::MediaServicesAPI;
8 use Net::HTTPS::Any qw( 0.10 https_post );
12 Net::GlobalPOPs::MediaServicesAPI - Interface to GlobalPOPs Media Services API
16 our $VERSION = '0.03';
17 our $URL = 'https://www.loginto.us/VOIP/api.pl';
18 #could be parsed from URL, if it mattered...
19 our $HOST = 'www.loginto.us';
20 our $PATH = '/VOIP/api.pl';
21 our $PORT = 443; #to allow testing to override
28 use Net::GlobalPOPs::MediaServicesAPI;
30 my $handle = Net::GlobalPOPs::MediaServicesAPI->new(
32 'password' => 'beast',
52 =head2 new HASHREF | OPTION, VALUE ...
54 Creates a new Net::GlobalPOPs::MediaServicesAPI object. Options may be passed
55 as a hash reference or a flat list of names and values.
59 =item login (required)
61 =item password (required)
63 =item login (required)
69 # If there is an error,
70 #returns false and sets an error string which may be queried with the I<errstr>
75 my $class = ref($proto) || $proto;
76 my $self = ref($_[0]) ? shift : { @_ };
77 $self->{'debug'} ||= 0;
89 unless ref($class) && $class->isa('Net::GlobalPOPs::MediaServicesAPI');
95 sub DESTROY { }; # no-op
99 my $opts = ref($_[0]) ? shift : { @_ };
101 $AUTOLOAD =~ /(^|::)(\w+)$/ or die "unparsable AUTOLOAD: $AUTOLOAD";
105 my $w = new XML::Writer(OUTPUT => \$output, DATA_MODE => 1, DATA_INDENT => 3);
107 $w->xmlDecl('ISO-8859-1');
108 $w->doctype('request', undef, $URL);
110 $w->startTag('request', 'id' => ''); #XXX request ID???
111 $w->startTag('header');
112 $w->startTag('sender');
114 if ( $self->{'sessionid'} ) {
116 #$w->dataElement( 'login' => '' );
117 #$w->dataElement( 'password' => '' );
118 $w->dataElement( 'sessionid' => $self->{'sessionid'} );
122 $w->dataElement( 'login' => $self->{'login'} );
123 $w->dataElement( 'password' => $self->{'password'} );
124 #$w->dataElement( 'sessionid' => '' );
128 $w->endTag('sender');
129 $w->endTag('header');
131 $w->startTag('body');
133 $w->dataElement( 'requesttype' => $function );
136 $w->startTag('item');
137 foreach my $opt ( keys %$opts ) {
138 $w->dataElement( $opt => $opts->{$opt} );
145 $w->endTag('request');
147 #$output =~ s/\n+/\n/g;
149 warn "XML Request for $function function:\n$output"
150 if $self->{'debug'} > 1;
152 my( $page, $response, %reply_headers ) = https_post(
155 'path' => ($PATH||443),
156 'args' => { 'apidata' => $output, },
157 #'content' => $output,
158 #'Content-Type' => 'text/plain',
159 #'Content-Type' => 'text/xml',
160 #'Content-Type' => 'application/xml',
162 'debug' => ( $self->{'debug'} > 1 ? 1 : 0 ),
165 unless ( $response =~ /^200/i ) {
166 $self->{'errstr'} = $response;
170 warn "XML Response for $function function:\n: $page"
171 if $self->{'debug'} > 1;
173 my $hashref = XMLin( $page );
175 warn "Parsed response for $function funtion:\n". Dumper($hashref)
176 if $self->{'debug'} > 1;
178 my $return = $hashref->{'body'};
180 warn "Returning data:\n". Dumper($return)
181 if $self->{'debug'} > 1;
189 Ivan Kohler, C<< <ivan-net-globalpops at freeside.biz> >>
193 Please report any bugs or feature requests to C<bug-net-globalpops-mediaservicesapi at rt.cpan.org>, or through
194 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-GlobalPOPs-MediaServicesAPI>. I will be notified, and then you'll
195 automatically be notified of progress on your bug as I make changes.
202 You can find documentation for this module with the perldoc command.
204 perldoc Net::GlobalPOPs::MediaServicesAPI
207 You can also look for information at:
211 =item * RT: CPAN's request tracker
213 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-GlobalPOPs-MediaServicesAPI>
215 =item * AnnoCPAN: Annotated CPAN documentation
217 L<http://annocpan.org/dist/Net-GlobalPOPs-MediaServicesAPI>
221 L<http://cpanratings.perl.org/d/Net-GlobalPOPs-MediaServicesAPI>
225 L<http://search.cpan.org/dist/Net-GlobalPOPs-MediaServicesAPI>
230 =head1 ACKNOWLEDGEMENTS
233 =head1 COPYRIGHT & LICENSE
235 Copyright 2008 Freeside Internet Services, Inc. (http://freeside.biz/)
237 This program is free software; you can redistribute it and/or modify it
238 under the same terms as Perl itself.
243 Open-source billing, trouble ticketing and automation for VoIP providers:
245 http://freeside.biz/freeside/
249 1; # End of Net::GlobalPOPs::MediaServicesAPI