2014-01-19 13:37:31 +00:00
|
|
|
/**
|
|
|
|
* Endpoint class.
|
|
|
|
*/
|
|
|
|
var Action = require('../action/action.js');
|
|
|
|
|
2014-01-20 19:30:45 +00:00
|
|
|
function Endpoint() {
|
2014-01-19 13:37:31 +00:00
|
|
|
// constructor
|
|
|
|
};
|
|
|
|
Endpoint.prototype = {
|
|
|
|
/**
|
|
|
|
* Build an action on resource endpoint.
|
|
|
|
* @param method <string> HTTP method
|
|
|
|
* @param url <url> target URL
|
|
|
|
* @param callback <function(err, action)> callback
|
|
|
|
*/
|
|
|
|
buildAction : function(method, url, callback) {
|
|
|
|
var col = this.targetCollection(url.pathname);
|
2014-01-22 18:38:47 +00:00
|
|
|
logger.debug('Building action ('+method+','+col+')');
|
2014-01-19 13:37:31 +00:00
|
|
|
var action;
|
|
|
|
if (col && method == 'POST') {
|
|
|
|
//TODO search
|
|
|
|
} else if (col && method == 'GET') {
|
2014-01-22 18:38:47 +00:00
|
|
|
action = new Action.ListAction();
|
2014-01-19 13:37:31 +00:00
|
|
|
} else if (!col && method == 'POST') {
|
|
|
|
//TODO edit
|
|
|
|
} else if (!col && method == 'GET') {
|
|
|
|
action = new Action.ShowAction();
|
|
|
|
}
|
|
|
|
if (action) {
|
|
|
|
this.bind(action, function(err) {
|
|
|
|
callback(err, action);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
callback(new Error('no action'));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-21 19:25:07 +00:00
|
|
|
/**
|
|
|
|
* @return target is a collection of resources.
|
|
|
|
*/
|
2014-01-19 13:37:31 +00:00
|
|
|
targetCollection : function(pathname) {
|
|
|
|
// TODO
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind action to endpoint resource.
|
|
|
|
*/
|
|
|
|
bind : function(action, callback) {
|
2014-01-21 19:25:07 +00:00
|
|
|
// implemented
|
2014-01-19 13:37:31 +00:00
|
|
|
callback(null, action);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
exports = module.exports = Endpoint;
|