Skip to content
Browse files

[minor] Code and comment cleanup.

  • Loading branch information...
1 parent 2e0a919 commit 8e4692e621699b9d344b54c2b93f1bd1ae67fd2f @Marak Marak committed Aug 30, 2012
Showing with 15 additions and 16 deletions.
  1. +15 −16 lib/resourceful/engines/restful.js
View
31 lib/resourceful/engines/restful.js
@@ -1,3 +1,14 @@
+/*
+
+ restful.js - RESTful resource engine for Resourceful
+
+ This resourceful engine expects `restful` endpoint to be waiting somewhere,
+ and uses the `request` library to communicate with it.
+
+ This engine is expected to work isomorphically ( on browser or server )
+
+*/
+
var resourceful = require('../../resourceful'),
Cache = resourceful.Cache;
@@ -35,21 +46,14 @@ Restful.prototype.request = function (action, key, data, callback) {
var self = this,
body,
label,
- plabel;
+ plabel,
+ resource;
- //
- // TODO: cleanup inflection / parsing code
- //
key = key._id || key;
- key = key.split('\/');
- label = key[0];
- plabel = key[0] = key[0] + 's';
- key = key.join('\/');
-
//
// Remark: non-strict /find route for `restful` routers
//
- if(action === "find") {
+ if(action === "find" && Object.keys(data).length > 1) {
key += '/find';
}
@@ -92,12 +96,7 @@ Restful.prototype.request = function (action, key, data, callback) {
//
// Remark: restful returns JSON results with labels, we must remove them
//
- if(typeof result[plabel] === "object") {
- result = result[plabel];
- }
- if(typeof result[label] === "object") {
- result = result[label];
- }
+ result = result[Object.keys(result)[0]]
} catch (ex) {
return callback(ex)
}

0 comments on commit 8e4692e

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