Permalink
Browse files

Initial commit via nodester-cli

  • Loading branch information...
1 parent 851f65d commit 551426ab9651e10617c1c54d5d31a5e9d69471e3 @contra contra committed Oct 25, 2011
Showing with 24 additions and 252 deletions.
  1. +1 −0 contratest/.gitignore
  2. +5 −0 contratest/server.js
  3. +0 −230 nodester.js
  4. +18 −22 package.json
View
1 contratest/.gitignore
@@ -0,0 +1 @@
+.nodester.appconfig
View
5 contratest/server.js
@@ -0,0 +1,5 @@
+var http = require('http');
+http.createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('Hello World\nApp (contratest) is running..');
+}).listen(12344);
View
230 nodester.js
@@ -1,230 +0,0 @@
-var request = require('request');
-var querystring = require('querystring');
-var fs = require('fs');
-var sys = require('sys');
-
-var headers = {
- 'Content-Type': 'application/x-www-form-urlencoded'
-};
-var nodester = function (username, password, basehost, secure) {
- if (typeof basehost != 'undefined') this.basehost = basehost;
- else this.basehost = 'api.nodester.com';
- if (typeof secure != 'undefined' && secure == true) this.proto = 'https://';
- else this.proto = 'http://';
- this.username = username;
- this.password = password;
- if (typeof this.username != 'undefined' && typeof this.password != 'undefined' && this.username.length > 0 && this.password.length > 0) {
- var userbits = this.username + ":" + this.password + "@";
- } else {
- var userbits = "";
- }
- this.baseurl = this.proto + userbits + this.basehost + "/";
- };
-
-function process_response(cb, errfn) {
- return function (err, response, body) {
- var errCode = null;
- if (!err && response && response.statusCode >= 400) {
- errCode = response.statusCode;
- }
- var data = {};
- try {
- data = JSON.parse(body);
- } catch (e) {
- if (!err) err = {
- message: body
- };
- data = body;
- }
- if (errfn && !err) {
- err = errfn(data);
- } else if (!err && data.status && !data.message && !/^success/.exec(data.status)) {
- err = {
- message: data.status
- }
- }
- if (errCode) {
- if (err) {
- err.code = errCode;
- err.message = '[HTTP ' + errCode + '] ' + err.message;
- } else {
- err = {
- code: errCode,
- message: "HTTP Error " + errCode
- };
- }
- }
- original = {response: body, errorCode: errCode };
- cb(err, data, original);
- }
-}
-
-nodester.prototype.request = function (method, path, body, cb) {
- request({
- uri: this.baseurl + path,
- method: method,
- body: querystring.stringify(body),
- headers: headers,
- proxy: process.env.http_proxy
- }, process_response(cb));
-}
-
-nodester.prototype.get = function (path, cb) {
- this.request('GET', path, null, cb);
-}
-nodester.prototype.post = function (path, body, cb) {
- this.request('POST', path, body, cb);
-}
-nodester.prototype.put = function (path, body, cb) {
- this.request('PUT', path, body, cb);
-}
-nodester.prototype.del = function (path, body, cb) {
- this.request('DELETE', path, body, cb);
-}
-
-nodester.prototype.coupon_request = function (email, cb) {
- this.post('coupon', {
- email: email
- }, cb)
-}
-
-nodester.prototype.user_create = function (user, pass, email, rsakey, coupon, cb) {
- fs.readFile(rsakey, 'ascii', function (err, rsadata) {
- if (err) cb(err, null);
- if (rsadata.length < 40) {
- cb({
- message: "Error: Invalid SSH key file."
- });
- } else {
- this.post('user', {
- user: user,
- password: pass,
- email: email,
- coupon: coupon,
- rsakey: rsadata
- }, cb);
- }
- }.bind(this));
-};
-
-nodester.prototype.user_delete = function (user, cb) {
- this.del('user', {
- user: user
- }, cb);
-};
-
-nodester.prototype.user_sendtoken = function (some_user, cb) {
- this.post('reset_password', {
- user: some_user
- }, cb);
-};
-
-nodester.prototype.user_setpass = function (token, a_password, cb) {
- this.put('reset_password/' + token, {
- password: a_password
- }, cb);
-};
-
-nodester.prototype.user_setkey = function (rsakey, cb) {
- this.put('user', {
- rsakey: rsakey
- }, cb);
-};
-
-nodester.prototype.apps_list = function (cb) {
- this.get('apps', cb);
-};
-
-nodester.prototype.app_create = function (name, start, cb) {
- this.post('app', {
- appname: name,
- start: start
- }, cb);
-};
-
-nodester.prototype.status = function (cb) {
- this.get('status', cb);
-};
-
-
-
-nodester.prototype.app_running = function (name, running, cb) {
- this.put('app', {
- appname: name,
- running: running
- }, cb);
-};
-
-nodester.prototype.app_start = function (name, cb) {
- this.app_running(name, "true", cb);
-};
-
-nodester.prototype.app_restart = function (name, cb) {
- this.app_running(name, "restart", cb);
-};
-
-nodester.prototype.app_stop = function (name, cb) {
- this.app_running(name, "false", cb);
-};
-
-nodester.prototype.app_delete = function (name, cb) {
- this.del('app', {
- appname: name
- }, cb);
-};
-
-nodester.prototype.app_gitreset = function (name, cb) {
- this.del('gitreset', {
- appname: name
- }, cb);
-};
-
-nodester.prototype.app_info = function (name, cb) {
- this.get('app/' + name, cb);
-};
-
-nodester.prototype.app_logs = function (name, cb) {
- this.get('applogs/' + name, cb);
-};
-
-nodester.prototype.appnpm_handler = function (name, package, action, cb) {
- this.post('appnpm', {
- appname: name,
- package: package,
- action: action
- }, cb);
-};
-
-nodester.prototype.appnpm_install = function (name, package, cb) {
- this.appnpm_handler(name, package, "install", cb);
-};
-
-nodester.prototype.appnpm_update = function (name, package, cb) {
- this.appnpm_handler(name, package, "update", cb);
-};
-
-nodester.prototype.appnpm_uninstall = function (name, package, cb) {
- this.appnpm_handler(name, package, "uninstall", cb);
-};
-
-
-nodester.prototype.appdomain_add = function (name, domain, cb) {
- this.post('appdomains', {
- appname: name,
- domain: domain
- }, cb);
-};
-
-nodester.prototype.appdomain_delete = function (name, domain, cb) {
- this.del('appdomains', {
- appname: name,
- domain: domain
- }, cb);
-};
-
-
-nodester.prototype.appdomains = function (cb) {
- this.get('appdomains', cb);
-};
-
-exports.nodester = nodester;
View
40 package.json
@@ -1,23 +1,19 @@
{
- "name": "nodester-api",
- "description": "A module to allow interaction with the http://nodester.com/ platform.",
- "version": "0.1.15",
- "homepage": "http://nodester.com/",
- "repository": "git://github.com/nodester/nodester-api.git",
- "author": "Daniel Bartlett <dan@f-box.org> (http://danb-uk.net/)",
- "contributors": [
- "Dav Glass <davglass@gmail.com> @davglass",
- "Chris Matthieu <chris@matthieu.us>",
- "Aaron <aaron@nodester.com>",
- "Contra <contra@nodester.com>",
- "Marcos Oliveira <marcosvm@gmail.com>"
- ],
- "engines": {
- "node": "*"
- },
- "dependencies" : {
- "request": "*",
- "querystring": "*"
- },
- "main": "./nodester.js"
-}
+ "name":"nodester-api",
+ "description":"A library to interact with Nodester",
+ "version":"0.1.16",
+ "homepage":"http://nodester.com/",
+ "repository":"git://github.com/nodester/nodester-api.git",
+ "author":"Contra <contra@nodester.com>",
+
+ "main":"./lib/nodester.js",
+ "dependencies":{
+ "request":"*"
+ },
+ "devDependencies":{
+ "coffee-script":"*"
+ },
+ "engines":{
+ "node":"*"
+ }
+}

0 comments on commit 551426a

Please sign in to comment.