<commit_before><commit_msg>Add brestful class for building Restful api<commit_after>var RestBuilder = require('./rest-builder.js');

function BRestful(app, bookshelf) {
  this.app = app;
  this.db = bookshelf;
  this.builder = new RestBuilder(app);
}

BRestful.prototype.createAPI = function (model, methods, preprocessors, postprocessors) {
  methods.forEach(function(method) {
    if (typeof this[method] === 'function') {
      var pre = preprocessors[method] || [];
      var post = postprocessors[method] || [];
      return this[method].call(this, model, pre, post);
    }
    throw 'HTTP Method: ' + method + ' is either invalid or unsupported';
  }).bind(this);
};

BRestful.prototype.GET = function(model, preprocessors, postprocessors) {
  this.builder.defineGetSingle(model, preprocessors.SINGLE, postprocessors.SINGLE);
  this.builder.defineGetMany(model, preprocessors.MANY, postprocessors.MANY);
};

BRestful.prototype.POST = function(model, preprocessors, postprocessors) {
  this.builder.definePost(model, preprocessors, postprocessors);
};

BRestful.prototype.PUT = function(model, preprocessors, postprocessors) {
  this.builder.definePut(model, preprocessors, postprocessors);
};

BRestful.prototype.DELETE = function(model, preprocessors, postprocessors) {
  this.builder.defineDelete(model, preprocessors, postprocessors);
};

module.exports = BRestful;
{'fraction_non_alphanumeric': 0.13100436681222707, 'fraction_numerical': 0.0, 'mean_word_length': 5.485849056603773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294291', 'n_tokens_mistral': 425, 'n_tokens_neox': 423, 'n_words': 84}