Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
115 changes: 68 additions & 47 deletions lib/webfaction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var xmlrpc = require('xmlrpc');
var util = require('util');
var _ = require('underscore');
var q = require('q');

var client = xmlrpc.createSecureClient('https://api.webfaction.com');

Expand All @@ -16,50 +17,64 @@ var Webfaction = function(username, password) {
* Helpers
*/

Webfaction.prototype.methodCall = function(method, params, callback) {
Webfaction.prototype.methodCall = function(method, params) {
var defer = q.defer();

if (!params) params = [];
params.unshift(this.session_id);
client.methodCall(method, params, function (error, value) {
if (error) {
console.log(error);

client.methodCall(method, params, function (err, value) {
if (err) {
defer.reject(err);
} else {
defer.resolve(value);
}
callback(value);
});

return defer.promise
};

/*
* API - General
*/

Webfaction.prototype.login = function(callback) {
client.methodCall('login', [this.username, this.password], (function (error, value) {
this.session_id = value[0];
this.account = value[1];
callback(value);
}).bind(this));
Webfaction.prototype.login = function() {
var defer = q.defer();

client.methodCall('login', [this.username, this.password], (function (err, value) {
if (err) {
defer.reject(err);
} else {
this.session_id = value[0];
this.account = value[1];
defer.resolve(value);
}
}).bind(this));

return defer.promise;
};

/*
* API - Domains
*/

Webfaction.prototype.createDomain = function(domain, subdomain, callback) {
this.methodCall('create_domain', [domain, subdomain], callback);
Webfaction.prototype.createDomain = function(domain, subdomain) {
return this.methodCall('create_domain', [domain, subdomain]);
};

Webfaction.prototype.deleteDomain = function(domain, subdomain, callback) {
this.methodCall('delete_domain', [], callback);
Webfaction.prototype.deleteDomain = function(domain, subdomain) {
return this.methodCall('delete_domain', [], callback);
};

Webfaction.prototype.listDomains = function(callback) {
this.methodCall('list_domains', [], callback);
Webfaction.prototype.listDomains = function() {
return this.methodCall('list_domains', []);
};

/*
* API - Applications
*/

Webfaction.prototype.createApp = function(opts, callback) {
Webfaction.prototype.createApp = function(opts) {
var optionalDefaults = {
autostart: false,
extra_info: '',
Expand All @@ -83,84 +98,87 @@ Webfaction.prototype.createApp = function(opts, callback) {
params.push(opts.autostart);
}

this.methodCall('create_app', params, callback);
return this.methodCall('create_app', params);

};

Webfaction.prototype.deleteApp = function(appName, callback) {
this.methodCall('delete_app', [appName], callback);
Webfaction.prototype.deleteApp = function(appName) {
return this.methodCall('delete_app', [appName]);
};

Webfaction.prototype.listApps = function(callback) {
this.methodCall('list_apps', [], callback);
Webfaction.prototype.listApps = function() {
return this.methodCall('list_apps', []);
};

Webfaction.prototype.listAppTypes = function(callback) {
this.methodCall('list_app_types', [], callback);
Webfaction.prototype.listAppTypes = function() {
return this.methodCall('list_app_types', []);
};

/*
* API - Websites
* API - Database
*/

Webfaction.prototype.createWebsite = function(opts, callback) {
Webfaction.prototype.createDatabase = function(opts) {
var params = [opts.name, opts.type, opts.password];
return this.methodCall('create_db', params);
};

var params = [opts.website_name, opts.ip, opts.https, opts.subdomains];
/*
* API - Websites
*/

opts.site_apps.forEach(function(val) {
params.push(val);
});
Webfaction.prototype.createWebsite = function(opts) {

this.methodCall('create_website', params, callback);
var params = [opts.website_name, opts.ip, opts.https, opts.subdomains, opts.site_apps];
return this.methodCall('create_website', params);
};

Webfaction.prototype.updateWebsite = function(opts, callback) {
Webfaction.prototype.updateWebsite = function(opts) {

var params = [opts.website_name, opts.ip, opts.https, opts.subdomains];

opts.site_apps.forEach(function(val) {
params.push(val);
});

this.methodCall('update_website', params, callback);
return this.methodCall('update_website', params);
};

Webfaction.prototype.deleteWebsite = function(opts, callback) {
Webfaction.prototype.deleteWebsite = function(opts) {
var params = [opts.website_name, opts.ip];

if (opts.https === true) {
params.push(opts.https);
}

this.methodCall('delete_website', params, callback);
return this.methodCall('delete_website', params);
};

Webfaction.prototype.listWebsites = function(callback) {
this.methodCall('list_websites', [], callback);
Webfaction.prototype.listWebsites = function() {
return this.methodCall('list_websites', []);
};

/*
* API - Cron
*/

Webfaction.prototype.createCronjob = function(line, callback) {
this.methodCall('create_cronjob', [line], callback);
Webfaction.prototype.createCronjob = function(line) {
return this.methodCall('create_cronjob', [line]);
};

Webfaction.prototype.deleteCronjob = function(line, callback) {
this.methodCall('delete_cronjob', [line], callback);
Webfaction.prototype.deleteCronjob = function(line) {
return this.methodCall('delete_cronjob', [line]);
};

/*
* API - Servers
*/

Webfaction.prototype.listIps = function(callback) {
this.methodCall('list_ips', [], callback);
Webfaction.prototype.listIps = function() {
return this.methodCall('list_ips', []);
};

Webfaction.prototype.listMachines = function(callback) {
this.methodCall('list_machines', [], callback);
Webfaction.prototype.listMachines = function() {
return this.methodCall('list_machines', []);
};

/*
Expand All @@ -171,5 +189,8 @@ Webfaction.prototype.listMachines = function(callback) {
* API - Misc
*/

Webfaction.prototype.system = function(cmd) {
return this.methodCall('system', [cmd]);
};

module.exports = Webfaction;
23 changes: 0 additions & 23 deletions node_modules/underscore/LICENSE

This file was deleted.

22 changes: 0 additions & 22 deletions node_modules/underscore/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions node_modules/underscore/package.json

This file was deleted.

Loading