DNS-WorldWideDns
view release on metacpan or search on metacpan
lib/DNS/WorldWideDns.pm view on Meta::CPAN
=head2 new ( username, password )
Constructor. Throws MissingParam.
=head3 username
Your worldwidedns.net username.
=head3 password
The password to go with username.
=cut
sub new {
my ($class, $username, $password) = @_;
# validate
unless (defined $username) {
MissingParam->throw(error=>'Need a username.');
}
unless (defined $password) {
MissingParam->throw(error=>'Need a password.');
}
# set up object
my $self = register($class);
my $refId = id $self;
$username{$refId} = $username;
$password{$refId} = $password;
return $self;
}
###############################################################
=head2 password ()
Returns the password set in the constructor.
=cut
###############################################################
=head2 updateDomain ( domain, params )
Updates a domain in your account. Throws MissingParam, InvalidParam, InvalidAccount and RequestError.
Returns a 1 on success.
=head3 domain
A domain to update.
=head3 params
A hash reference identical to the one returned by getDomain().
=cut
sub updateDomain {
my ($self, $domain, $params) = @_;
# validate inputs
unless (defined $domain) {
MissingParam->throw(error=>'Need a domain.');
}
unless ($domain =~ m{^[\w\-\.]+$}xms) {
InvalidParam->throw(error=>'Domain is improperly formatted.', got=>$domain);
}
unless (defined $params) {
MissingParam->throw(error=>'Need parameters hash ref to set on the domain.');
}
unless (ref $params eq 'HASH') {
InvalidParam->throw(error=>'Expected a params hash reference.', got=>$params);
}
# zone data
my $zoneData;
foreach my $record (@{$params->{records}}) {
$zoneData .= join(" ", $record->{name}, $record->{ttl}, 'IN', $record->{type}, $record->{data})."\r\n";
}
# make request
my $url = 'https://www.worldwidedns.net/api_dns_modify_raw.asp';
my $request = POST $url, [
NAME => $self->username,
PASSWORD => $self->password,
DOMAIN => $domain,
HOSTMASTER => $params->{hostmaster},
REFRESH => $params->{refresh},
RETRY => $params->{retry},
SECURE => $params->{secureTransfer},
EXPIRE => $params->{expire},
TTL => $params->{ttl},
FOLDER => '',
ZONENS => 'ns1.worldwidedns.net',
ZONEDATA => $zoneData,
];
my $response = $self->makeRequest($url, $request);
my $content = $response->content;
chomp $content;
# interpret results
if ($content =~ m{211\s*212\s*213}xmsi) {
return 1;
}
elsif ($content eq "405") {
RequestError->throw(
error => 'Domain not in account.',
url => $url,
code => $content,
response => $response,
);
}
RequestError->throw(
error => 'Updating one of the name servers failed.',
url => $url,
code => $content,
response => $response,
( run in 0.469 second using v1.01-cache-2.11-cpan-5b529ec07f3 )