function getRequest(url, key) {
return $.ajax({
url: url,
contentType: 'application/json',
type: 'get',
beforeSend: function(xhr){
xhr.setRequestHeader('Authorization', 'Bearer ' + key);
}
});
}
function getDroplets(key, callback) {
return getRequest('https://api.digitalocean.com/v2/droplets', key).then(function() {
var droplets = response.droplets;
var numDroplets = droplets.length;
return {
droplets: droplets,
numDroplets: numDroplets
}
});
}