API-DirectAdmin

 view release on metacpan or  search on metacpan

lib/API/DirectAdmin.pm  view on Meta::CPAN

package API::DirectAdmin;

use Modern::Perl '2010';
use LWP::UserAgent;
use HTTP::Request;
use Data::Dumper;
use Carp;
use URI;

our $VERSION = 0.09;
our $DEBUG   = '';
our $FAKE_ANSWER = '';

# for init subclasses
init_components(
    domain => 'Domain',
    mysql  => 'Mysql',
    user   => 'User',
    dns    => 'DNS',
    ip     => 'Ip',
);

# init
sub new {
    my $class = shift;
    $class = ref ($class) || $class;
    
    my $self = {
        auth_user   => '',
        auth_passwd => '',
        host        => '',
        ip          => '',
        debug       => $DEBUG,
	    allow_https => 1,
	    fake_answer => $FAKE_ANSWER,
        (@_)
    };

    confess "Required auth_user!"   unless $self->{auth_user};
    confess "Required auth_passwd!" unless $self->{auth_passwd};
    confess "Required host!"        unless $self->{host};

    return bless $self, $class;
}

# initialize components
sub init_components {
    my ( %c ) = @_;
    my $caller = caller;

    for my $alias (  keys %c ) {

        my $item = $c{$alias};

        my $sub = sub {
            my( $self ) = @_;
            $self->{"_$alias"} ||= $self->load_component($item);
            return $self->{"_$alias"} || confess "Not implemented!";
        };
        
        no strict 'refs';
 
        *{"$caller\::$alias"} = $sub;

lib/API/DirectAdmin.pm  view on Meta::CPAN

    $da->dns->dumpzone( {domain => 'domain.com'} );

=item add_record

Add zone record to dns for domain. Available types of records: A, AAAA, NS, MX, TXT, PTR, CNAME, SRV

Example:

    my $result = $da->dns->add_record({
        domain => 'domain.com', 
        type   => 'A',
        name   => 'subdomain', # will be "subdomain.domain.com." in record
        value  => '127.127.127.127',
    });

Example with MX record:

    my $result = $da->dns->add_record( { 
        domain  => 'domain.com',
        type    => 'MX',
        name    => 'mx1',
        value   => 10,
    } );

=item remove_record

Remove record from domain zone

Example:

    my $result = $da->dns->remove_record({
        domain => 'domain.com',
        type   => 'A',
        name   => 'subdomain',
        value  => '127.127.127.127',
    });

Example with MX record:

    my $result = $da->dns->remove_record({
        domain => 'domain.com',
        type   => 'mx',
        name   => 'mx1',
        value  => 10,
    });

=back

=head1 INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

=head1 DEPENDENCIES

This module requires these other modules and libraries:
  Modern::Perl
  LWP::UserAgent
  HTTP::Request
  URI
  Carp 
  Data::Dumper

=head1 COPYRIGHT AND LICENCE

Copyright (C) 2012-2013 by Andrey "Chips" Kuzmin <chipsoid@cpan.org>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.1 or,
at your option, any later version of Perl 5 you may have available.

=cut



( run in 0.363 second using v1.01-cache-2.11-cpan-39bf76dae61 )