| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::IPRental; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | BEGIN { | 
| 4 | 1 |  |  | 1 |  | 992 | $WebService::IPRental::VERSION = '0.02'; | 
| 5 |  |  |  |  |  |  | } | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # ABSTRACT: IP Rental API | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 10 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 10 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 42 |  | 
| 11 | 1 |  |  | 1 |  | 437 | use SOAP::Lite; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | #use SOAP::Lite +trace => 'all'; | 
| 14 |  |  |  |  |  |  | use Carp 'croak'; | 
| 15 |  |  |  |  |  |  | use XML::Simple 'XMLin'; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | $SOAP::Constants::PREFIX_ENC = 'SOAP-ENC'; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | sub new { | 
| 20 |  |  |  |  |  |  | my $class = shift; | 
| 21 |  |  |  |  |  |  | my $args = scalar @_ % 2 ? shift : {@_}; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | $args->{APIkey}   or croak 'APIkey is required'; | 
| 24 |  |  |  |  |  |  | $args->{APIpass}  or croak 'APIpass is required'; | 
| 25 |  |  |  |  |  |  | $args->{Username} or croak 'Username is required'; | 
| 26 |  |  |  |  |  |  | $args->{Password} or croak 'Password is required'; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | $args->{TTL} ||= 780; | 
| 29 |  |  |  |  |  |  | $args->{soap} = | 
| 30 |  |  |  |  |  |  | SOAP::Lite->envprefix('SOAP-ENV') | 
| 31 |  |  |  |  |  |  | ->on_fault( sub { print( Dumper( $_[1]->fault ), "\n" ); } ) | 
| 32 |  |  |  |  |  |  | ->on_action( sub { 'urn:IPRentalSoapAPIAction' } ) | 
| 33 |  |  |  |  |  |  | ->proxy( 'https://secure.iprental.com/api/', timeout => 5 ) | 
| 34 |  |  |  |  |  |  | ->ns( 'urn:IPRentalSoapAPI', 'ns1' )->outputxml(1)->autotype(0); | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | bless $args, $class; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub doIpLease { | 
| 40 |  |  |  |  |  |  | my ($self) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | my @search_request_params; | 
| 43 |  |  |  |  |  |  | foreach my $arg (qw(APIkey APIpass username password )) { | 
| 44 |  |  |  |  |  |  | push @search_request_params, | 
| 45 |  |  |  |  |  |  | SOAP::Data->name($arg)->value( $self->{ ucfirst $arg } ) | 
| 46 |  |  |  |  |  |  | ->attr( { 'xsi:type' => "xsd:string" } ); | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | foreach my $arg ( 'TTL', 'Location' ) { | 
| 49 |  |  |  |  |  |  | push @search_request_params, | 
| 50 |  |  |  |  |  |  | SOAP::Data->name($arg)->value( $self->{$arg} || 0 ) | 
| 51 |  |  |  |  |  |  | ->attr( { 'xsi:type' => "xsd:int" } ); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | my $request_params = | 
| 55 |  |  |  |  |  |  | SOAP::Data->name('return')->value( [@search_request_params] ) | 
| 56 |  |  |  |  |  |  | ->attr( { 'xsi:type' => 'ns1:IPRargs' } ); | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | my $xml = | 
| 59 |  |  |  |  |  |  | $self->{soap}->call( SOAP::Data->name('ns1:doIpLease'), $request_params ); | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | my $data = XMLin( $xml, NoAttr => 1 ); | 
| 62 |  |  |  |  |  |  | my $response = | 
| 63 |  |  |  |  |  |  | $data->{'SOAP-ENV:Body'}->{'ns1:doIpLeaseResponse'}->{return}; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | return $response; | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub verboseReponseCode { | 
| 69 |  |  |  |  |  |  | my ( $self, $r ) = @_; | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | return "Good, Fresh IP"                     if $r == 202; | 
| 72 |  |  |  |  |  |  | return "Good, Duplicate IP"                 if $r == 203; | 
| 73 |  |  |  |  |  |  | return "Internal Error, Unable to serve IP" if $r == 402; | 
| 74 |  |  |  |  |  |  | return "Unknown User Authentication"        if $r == 403; | 
| 75 |  |  |  |  |  |  | return "Unknown API Authentication"         if $r == 404; | 
| 76 |  |  |  |  |  |  | return "0 IP leases left in your pool"      if $r == 405; | 
| 77 |  |  |  |  |  |  | return "Impermissible network type"         if $r == 406; | 
| 78 |  |  |  |  |  |  | return "Unknown"; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | 1; | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | __END__ |