Skip to content
This repository
Browse code

[api] Start stubbing out clients and common methods

  • Loading branch information...
commit 641b226a77f822b4119b6ac038a58770b1f07eda 1 parent ab8d16a
Charlie Robbins indexzero authored
10 README.md
Source Rendered
... ... @@ -1,11 +1,5 @@
1   -
2   -
3   -
4   -# noc
5   -(**N**odejitsu **O**perations **C**ontroller)
6   -
7   -## noc is a CLI tool for easily deploying node.js applications on the Nodejitsu platform
8   -
  1 +# jitsu
  2 +CLI tool for easily deploying node.js applications on the Nodejitsu platform
9 3
10 4 ## INSTALLATION
11 5
28 lib/jitsu.js
... ... @@ -0,0 +1,28 @@
  1 +/*
  2 + * jitsu.js: Top-level include for the jitsu module.
  3 + *
  4 + * (C) 2010, Nodejitsu Inc.
  5 + *
  6 + */
  7 +
  8 +require.paths.unshift(__dirname);
  9 +
  10 +var jitsu = exports;
  11 +
  12 +// Failure HTTP Response codes based
  13 +// off of `/lib/broodmother/slave/service.js`
  14 +var failCodes jitsu.failCodes = {
  15 + 400: "Bad Request",
  16 + 404: "Item not found",
  17 + 500: "Internal Server Error"
  18 +};
  19 +
  20 +// Success HTTP Response codes based
  21 +// off of `/lib/broodmother/slave/service.js`
  22 +var successCodes = jitsu.successCodes = {
  23 + 200: "OK",
  24 + 201: "Created"
  25 +};
  26 +
  27 +jitsu.client = require('jitsu/client');
  28 +jitsu.apps = require('jitsu/apps');
33 lib/jitsu/apps.js
... ... @@ -0,0 +1,33 @@
  1 +/*
  2 + * app.js: Client for the Nodejitsu apps API.
  3 + *
  4 + * (C) 2010, Nodejitsu Inc.
  5 + *
  6 + */
  7 +
  8 +var util = require('util'),
  9 + jitsu = require('jitsu');
  10 +
  11 +var Apps = exports.Apps = function (options) {
  12 + jitsu.Client.call(this, options);
  13 +};
  14 +
  15 +util.inherits(Apps, jitsu.Client);
  16 +
  17 +Apps.prototype.list = function (callback) {
  18 +
  19 +};
  20 +
  21 +Apps.prototype.create = function (app, callback) {
  22 + this._request('POST', ['apps' app.name], app, callback, function (err, res, body) {
  23 +
  24 + });
  25 +};
  26 +
  27 +Apps.prototype.update = function (attrs, callback) {
  28 +
  29 +};
  30 +
  31 +Apps.prototype.destory = function (name, callback) {
  32 +
  33 +};
54 lib/jitsu/client.js
... ... @@ -0,0 +1,54 @@
  1 +/*
  2 + * client.js: Client base for the Nodejitsu API clients.
  3 + *
  4 + * (C) 2010, Nodejitsu Inc.
  5 + *
  6 + */
  7 +
  8 +var request = require('request'),
  9 + jitsu = require('jitsu');
  10 +
  11 +var Client = exports.Client = function (options) {
  12 +
  13 +};
  14 +
  15 +Client.prototype._request = function (method, uri /* variable arguments */) {
  16 + var options, args = Array.prototype.slice.call(arguments),
  17 + success = args.pop(),
  18 + callback = args.pop(),
  19 + body = typeof args[args.length - 1] === 'object' && args.pop();
  20 +
  21 + options = {
  22 + method: method || 'GET',
  23 + uri: this.remoteUri + uri,
  24 + headers: {
  25 + 'Content-Type': 'application/json'
  26 + }
  27 + };
  28 +
  29 + if (body) {
  30 + options.body = JSON.stringify(body);
  31 + }
  32 +
  33 + request(options, function (err, response, body) {
  34 + if (err) {
  35 + return callback(err);
  36 + }
  37 +
  38 + try {
  39 + var statusCode = response.statusCode.toString(),
  40 + result = JSON.parse(body);
  41 + }
  42 + catch (ex) {
  43 + // Ignore Errors
  44 + }
  45 +
  46 + if (Object.keys(jitsu.failCodes).indexOf(statusCode) !== -1) {
  47 + var error = new Error('Broodmother Error (' + statusCode + '): ' + jitsu.failCodes[statusCode]);
  48 + error.result = result;
  49 + return callback(error);
  50 + }
  51 +
  52 + success(response, result);
  53 + });
  54 +};
7 lib/jitsu/config.js
... ... @@ -0,0 +1,7 @@
  1 +/*
  2 + * config.js: Configuration for the jitsu CLI.
  3 + *
  4 + * (C) 2010, Nodejitsu Inc.
  5 + *
  6 + */
  7 +

0 comments on commit 641b226

Please sign in to comment.
Something went wrong with that request. Please try again.