Skip to content

Commit

Permalink
XML n'at
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Feb 10, 2012
1 parent d4dd7e2 commit 84a6b86
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions api.js
Expand Up @@ -35,6 +35,7 @@ var createActionHero = function(){
api.async = require('async');
api.crypto = require("crypto");
api.consoleColors = require('colors');
api.data2xml = require('data2xml');

if(api.path.existsSync('./config.json')){
api.configData = JSON.parse(api.fs.readFileSync('./config.json','utf8'));
Expand Down
1 change: 0 additions & 1 deletion initializers/initDB.js
@@ -1,7 +1,6 @@
////////////////////////////////////////////////////////////////////////////
// DB setup
//
// All DB connection options must define: api.rateLimitCheck = function(api, connection, next) which will be used in all web connections. It should return requestThisHourSoFar (int)
// You can add DB specific by adding your task to the api.taks object
// Your DB init function should be called init and be exported. init = function(api, next)
// Name your DB init file the same thing you want folks to use in api.configData.database.type
Expand Down
4 changes: 1 addition & 3 deletions initializers/initPostVariables.js
Expand Up @@ -9,9 +9,7 @@ var initPostVariables = function(api, next)
"action",
"limit",
"offset",
"id",
"createdAt",
"updatedAt"
"outputType"
];
for(var i in api.actions){
var action = api.actions[i];
Expand Down
11 changes: 10 additions & 1 deletion initializers/initWebServer.js
Expand Up @@ -126,7 +126,16 @@ var initWebServer = function(api, next)

process.nextTick(function() {
if(cont != false){
var stringResponse = JSON.stringify(connection.response);
var stringResponse = "";
if(typeof connection.params.outputType == "string"){
if(connection.params.outputType.toLowerCase() == "xml"){
stringResponse = api.data2xml('XML', connection.response);
}else{
stringResponse = JSON.stringify(connection.response);
}
}else{
stringResponse = JSON.stringify(connection.response);
}

if(connection.params.callback != null){
connection.responseHeaders['Content-Type'] = "application/javascript";
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -19,7 +19,8 @@
"request":"2.x.x",
"validator":"0.x.x",
"formidable":"1.x.x",
"colors":"0.x.x"
"colors":"0.x.x",
"data2xml":"x"
},
"devDependencies": {
"vows":"0.x.x"
Expand Down
4 changes: 1 addition & 3 deletions readme.markdown
Expand Up @@ -476,9 +476,7 @@ Params (GET and POST) provided by the user will be checked against a whitelist.
"action",
"limit",
"offset",
"id",
"createdAt",
"updatedAt"
"outputType"
];
Params are loaded in this order GET -> POST (normal) -> POST (multipart). This means that if you have {url}?key=getValue and you post a variable `key`=`postValue` as well, the postValue will be the one used. The only exception to this is if you use the URL method of defining your action.

Expand Down
4 changes: 1 addition & 3 deletions spec/api.js
Expand Up @@ -65,9 +65,7 @@ suite.addBatch({
"action",
"limit",
"offset",
"id",
"createdAt",
"updatedAt"
"outputType"
];
for (var i in required){
specHelper.assert.isTrue(api.postVariables.indexOf(required[i]) > -1);
Expand Down
1 change: 1 addition & 0 deletions versions.markdown
Expand Up @@ -6,6 +6,7 @@

**Details:**

* You can now request XML output rather than json. Pass `outputType=XML` to the api
* Actions will be checked for the proper variables and methods.
* Actions' required params will be automatically checked for existence.
* Removed anything to do with rate-limiting. I don't think that anyone was using it anyway. This really isn't a core feature and was causing trouble at the DB layer.
Expand Down

0 comments on commit 84a6b86

Please sign in to comment.