digitalocean-api
Advanced tools
Comparing version 0.0.4 to 0.1.0
@@ -8,10 +8,12 @@ var extend = require('xtend'); | ||
/** | ||
* Digitalocean API Client | ||
* @param {[type]} clientID [description] | ||
* @param {[type]} apiKey [description] | ||
* <b>Digitalocean API Client</b>. | ||
* @constructor | ||
* @param {string} clientID Your account's DigitalOcean Client Id | ||
* @param {string} apiKey Your account's DigitalOcean API Key | ||
* @author Matěj Šimek <email@matejsimek.cz> (www.matejsimek.cz) | ||
*/ | ||
var Digitalocean = function(clientID, apiKey) { | ||
this.credentials = { | ||
client_id: clientID, | ||
api_key: apiKey | ||
client_id: clientID, | ||
api_key: apiKey | ||
}; | ||
@@ -22,9 +24,12 @@ }; | ||
/** | ||
* Helper to handle requests to the API with authorization | ||
* <b>Helper to handle requests to the API with authorization</b>. | ||
* | ||
* @param {[String]} url address part after API root | ||
* @param {[Object]} parameters additional parameters | ||
* @param {Function} callback [description] | ||
* @private | ||
* @param {string} url address part after API root | ||
* @param {Object} parameters additional parameters | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method get | ||
*/ | ||
Digitalocean.prototype.get = function(url, parameters, callback) { | ||
Digitalocean.prototype._get = function(url, parameters, callback) { | ||
extend(parameters, this.credentials); // Add credentials to parameters | ||
@@ -38,122 +43,160 @@ var getURL = API_URL + '/' + url + '?' + querystring.stringify(parameters); // Construct URL with parameters | ||
}, function(error, response, body) { | ||
if(!error && !!body.status && body.status !== 'OK'){ | ||
error = new Error(body.description || body.error_message); | ||
} | ||
callback(error, body || {}); | ||
if (!error && !!body.status && body.status !== 'OK') { | ||
error = new Error(body.description || body.error_message); | ||
} | ||
); | ||
callback(error, body || {}); | ||
}); | ||
}; | ||
/** | ||
* Show All Active Droplets | ||
* <b>Show All Active Droplets</b>. | ||
* This method returns all active droplets that are currently running in your account. All available API information is presented for each droplet. | ||
* @param {Function} callback [description] | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletGetAll | ||
*/ | ||
Digitalocean.prototype.dropletGetAll = function(callback) { | ||
this.get('droplets/', {}, function(error, body) { | ||
this._get('droplets/', {}, function(error, body) { | ||
callback(error, body.droplets); | ||
}); | ||
}; | ||
/** | ||
* Show Droplet | ||
* This method returns full information for a specific droplet ID that is passed in the URL. | ||
* @param {[Number]} id [description] | ||
* @param {Function} callback [description] | ||
* <b>New Droplet</b>. | ||
* This method allows you to create a new droplet. See the required parameters section below for an explanation of the variables that are needed to create a new droplet. | ||
* @param {string} name Required, this is the name of the droplet - must be formatted by hostname rules | ||
* @param {number} sizeId Required, this is the id of the size you would like the droplet created at | ||
* @param {number} imageId Required, this is the id of the image you would like the droplet created with | ||
* @param {number} regionId Required, this is the id of the region you would like your server in IE: US/Amsterdam | ||
* @param {Object} optionals { ssh_key_ids: [], private_networking: false, backups_enabled: false } | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletNew | ||
*/ | ||
Digitalocean.prototype.dropletGet = function(id, callback) { | ||
this.get('droplets/' + id, {}, function(error, body) { | ||
Digitalocean.prototype.dropletNew = function(name, sizeId, imageId, regionId, optionals, callback) { | ||
var options = { | ||
name: name, | ||
size_id: sizeId, | ||
image_id: imageId, | ||
region_id: regionId | ||
}; | ||
extend(options, optionals); | ||
this._get('droplets/new', options, function(error, body) { | ||
callback(error, body.droplet); | ||
}); | ||
}; | ||
/** | ||
* New Droplet | ||
* This method allows you to create a new droplet. See the required parameters section below for an explanation of the variables that are needed to create a new droplet. | ||
* @param {[String]} name Required, this is the name of the droplet - must be formatted by hostname rules | ||
* @param {[Number]} sizeId Required, this is the id of the size you would like the droplet created at | ||
* @param {[Number]} imageId Required, this is the id of the image you would like the droplet created with | ||
* @param {[Number]} regionId Required, this is the id of the region you would like your server in IE: US/Amsterdam | ||
* @param {[Array]} sshKeyIds Optional, list of ssh_key_ids that you would like to be added to the server | ||
* @param {Function} callback [description] | ||
* <b>Show Droplet</b>. | ||
* This method returns full information for a specific droplet ID that is passed in the URL. | ||
* @param {number} id Required, this is the id of your droplet | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletGet | ||
*/ | ||
Digitalocean.prototype.dropletNew = function(name, sizeId, imageId, regionId, sshKeyIds, callback) { | ||
this.get('droplets/new', {name: name, size_id: sizeId, image_id: imageId, region_id: regionId, ssh_key_ids: sshKeyIds}, function(error, body) { | ||
Digitalocean.prototype.dropletGet = function(id, callback) { | ||
this._get('droplets/' + id, {}, function(error, body) { | ||
callback(error, body.droplet); | ||
}); | ||
}; | ||
/** | ||
* Reboot Droplet | ||
* <b>Reboot Droplet</b>. | ||
* This method allows you to reboot a droplet. This is the preferred method to use if a server is not responding. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to reboot | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletReboot | ||
*/ | ||
Digitalocean.prototype.dropletRebootHard = function(id, callback) { | ||
this.get('droplets/' + id + '/reboot/', {}, function(error, body) { | ||
Digitalocean.prototype.dropletReboot = function(id, callback) { | ||
this._get('droplets/' + id + '/reboot/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Power Cycle Droplet | ||
* <b>Power Cycle Droplet</b>. | ||
* This method allows you to power cycle a droplet. This will turn off the droplet and then turn it back on. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to power cycle | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletPowerCycle | ||
*/ | ||
Digitalocean.prototype.dropletPowerCycle = function(id, callback) { | ||
this.get('droplets/' + id + '/power_cycle/', {}, function(error, body) { | ||
this._get('droplets/' + id + '/power_cycle/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Shut Down Droplet | ||
* <b>Shut Down Droplet</b>. | ||
* This method allows you to shutdown a running droplet. The droplet will remain in your account. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to shutdown | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletShutdown | ||
*/ | ||
Digitalocean.prototype.dropletShutdown = function(id, callback) { | ||
this.get('droplets/' + id + '/shutdown/', {}, function(error, body) { | ||
this._get('droplets/' + id + '/shutdown/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Power Off | ||
* <b>Power Off</b>. | ||
* This method allows you to poweroff a running droplet. The droplet will remain in your account. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to power off | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletPowerOff | ||
*/ | ||
Digitalocean.prototype.dropletPowerOff = function(id, callback) { | ||
this.get('droplets/' + id + '/power_off/', {}, function(error, body) { | ||
this._get('droplets/' + id + '/power_off/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Power On | ||
* <b>Power On</b>. | ||
* This method allows you to poweron a powered off droplet. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to power on | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletPowerOn | ||
*/ | ||
Digitalocean.prototype.dropletPowerOn = function(id, callback) { | ||
this.get('droplets/' + id + '/power_on/', {}, function(error, body) { | ||
this._get('droplets/' + id + '/power_on/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Reset Root Password | ||
* <b>Reset Root Password</b>. | ||
* This method will reset the root password for a droplet. Please be aware that this will reboot the droplet to allow resetting the password. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to reset password on | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletPasswordReset | ||
*/ | ||
Digitalocean.prototype.dropletResetRootPassword = function(id, callback) { | ||
this.get('droplets/' + id + '/password_reset/', {}, function(error, body) { | ||
Digitalocean.prototype.dropletPasswordReset = function(id, callback) { | ||
this._get('droplets/' + id + '/password_reset/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Resize Droplet | ||
* <b>Resize Droplet</b>. | ||
* This method allows you to resize a specific droplet to a different size. This will affect the number of processors and memory allocated to the droplet. | ||
* @param {[type]} id [description] | ||
* @param {[type]} sizeId [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to resize | ||
* @param {number} sizeId Required, this is the id of the size you would like the droplet to be resized to | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletResize | ||
*/ | ||
Digitalocean.prototype.dropletResize = function(id, sizeId, callback) { | ||
this.get('droplets/' + id + '/resize/', {size_id: sizeId}, function(error, body) { | ||
this._get('droplets/' + id + '/resize/', { | ||
size_id: sizeId | ||
}, function(error, body) { | ||
callback(error, body.event_id); | ||
@@ -163,10 +206,12 @@ }); | ||
/** | ||
* Take a Snapshot | ||
* <b>Take a Snapshot</b>. | ||
* This method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image. Please be aware this may cause a reboot. | ||
* @param {[type]} id [description] | ||
* @param {[type]} name [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to resize | ||
* @param {Object} optionals { name: "date/time" } | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletSnapshot | ||
*/ | ||
Digitalocean.prototype.dropletSnapshot = function(id, name, callback) { | ||
this.get('droplets/' + id + '/snapshot/', {name: name}, function(error, body) { | ||
Digitalocean.prototype.dropletSnapshot = function(id, optionals, callback) { | ||
this._get('droplets/' + id + '/snapshot/', optionals, function(error, body) { | ||
callback(error, body.event_id); | ||
@@ -177,55 +222,62 @@ }); | ||
/** | ||
* Restore Droplet | ||
*This method allows you to restore a droplet with a previous image or snapshot. This will be a mirror copy of the image or snapshot to your droplet. Be sure you have backed up any necessary information prior to restore. | ||
* @param {[type]} id [description] | ||
* @param {[type]} imageId [description] | ||
* @param {Function} callback [description] | ||
* <b>Restore Droplet</b>. | ||
* This method allows you to restore a droplet with a previous image or snapshot. This will be a mirror copy of the image or snapshot to your droplet. Be sure you have backed up any necessary information prior to restore. | ||
* @param {number} id Required, this is the id of your droplet that you want to restore | ||
* @param {number} imageId Required, this is the id of the image you would like to use to restore your droplet with | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletRestore | ||
*/ | ||
Digitalocean.prototype.dropletRestore = function(id, imageId, callback) { | ||
this.get('droplets/' + id + '/restore/', {image_id: imageId}, function(error, body) { | ||
this._get('droplets/' + id + '/restore/', { | ||
image_id: imageId | ||
}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Rebuild Droplet | ||
* <b>Rebuild Droplet</b>. | ||
* This method allows you to reinstall a droplet with a default image. This is useful if you want to start again but retain the same IP address for your droplet. | ||
* @param {[type]} id [description] | ||
* @param {[type]} imageId [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of your droplet that you want to rebuild | ||
* @param {number} imageId Required, this is the id of the image you would like to use to rebuild your droplet with | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletRebuild | ||
*/ | ||
Digitalocean.prototype.dropletRebuild = function(id, imageId, callback) { | ||
this.get('droplets/' + id + '/rebuild/', {image_id: imageId}, function(error, body) { | ||
this._get('droplets/' + id + '/rebuild/', { | ||
image_id: imageId | ||
}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Enable Automatic Backups | ||
* This method enables automatic backups which run in the background daily to backup your droplet's data. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* <b>Rename Droplet</b>. | ||
* This method renames the droplet to the specified name. | ||
* @param {number} id Required, this is the id of your droplet that you want to rename | ||
* @param {string} name Required, new name of the droplet | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletRename | ||
*/ | ||
Digitalocean.prototype.dropletBackupEnable = function(id, callback) { | ||
this.get('droplets/' + id + '/enable_backups/', {}, function(error, body) { | ||
Digitalocean.prototype.dropletRename = function(id, name, callback) { | ||
this._get('droplets/' + id + '/rename/', { | ||
name: name | ||
}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Disable Automatic Backups | ||
* This method disables automatic backups from running to backup your droplet's data. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
*/ | ||
Digitalocean.prototype.dropletBackupDisable = function(id, callback) { | ||
this.get('droplets/' + id + '/disable_backups/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Destroy Droplet | ||
* <b>Destroy Droplet</b>. | ||
* This method destroys one of your droplets - this is irreversible. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of the droplet you want to destroy | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method dropletDestroy | ||
*/ | ||
Digitalocean.prototype.dropletDestroy = function(id, callback) { | ||
this.get('droplets/' + id + '/destroy/', {}, function(error, body) { | ||
this._get('droplets/' + id + '/destroy/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
@@ -235,9 +287,12 @@ }); | ||
/** | ||
* All Regions | ||
* <b>All Regions</b>. | ||
* This method will return all the available regions within the Digital Ocean cloud. | ||
* @param {Function} callback [description] | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method regionGetAll | ||
*/ | ||
Digitalocean.prototype.regionGetAll = function(callback) { | ||
this.get('regions/', {}, function(error, body) { | ||
this._get('regions/', {}, function(error, body) { | ||
callback(error, body.regions); | ||
@@ -248,41 +303,90 @@ }); | ||
/** | ||
* All Images | ||
* This method returns all the available images that can be accessed by your client ID. You will have access to all public images by default, and any snapshots or backups that you have created in your own account. | ||
* @param {Function} callback [description] | ||
* @private | ||
* @param {string} filter Optional, String, either "my_images" or "global" | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method _images | ||
*/ | ||
Digitalocean.prototype.imageGetAll = function(callback) { | ||
this.get('images/', {}, function(error, body) { | ||
Digitalocean.prototype._images = function(filter, callback) { | ||
this._get('images/', { | ||
filter: filter | ||
}, function(error, body) { | ||
callback(error, body.images); | ||
}); | ||
}; | ||
/** | ||
* <b>All Images</b>. | ||
* This method returns all the available images that can be accessed by your client ID. You will have access to all public images by default, and any snapshots or backups that you have created in your own account. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method imageGetAll | ||
*/ | ||
Digitalocean.prototype.imageGetAll = function(callback) { | ||
this._images(null, callback); | ||
}; | ||
/** | ||
* <b>Global images</b>. | ||
* This method returns all public images. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method imageGetGlobal | ||
*/ | ||
Digitalocean.prototype.imageGetGlobal = function(callback) { | ||
this.get('images/', {filter: 'global'}, function(error, body) { | ||
callback(error, body.images); | ||
}); | ||
this._images('global', callback); | ||
}; | ||
/** | ||
* <b>Mine images</b>. | ||
* This method returns snapshots or backups that you have created in your own account. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method imageGetMine | ||
*/ | ||
Digitalocean.prototype.imageGetMine = function(callback) { | ||
this.get('images/', {filter: 'my_images'}, function(error, body) { | ||
callback(error, body.images); | ||
}); | ||
this._images('my_images', callback); | ||
}; | ||
/** | ||
* Show Image | ||
* <b>Show Image</b>. | ||
* This method displays the attributes of an image. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of the image you would like to use to rebuild your droplet with | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method imageGet | ||
*/ | ||
Digitalocean.prototype.imageGet = function(id, callback) { | ||
this.get('images/' + id + '/', {}, function(error, body) { | ||
this._get('images/' + id + '/', {}, function(error, body) { | ||
callback(error, body.image); | ||
}); | ||
}; | ||
/** | ||
* Destroy Image | ||
* <b>Destroy Image</b>. | ||
* This method allows you to destroy an image. There is no way to restore a deleted image so be careful and ensure your data is properly backed up. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of the image you would like to destroy | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method imageDestroy | ||
*/ | ||
Digitalocean.prototype.imageDestroy = function(id, callback) { | ||
this.get('images/' + id + '/destroy/', {}, function(error, body) { | ||
this._get('images/' + id + '/destroy/', {}, function(error, body) { | ||
callback(error, body.status); | ||
}); | ||
}; | ||
/** | ||
* <b>Transfer Image</b>. | ||
* This method allows you to transfer an image to a specified region. | ||
* @param {number} id Required, this is the id of the image you would like to transfer. | ||
* @param {number} regionId Required, this is the id of the region to which you would like to transfer. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method imageTransfer | ||
*/ | ||
Digitalocean.prototype.imageTransfer = function(id, regionId, callback) { | ||
this._get('images/' + id + '/transfer/', { | ||
region_id: regionId | ||
}, function(error, body) { | ||
callback(error, body.event_id); | ||
@@ -292,53 +396,75 @@ }); | ||
/** | ||
* All SSH Keys | ||
* <b>All SSH Keys</b>. | ||
* This method lists all the available public SSH keys in your account that can be added to a droplet. | ||
* @param {Function} callback [description] | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method sshKeyGetAll | ||
*/ | ||
Digitalocean.prototype.sshKeyGetAll = function(callback) { | ||
this.get('ssh_keys/', {}, function(error, body) { | ||
this._get('ssh_keys/', {}, function(error, body) { | ||
callback(error, body.ssh_keys); | ||
}); | ||
}; | ||
/** | ||
* Show SSH Key | ||
* This method shows a specific public SSH key in your account that can be added to a droplet. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* <b>Add SSH Key</b>. | ||
* This method allows you to add a new public SSH key to your account. | ||
* @param {string} name Required, the name you want to give this SSH key. | ||
* @param {string} pubKey Required, the actual public SSH key. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method sshKeyAdd | ||
*/ | ||
Digitalocean.prototype.sshKeyGet = function(id, callback) { | ||
this.get('ssh_keys/' + id + '/', {}, function(error, body) { | ||
Digitalocean.prototype.sshKeyAdd = function(name, pubKey, callback) { | ||
this._get('ssh_keys/new/', { | ||
name: name, | ||
ssh_pub_key: pubKey | ||
}, function(error, body) { | ||
callback(error, body.ssh_key); | ||
}); | ||
}; | ||
/** | ||
* Add SSH Key | ||
* This method allows you to add a new public SSH key to your account. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* <b>Show SSH Key</b>. | ||
* This method shows a specific public SSH key in your account that can be added to a droplet. | ||
* @param {number} id Required, this is the id of the ssh key you would like to get information on. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method sshKeyGet | ||
*/ | ||
Digitalocean.prototype.sshKeyAdd = function(name, pubKey, callback) { | ||
this.get('ssh_keys/new/', {name: name, ssh_pub_key: pubKey}, function(error, body) { | ||
Digitalocean.prototype.sshKeyGet = function(id, callback) { | ||
this._get('ssh_keys/' + id + '/', {}, function(error, body) { | ||
callback(error, body.ssh_key); | ||
}); | ||
}; | ||
/** | ||
* Edit SSH Key | ||
* <b>Edit SSH Key</b>. | ||
* This method allows you to modify an existing public SSH key in your account. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {type} id Required, this is the id of the ssh key you would like to edit. | ||
* @param {string} pubKey Required, the public SSH key. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method sshKeyEdit | ||
*/ | ||
Digitalocean.prototype.sshKeyEdit = function(id, pubKey, callback) { | ||
this.get('ssh_keys/' + id + '/edit/', {ssh_pub_key: pubKey}, function(error, body) { | ||
this._get('ssh_keys/' + id + '/edit/', { | ||
ssh_pub_key: pubKey | ||
}, function(error, body) { | ||
callback(error, body.event_id); | ||
}); | ||
}; | ||
/** | ||
* Destroy SSH Key | ||
* <b>Destroy SSH Key</b>. | ||
* This method will delete the SSH key from your account. | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
* @param {number} id Required, this is the id of the ssh key you would like to destroy. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method sshKeyDestroy | ||
*/ | ||
Digitalocean.prototype.sshKeyDestroy = function(id, callback) { | ||
this.get('ssh_keys/' + id + '/destroy/', {}, function(error, body) { | ||
this._get('ssh_keys/' + id + '/destroy/', {}, function(error, body) { | ||
callback(error, body.event_id); | ||
@@ -348,9 +474,12 @@ }); | ||
/** | ||
* All Sizes | ||
* <b>All Sizes</b>. | ||
* This method returns all the available sizes that can be used to create a droplet. | ||
* @param {Function} callback [description] | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method sizeGetAll | ||
*/ | ||
Digitalocean.prototype.sizeGetAll = function(callback) { | ||
this.get('sizes/', {}, function(error, body) { | ||
this._get('sizes/', {}, function(error, body) { | ||
callback(error, body.sizes); | ||
@@ -360,12 +489,165 @@ }); | ||
/** | ||
* Show event | ||
* This method returns details of a event | ||
* @param {[type]} id [description] | ||
* @param {Function} callback [description] | ||
*/ | ||
Digitalocean.prototype.eventGet = function(id,callback){ | ||
this.get('events/' + id ,{},function(error,body){ | ||
callback(error,body.event); | ||
* <b>All Domains</b>. | ||
* This method returns all of your current domains. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainGetAll | ||
*/ | ||
Digitalocean.prototype.domainGetAll = function(callback) { | ||
this._get('domains/', {}, function(error, body) { | ||
callback(error, body.domains); | ||
}); | ||
} | ||
}; | ||
/** | ||
* <b>New Domain</b>. | ||
* This method creates a new domain name with an A record for the specified [ip_address]. | ||
* @param {string} name Required, name of the domain. | ||
* @param {string} ipAddress Required, ip address for the domain's initial a record. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainNew | ||
*/ | ||
Digitalocean.prototype.domainNew = function(name, ipAddress, callback) { | ||
this._get('domains/new', { | ||
name: name, | ||
ip_address: ipAddress | ||
}, function(error, body) { | ||
callback(error, body.domain); | ||
}); | ||
}; | ||
/** | ||
* <b>Domain Show</b>. | ||
* This method returns the specified domain. | ||
* @param {(number|string)} id Required, Integer or Domain Name (e.g. domain.com), specifies the domain to display. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainGet | ||
*/ | ||
Digitalocean.prototype.domainGet = function(id, callback) { | ||
this._get('domains/' + id, {}, function(error, body) { | ||
callback(error, body.domain); | ||
}); | ||
}; | ||
/** | ||
* <b>Destroy Domain</b>. | ||
* This method deletes the specified domain. | ||
* @param {(number|string)} id Required, Integer or Domain Name (e.g. domain.com), specifies the domain to display. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainDestroy | ||
*/ | ||
Digitalocean.prototype.domainDestroy = function(id, callback) { | ||
this._get('domains/' + id + '/destroy/', {}, function(error, body) { | ||
callback(error, body.status); | ||
}); | ||
}; | ||
/** | ||
* <b>All Domain Records</b>. | ||
* This method returns all of your current domain records. | ||
* @param {(number|string)} id Required, Integer or Domain Name (e.g. domain.com), specifies the domain to display. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainRecordGetAll | ||
*/ | ||
Digitalocean.prototype.domainRecordGetAll = function(id, callback) { | ||
this._get('domains/' + id + '/records/', {}, function(error, body) { | ||
callback(error, body.records); | ||
}); | ||
}; | ||
/** | ||
* <b>New Domain Record</b>. | ||
* This method creates a new domain name with an A record for the specified [ip_address]. | ||
* @param {(number|string)} id Required, Integer or Domain Name (e.g. domain.com), specifies the domain to display. | ||
* @param {string} recordType Required, the type of record you would like to create. 'A', 'CNAME', 'NS', 'TXT', 'MX' or 'SRV' | ||
* @param {string} data Required, this is the value of the record | ||
* @param {Object} optionals { name, priority, port, weight }<br>- name is required for 'A', 'CNAME', 'TXT' and 'SRV' records<br>- priority is required for 'SRV' and 'MX' records<br>- port is required for 'SRV' records<br>- weight is required for 'SRV' records | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainRecordNew | ||
*/ | ||
Digitalocean.prototype.domainRecordNew = function(id, recordType, data, optionals, callback) { | ||
var options = { | ||
record_type: recordType, | ||
data: data | ||
}; | ||
extend(options, optionals); | ||
this._get('domains/' + id + '/records/new', options, function(error, body) { | ||
callback(error, body.domain_record); | ||
}); | ||
}; | ||
/** | ||
* <b>Show Domain Record</b>. | ||
* This method returns the specified domain record. | ||
* @param {(number|string)} id Required, Integer or Domain Name (e.g. domain.com), specifies the domain for which to retrieve a record. | ||
* @param {number} recordId Required, specifies the record_id to retrieve. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainRecordGet | ||
*/ | ||
Digitalocean.prototype.domainRecordGet = function(id, recordId, callback) { | ||
this._get('domains/' + id + '/records/' + recordId, {}, function(error, body) { | ||
callback(error, body.record); | ||
}); | ||
}; | ||
/** | ||
* <b>Edit Domain Record</b>. | ||
* This method edits an existing domain record. | ||
* @param {(number|string)} id Required, Integer or Domain Name (e.g. domain.com), specifies the domain to display. | ||
* @param {number} recordId Required, specifies the record to update. | ||
* @param {string} recordType Required, the type of record you would like to create. 'A', 'CNAME', 'NS', 'TXT', 'MX' or 'SRV' | ||
* @param {string} data Required, this is the value of the record | ||
* @param {Object} optionals { name, priority, port, weight }<br>- name is required for 'A', 'CNAME', 'TXT' and 'SRV' records<br>- priority is required for 'SRV' and 'MX' records<br>- port is required for 'SRV' records<br>- weight is required for 'SRV' records | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainRecordEdit | ||
*/ | ||
Digitalocean.prototype.domainRecordEdit = function(id, recordId, recordType, data, optionals, callback) { | ||
var options = { | ||
record_type: recordType, | ||
data: data | ||
}; | ||
extend(options, optionals); | ||
this._get('domains/' + id + '/records/' + recordId + '/edit', options, function(error, body) { | ||
callback(error, body.domain_record); | ||
}); | ||
}; | ||
/** | ||
* <b>Destroy Domain Record</b>. | ||
* This method deletes the specified domain record. | ||
* @param {(number|string)} id Required, Integer or Domain Name (e.g. domain.com), specifies the domain for which to destroy a record. | ||
* @param {number} recordId Required, specifies which record to destroy. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method domainRecordDestroy | ||
*/ | ||
Digitalocean.prototype.domainRecordDestroy = function(id, recordId, callback) { | ||
this._get('domains/' + id + '/records/' + recordId + '/destroy', {}, function(error, body) { | ||
callback(error, body.status); | ||
}); | ||
}; | ||
/** | ||
* <b>Show event</b>. | ||
* This method is primarily used to report on the progress of an event by providing the percentage of completion. | ||
* @param {number} id Required, this is the id of the event you would like more information about. | ||
* @callback complete | ||
* @memberof Digitalocean | ||
* @method eventGet | ||
*/ | ||
Digitalocean.prototype.eventGet = function(id, callback) { | ||
this._get('events/' + id, {}, function(error, body) { | ||
callback(error, body.event); | ||
}); | ||
}; |
{ | ||
"name": "digitalocean-api", | ||
"version": "0.0.4", | ||
"author": "Matej Simek <email@matejsimek.cz>", | ||
"description": "DigitalOcean API wrapper", | ||
"keywords": ["digitalocean", "digitalocean-api"], | ||
"homepage": "https://github.com/enzy/digitalocean-api", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/enzy/digitalocean-api.git" | ||
}, | ||
"main": "./lib/digitalocean.js", | ||
"engines": { | ||
"node": "~0.8.20" | ||
}, | ||
"dependencies": { | ||
"xtend": "~1.0.3", | ||
"request": "~2.12.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.8.1" | ||
} | ||
"name": "digitalocean-api", | ||
"version": "0.1.0", | ||
"author": "Matěj Šimek <email@matejsimek.cz> (www.matejsimek.cz)", | ||
"description": "DigitalOcean API wrapper", | ||
"contributors": [ | ||
{ | ||
"name": "Ryan Sullivan", | ||
"email": "ryan@toptiertech.com" | ||
}, | ||
{ | ||
"name": "Eric Vicenti", | ||
"email": "ericvicenti@gmail.com" | ||
}, | ||
{ | ||
"name": "Manuel Stofer", | ||
"email": "manuel@takimata.ch" | ||
}, | ||
{ | ||
"name": "Pahan Sarathchandra", | ||
"email": "pahan123@gmail.com" | ||
} | ||
], | ||
"keywords": [ | ||
"digitalocean", | ||
"digitalocean-api" | ||
], | ||
"homepage": "https://github.com/enzy/digitalocean-api", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/enzy/digitalocean-api.git" | ||
}, | ||
"main": "./lib/digitalocean.js", | ||
"engines": { | ||
"node": ">=0.8.0" | ||
}, | ||
"dependencies": { | ||
"xtend": "2.x", | ||
"request": "2.x" | ||
}, | ||
"devDependencies": { | ||
"mocha": "latest", | ||
"grunt": "~0.4.2", | ||
"grunt-jsdoc": "~0.5.1" | ||
} | ||
} |
@@ -34,2 +34,4 @@ # digitalocean-api | ||
More [detailed documentation](http://enzy.github.io/digitalocean-api/Digitalocean.html) generated from the source code is available. | ||
Convention for callback arguments: `callback(error, data)` | ||
@@ -41,5 +43,5 @@ | ||
dropletGetAll(callback) | ||
dropletNew(name, sizeId, imageId, regionId, optionals, callback) | ||
dropletGet(id, callback) | ||
dropletNew(name, sizeId, imageId, regionId, sshKeyIds, callback) | ||
dropletRebootHard(id, callback) | ||
dropletReboot(id, callback) | ||
dropletPowerCycle(id, callback) | ||
@@ -49,16 +51,15 @@ dropletShutdown(id, callback) | ||
dropletPowerOn(id, callback) | ||
dropletResetRootPassword(id, callback) | ||
dropletPasswordReset(id, callback) | ||
dropletResize(id, sizeId, callback) | ||
dropletSnapshot(id, name, callback) | ||
dropletSnapshot(id, optionals, callback) | ||
dropletRestore(id, imageId, callback) | ||
dropletRebuild(id, imageId, callback) | ||
dropletBackupEnable(id, callback) | ||
dropletBackupDisable(id, callback) | ||
dropletRename(id, name, callback) | ||
dropletDestroy(id, callback) | ||
``` | ||
### Sizes | ||
### Regions | ||
```js | ||
sizeGetAll(callback) | ||
regionGetAll(callback) | ||
``` | ||
@@ -74,2 +75,3 @@ | ||
imageDestroy(id, callback) | ||
imageTransfer(id, regionId, callback) | ||
``` | ||
@@ -81,4 +83,4 @@ | ||
sshKeyGetAll(callback) | ||
sshKeyAdd(name, pubKey, callback) | ||
sshKeyGet(id, callback) | ||
sshKeyAdd(name, pubKey, callback) | ||
sshKeyEdit(id, pubKey, callback) | ||
@@ -88,8 +90,22 @@ sshKeyDestroy(id, callback) | ||
### Regions | ||
### Sizes | ||
```js | ||
regionGetAll(callback) | ||
sizeGetAll(callback) | ||
``` | ||
### Domains | ||
```js | ||
domainGetAll(callback) | ||
domainNew(name, ipAddress, callback) | ||
domainGet(id, callback) | ||
domainDestroy(id, callback) | ||
domainRecordGetAll(id, callback) | ||
domainRecordNew(id, recordType, data, optionals, callback) | ||
domainRecordGet(id, recordId, callback) | ||
domainRecordEdit(id, recordId, recordType, data, optionals, callback) | ||
domainRecordDestroy(id, recordId, callback) | ||
``` | ||
### Events | ||
@@ -96,0 +112,0 @@ ```js |
var fs = require('fs'); | ||
var path = require('path'); | ||
var config = JSON.parse(fs.readFileSync(path.normalize(__dirname + '/config.json', 'utf8'))); | ||
var config = JSON.parse(fs.readFileSync(path.normalize(__dirname + '/config.js', 'utf8'))); | ||
describe('DigitalOcean API Wrapper', function() { | ||
describe('DigitalOcean API', function() { | ||
var Digitalocean = require('../lib/digitalocean'); | ||
var api = new Digitalocean(config.clientId, config.apiKey); | ||
describe('connection test', function() { | ||
describe('Droplet test', function() { | ||
it('should get all droplets', function(done) { | ||
api.dropletGetAll(done); | ||
}); | ||
}); | ||
describe('Region test', function() { | ||
it('should get all regions', function(done) { | ||
api.regionGetAll(done); | ||
}); | ||
}); | ||
describe('Image test', function() { | ||
it('should get all images', function(done) { | ||
this.timeout(8000); | ||
api.imageGetAll(done); | ||
}); | ||
it('should get global images', function(done) { | ||
this.timeout(8000); | ||
api.imageGetGlobal(done); | ||
}); | ||
it('should get my images', function(done) { | ||
api.imageGetMine(done); | ||
}); | ||
}); | ||
describe('SSH test', function() { | ||
it('should get all sshKeys', function(done) { | ||
api.sshKeyGetAll(done); | ||
}); | ||
}); | ||
describe('Size test', function() { | ||
it('should get all sizes', function(done) { | ||
@@ -40,4 +49,8 @@ api.sizeGetAll(done); | ||
}); | ||
}); | ||
describe('Domain test', function() { | ||
it('should get all domains', function(done) { | ||
api.domainGetAll(done); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27808
7
657
109
3
1
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxtend@2.2.0(transitive)
- Removedrequest@2.12.0(transitive)
- Removedxtend@1.0.3(transitive)
Updatedrequest@2.x
Updatedxtend@2.x