NAME

WebService::DigitalOcean - Access the DigitalOcean RESTful API (v2)

VERSION

version 0.020

SYNOPSIS

use WebService::DigitalOcean;

my $do = WebService::DigitalOcean->new({ token => $TOKEN });

my $res = $do->domain_create({
    name => 'example.com',
    ip_address => '127.0.0.1',
});

if ($res->{is_success}) {
    say $res->{content}{name};
}
else {
    say "Could not create domain";
}

DESCRIPTION

This module implements DigitalOceans new RESTful API.

It's on a very early stage of development, so expect new features, better docs and tests very soon.

Patches welcome: https://github.com/andrewalker/p5-webservice-digitalocean

ATTRIBUTES

api_base_url

A string prepended to all API endpoints. By default, it's https://api.digitalocean.com/v2. This can be adjusted to facilitate tests.

token

The authorization token. It can be retrieved by logging into one's DigitalOcean account, and generating a personal token here: https://cloud.digitalocean.com/settings/applications.

METHODS

$do->domain_create(\%args)

Arguments

Str $args{name}

The domain name.

Str $args{ip_address}

The IP address the domain will point to.

Creates a new domain name.

$do->domain_create({
    name       => 'example.com',
    ip_address => '12.34.56.78',
});

More info: https://developers.digitalocean.com/#create-a-new-domain.

$do->domain_delete($domain)

Arguments

Str $domain

The domain name.

Deletes the specified domain.

$do->domain_delete('example.com');

More info: https://developers.digitalocean.com/#delete-a-domain.

$do->domain_get($domain)

Arguments

Str $domain

The domain name.

Retrieves the specified domain.

my $response = $do->domain_get('example.com');

More info: https://developers.digitalocean.com/#retrieve-an-existing-domain.

$do->domain_list()

Lists all domains for this account.

my $response = $do->domain_list();

for (@{ $response->{content} }) {
    print $_->{id};
}

More info: https://developers.digitalocean.com/#list-all-domains.

$do->domain_record_create(\%args)

Arguments

Str $args{domain}

The domain under which the record will be created.

Str $args{type}

The type of the record (eg MX, CNAME, A, etc).

Str $args{name} (optional)

The name of the record.

Str $args{data} (optional)

The data (such as the IP address) of the record.

Int $args{priority} (optional)

Priority, for MX or SRV records.

Int $args{port} (optional)

The port, for SRV records.

Int $args{weight} (optional)

The weight, for SRV records.

Creates a new record for a domain.

my $response = $do->domain_record_create({
    domain => 'example.com',
    type   => 'A',
    name   => 'www2',
    data   => '12.34.56.78',
});

my $id = $response->{content}{id};

More info: https://developers.digitalocean.com/#create-a-new-domain-record.

$do->domain_record_delete(\%args)

Arguments

Str $args{domain}

The domain to which the record belongs.

Int $args{id}

The id of the record.

Deletes the specified record.

$do->domain_record_delete({
    domain => 'example.com',
    id     => 1215,
});

More info: https://developers.digitalocean.com/#delete-a-domain-record.

$do->domain_record_get(\%args)

Arguments

Str $args{domain}

The domain to which the record belongs.

Int $args{id}

The id of the record.

Retrieves details about a particular record, identified by id.

my $response = $do->domain_record_get({
    domain => 'example.com',
    id     => 1215,
});

my $ip = $response->{content}{data};

More info: https://developers.digitalocean.com/#retrieve-an-existing-domain-record.

$do->domain_record_list($domain)

Arguments

Str $domain

The domain to which the records belong.

Retrieves all the records for a particular domain.

my $response = $do->domain_record_list('example.com');

for (@{ $response->{content} }) {
    print "$_->{name} => $_->{data}\n";
}

More info: https://developers.digitalocean.com/#list-all-domain-records.

$do->droplet_create(\%args)

Arguments

Str $args{name}
Str $args{region}
Str $args{size}
Str $args{image}
ArrayRef $args{ssh_keys} (optional)
Bool $args{backups} (optional)
Bool $args{ipv6} (optional)
Bool $args{private_networking} (optional)

Creates a new droplet.

$do->droplet_create(
    name               => "My-Droplet",
    region             => "nyc1",
    size               => "512mb",
    image              => 449676389,
    ssh_keys           => [ 52341234, 215124, 64325534 ],
    backups            => 0,
    ipv6               => 1,
    private_networking => 0,
);

More info: https://developers.digitalocean.com/#create-a-new-droplet.

$do->droplet_delete($id)

Arguments

Int $id

Deletes the specified droplet.

$do->droplet_delete(1250928);

More info: https://developers.digitalocean.com/#delete-a-droplet.

$do->droplet_get($id)

Arguments

Int $id

Retrieves the specified droplet.

my $response = $do->droplet_get(15314123);

More info: https://developers.digitalocean.com/#retrieve-an-existing-droplet-by-id.

$do->droplet_list()

Lists all droplets for this account.

my $response = $do->droplet_list();

for (@{ $response->{content} }) {
    print $_->{id};
}

More info: https://developers.digitalocean.com/#list-all-droplets.

$do->droplet_resize(\%args)

Arguments

Int $args{droplet}
Str $args{size}

Resizes a droplet.

$do->droplet_resize({
    droplet => 123456,
    size    => '1gb',
});

More info: https://developers.digitalocean.com/#resize-a-droplet.

$do->droplet_change_kernel(\%args)

Arguments

Int $args{droplet}
Int $args{kernel}

Changes the kernel of a droplet.

$do->droplet_change_kernel({
    droplet => 123456,
    kernel  => 654321,
});

More info: https://developers.digitalocean.com/#change-the-kernel.

$do->droplet_rebuild(\%args)

Arguments

Int $args{droplet}
Str $args{image}

Rebuilds a droplet.

$do->droplet_rebuild({
    droplet => 123456,
    image   => 654321,
});

More info: https://developers.digitalocean.com/#rebuild-a-droplet.

$do->droplet_restore(\%args)

Arguments

Int $args{droplet}
Str $args{image}

Restores a droplet to an image backup.

$do->droplet_rebuild({
    droplet => 123456,
    image   => 654321,
});

More info: https://developers.digitalocean.com/#restore-a-droplet.

$do->droplet_rename(\%args)

Arguments

Int $args{droplet}
Str $args{name}

Renames a droplet, thus setting the reverse DNS.

$do->droplet_rename({
    droplet => 123456,
    name    => 'new-name',
});

More info: https://developers.digitalocean.com/#rename-a-droplet.

$do->droplet_snapshot(\%args)

Arguments

Int $args{droplet}
Str $args{name}

Saves a snapshopt of the droplet.

$do->droplet_rebuild({
    droplet => 123456,
    name    => 'snapshot-name',
});

More info: https://developers.digitalocean.com/#rebuild-a-droplet.

$do->droplet_reboot($droplet_id)

Arguments

Int $droplet_id

Reboots droplet.

$do->droplet_reboot(123456);

More info: https://developers.digitalocean.com/#reboot-a-droplet.

$do->droplet_power_cycle($droplet_id)

Arguments

Int $droplet_id

Power cycles droplet.

$do->droplet_power_cycle(123456);

More info: https://developers.digitalocean.com/#power-cycle-a-droplet.

$do->droplet_power_on($droplet_id)

Arguments

Int $droplet_id

Powers on droplet.

$do->droplet_power_on(123456);

More info: https://developers.digitalocean.com/#power-on-a-droplet.

$do->droplet_power_off($droplet_id)

Arguments

Int $droplet_id

Powers off droplet.

$do->droplet_power_off(123456);

More info: https://developers.digitalocean.com/#power-off-a-droplet.

$do->droplet_password_reset($droplet_id)

Arguments

Int $droplet_id

Resets the root password of the droplet.

$do->droplet_password_reset(123456);

More info: https://developers.digitalocean.com/#password-reset-a-droplet.

$do->droplet_shutdown($droplet_id)

Arguments

Int $droplet_id

Shuts down a droplet

$do->droplet_shutdown(123456);

More info: https://developers.digitalocean.com/#shutdown-a-droplet.

$do->droplet_enable_ipv6($droplet_id)

Arguments

Int $droplet_id

Enables IPv6 in a droplet.

$do->droplet_enable_ipv6(123456);

More info: https://developers.digitalocean.com/#enable-ipv6.

$do->droplet_enable_private_networking($droplet_id)

Arguments

Int $droplet_id

Enables private networking for a droplet.

$do->droplet_enable_private_networking(123456);

More info: https://developers.digitalocean.com/#enable-private-networking.

$do->droplet_disable_backups($droplet_id)

Arguments

Int $droplet_id

Disables backups for the droplet.

$do->droplet_disable_backups(123456);

More info: https://developers.digitalocean.com/#disable-backups.

$do->droplet_action_get(\%args)

Arguments

Int $args{droplet}
Int $args{action}

Retrieve details from a specific action.

$do->droplet_action_get({
    droplet => 123456,
    action  => 53,
});

More info: https://developers.digitalocean.com/#retrieve-a-droplet-action.

$do->key_create(\%args)

Arguments

Str $args{name}
Str $args{public_key}

Creates a new ssh key for this account.

my $response = $do->key_create({
    name       => 'my public key',
    public_key => <$public_key_fh>,
});

More info: https://developers.digitalocean.com/#create-a-new-key.

$do->key_delete(\%args)

Arguments

Int $args{id} OR
Str $args{fingerprint}

Deletes the specified ssh key.

$do->key_delete({ id => 146432 });

More info: https://developers.digitalocean.com/#destroy-a-key.

$do->key_get(\%args)

Arguments

Int $args{id} OR
Str $args{fingerprint}

Retrieves details about a particular ssh key, identified by id or fingerprint (pick one).

my $response = $do->key_get({ id => 1215 });

More info: https://developers.digitalocean.com/#retrieve-an-existing-key.

$do->key_list()

Retrieves all the keys for this account.

More info: https://developers.digitalocean.com/#list-all-keys.

$do->region_list()

Retrieves all the regions available in Digital Ocean.

my $regions = $do->region_list();

for my $r (@{ $regions->{content} }) {
    if ($r->{available}) {
        say "$r->{name} is available";
    }
}

More info: https://developers.digitalocean.com/#list-all-regions.

$do->size_list()

Retrieves all the sizes available in Digital Ocean.

my $sizes = $do->size_list();

for my $s (@{ $sizes->{content} }) {
    say "Size $s->{slug} costs $s->{price_hourly} per hour.";
}

More info: https://developers.digitalocean.com/#list-all-sizes.

SEE ALSO

DigitalOcean

First DigitalOcean module, uses v1 API. It has a more OO approach than this module, and might have a more stable interface at the moment.

https://developers.digitalocean.com

Documentation for API v2, in DigitalOcean's website.

CAVEATS

This is alpha software. The interface is unstable, and may change without notice.

Also, there are no real unit tests. We currently only test compilation and instantiation of the module.

AUTHOR

André Walker <andre@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2014 by André Walker.

This is free software, licensed under:

The GNU General Public License, Version 2, June 1991