DNS-PunyDNS

 view release on metacpan or  search on metacpan

lib/DNS/PunyDNS.pm  view on Meta::CPAN

    return 0 if ( $self->{'error'} );
    return 1;
}

sub get_dns_info {
    my ( $self, $domain ) = @_;
    die "You must provide a domain to check" if ( !$domain );
    my $response = $self->_get_it( $GETDNSINFO, { 'domain' => $domain } );
    return if ( $self->{'error'} );
    my @domain_info = ();
    my $info        = $response->{'info'};
    if ( ref($info) eq 'ARRAY' ) {
        for my $dnsinfo ( @{$info} ) {
            my %tmp_info;
            $tmp_info{'domain'} = $response->{'domain'};
            $tmp_info{'ip'}     = $dnsinfo->{'ip'};
            $tmp_info{'type'}   = $dnsinfo->{'type'};
            push @domain_info, \%tmp_info;
        }
    } else {
        my %tmp_info = (
            'domain' => $response->{'domain'},
            'ip'     => $info->{'ip'},
            'type'   => $info->{'type'},
        );
        push @domain_info, \%tmp_info;
    }

    return \@domain_info;
} ## end sub get_dns_info

sub list_dns_info {
    my ($self)   = @_;
    my $response = $self->_get_it($LISTDNSINFO);
    my @domains  = ();
    if ( $response->{'domains'}{'domain'} ) {
        if ( ref( $response->{'domains'}{'domain'} ) eq 'ARRAY' ) {
            push @domains, @{ $response->{'domains'}{'domain'} };
        } else {
            push @domains, $response->{'domains'}{'domain'};
        }
    }
    return \@domains;
}

sub list_dns {
    my ($self)   = @_;
    my $response = $self->_get_it($LISTDNS);
    my @domains  = ();
    if ( $response->{'domain'} ) {
        if ( ref( $response->{'domains'} ) eq 'ARRAY' ) {
            push @domains, @{ $response->{'domain'} };
        } else {
            push @domains, $response->{'domain'};
        }
    }
    return \@domains;
}

sub _build_request {
    my ( $self, $endpoint, $args ) = @_;
    $args->{'ESBUsername'} = $self->{'username'};
    $args->{'ESBPassword'} = $self->{'password'};
    $args->{'lang'}        = 'en';
    my @keys = keys %{$args};

    my $url = $BASE_URL . $endpoint . '?' . join( '&', map { $_ . '=' . $args->{$_} } @keys );

    return $url;
}

sub _get_it {
    my ( $self, $endpoint, $args ) = @_;

    my $url = $self->_build_request( $endpoint, $args );
    delete $self->{'error'};

    my $ua       = new LWP::UserAgent();
    my $req      = new HTTP::Request( 'GET', $url );
    my $response = $ua->request($req);

    if ( $response->is_success ) {
        my $content = $response->content;
        my $decoded_content = XMLin( \$content, KeyAttr => 'domain' );
        if ( $decoded_content->{'error'} ) {
            $self->{'error'} = $decoded_content->{'error'};
        }
        return $decoded_content;
    } else {
        die "There was a problem with the request\n" . $response->status_line;
    }

} ## end sub _get_it

=head1 AUTHOR

Bruno Martins, C<< <bruno-martins at telecom.pt> >>

=head1 NOTES

=head2 Handling Errors

There are several ways that the operations can fail, for example, you can try to add a dns entry that already exists or you can try to update a dns entry that is not under your account, etc. 

Each time an operation is executed and raises an error C<< $dns->{'error'} >> is set with the error reason.

=head2 SAPO dynamic DNS API authentication

SAPO dynamic DNS API is only available over https, so your username and password are not sent I<clean>

=head2 Record Types

SAPO dynamic DNS API only allows A and AAAA record types

=head2 Domain names

At this time, SAPO dynamic DNS only allows .sl.pt domains

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc DNS::PunyDNS


You can also look for information at:

=over 4

=item * Search CPAN

L<http://search.cpan.org/dist/DNS::PunyDNS/>

=back



( run in 1.950 second using v1.01-cache-2.11-cpan-b16cb0d3907 )