Skip to content

Commit

Permalink
[api] Start stubbing out clients and common methods
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Feb 21, 2011
1 parent ab8d16a commit 641b226
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 8 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,5 @@

# jitsu

CLI tool for easily deploying node.js applications on the Nodejitsu platform

# noc
(**N**odejitsu **O**perations **C**ontroller)

## noc is a CLI tool for easily deploying node.js applications on the Nodejitsu platform



## INSTALLATION ## INSTALLATION


Expand Down
28 changes: 28 additions & 0 deletions lib/jitsu.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* jitsu.js: Top-level include for the jitsu module.
*
* (C) 2010, Nodejitsu Inc.
*
*/

require.paths.unshift(__dirname);

var jitsu = exports;

// Failure HTTP Response codes based
// off of `/lib/broodmother/slave/service.js`
var failCodes jitsu.failCodes = {
400: "Bad Request",
404: "Item not found",
500: "Internal Server Error"
};

// Success HTTP Response codes based
// off of `/lib/broodmother/slave/service.js`
var successCodes = jitsu.successCodes = {
200: "OK",
201: "Created"
};

jitsu.client = require('jitsu/client');
jitsu.apps = require('jitsu/apps');
33 changes: 33 additions & 0 deletions lib/jitsu/apps.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* app.js: Client for the Nodejitsu apps API.
*
* (C) 2010, Nodejitsu Inc.
*
*/

var util = require('util'),
jitsu = require('jitsu');

var Apps = exports.Apps = function (options) {
jitsu.Client.call(this, options);
};

util.inherits(Apps, jitsu.Client);

Apps.prototype.list = function (callback) {

};

Apps.prototype.create = function (app, callback) {
this._request('POST', ['apps' app.name], app, callback, function (err, res, body) {

});
};

Apps.prototype.update = function (attrs, callback) {

};

Apps.prototype.destory = function (name, callback) {

};
54 changes: 54 additions & 0 deletions lib/jitsu/client.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* client.js: Client base for the Nodejitsu API clients.
*
* (C) 2010, Nodejitsu Inc.
*
*/

var request = require('request'),
jitsu = require('jitsu');

var Client = exports.Client = function (options) {

};

Client.prototype._request = function (method, uri /* variable arguments */) {
var options, args = Array.prototype.slice.call(arguments),
success = args.pop(),
callback = args.pop(),
body = typeof args[args.length - 1] === 'object' && args.pop();

options = {
method: method || 'GET',
uri: this.remoteUri + uri,
headers: {
'Content-Type': 'application/json'
}
};

if (body) {
options.body = JSON.stringify(body);
}

request(options, function (err, response, body) {
if (err) {
return callback(err);
}

try {
var statusCode = response.statusCode.toString(),
result = JSON.parse(body);
}
catch (ex) {
// Ignore Errors
}

if (Object.keys(jitsu.failCodes).indexOf(statusCode) !== -1) {
var error = new Error('Broodmother Error (' + statusCode + '): ' + jitsu.failCodes[statusCode]);
error.result = result;
return callback(error);
}

success(response, result);
});
};
7 changes: 7 additions & 0 deletions lib/jitsu/config.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* config.js: Configuration for the jitsu CLI.
*
* (C) 2010, Nodejitsu Inc.
*
*/

0 comments on commit 641b226

Please sign in to comment.