Skip to content
Browse files

[api] Start stubbing out clients and common methods

  • Loading branch information...
1 parent ab8d16a commit 641b226a77f822b4119b6ac038a58770b1f07eda @indexzero indexzero committed Feb 21, 2011
Showing with 124 additions and 8 deletions.
  1. +2 −8 README.md
  2. +28 −0 lib/jitsu.js
  3. +33 −0 lib/jitsu/apps.js
  4. +54 −0 lib/jitsu/client.js
  5. +7 −0 lib/jitsu/config.js
View
10 README.md
@@ -1,11 +1,5 @@
-
-
-
-# noc
-(**N**odejitsu **O**perations **C**ontroller)
-
-## noc is a CLI tool for easily deploying node.js applications on the Nodejitsu platform
-
+# jitsu
+CLI tool for easily deploying node.js applications on the Nodejitsu platform
## INSTALLATION
View
28 lib/jitsu.js
@@ -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');
View
33 lib/jitsu/apps.js
@@ -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) {
+
+};
View
54 lib/jitsu/client.js
@@ -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);
+ });
+};
View
7 lib/jitsu/config.js
@@ -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.
Something went wrong with that request. Please try again.