-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] Start stubbing out clients and common methods
- Loading branch information
Showing
5 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |||
|
|||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |||
}); | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |||
* | |||
*/ | |||
|