diff --git a/lib/breinify.js b/lib/breinify.js index 2a203fb..e71c354 100644 --- a/lib/breinify.js +++ b/lib/breinify.js @@ -98,46 +98,37 @@ Breinify.prototype = { recommendation: function () { overload.overload({ 'Object,Function': function (user, callback) { - this._recommendation(user, 3, null, null, callback); + this._recommendation(user, { + 'numRecommendations': 10, + 'recommendationDisableCache': true + }, null, callback); }, - 'Object,Number,Function': function (user, nrOfRecommendations, callback) { - this._recommendation(user, nrOfRecommendations, null, null, callback); - }, - 'Object,Number,String,Function': function (user, nrOfRecommendations, category, callback) { - this._recommendation(user, nrOfRecommendations, category, null, callback); - }, - 'Object,Number,Boolean,Function': function (user, nrOfRecommendations, sign, callback) { - this._recommendation(user, nrOfRecommendations, null, sign, callback); - }, - 'Object,Number,String,Boolean,Function': function (user, nrOfRecommendations, category, sign, callback) { - this._recommendation(user, nrOfRecommendations, category, sign, callback); + 'Object,Object,Function': function (user, recommendation, callback) { + this._recommendation(user, recommendation, null, callback); } }, arguments, this); }, - _recommendation: function (user, nrOfRecommendations, category, sign, callback) { + _recommendation: function (user, recommendation, sign, callback) { // need a valid user if (util.isEmpty(user)) { this._handleError(callback, 'Please send in an user'); return; + } else if (util.isEmpty(recommendation)) { + this._handleError(callback, 'Please specify the requested recommendation attributes'); + return; } var config = this.config(); var endpoint = this.recommendationEndpoint(); sign = this._sign(sign); - category = typeof category === 'undefined' || category === null ? '' : category; - nrOfRecommendations = typeof nrOfRecommendations === 'undefined' || nrOfRecommendations === null ? 3 : nrOfRecommendations; - var payload = { 'apiKey': config.apiKey, 'unixTimestamp': Math.floor(Date.now() / 1000), 'user': user, - 'recommendation': { - 'numRecommendations': nrOfRecommendations, - 'recommendationCategory': category - } + 'recommendation': recommendation }; if (sign) { var message = '' + payload.unixTimestamp; @@ -211,14 +202,14 @@ Breinify.prototype = { this.__temporalData(user, sign, callback); }, - __temporalData: function(user, sign, callback) { + __temporalData: function (user, sign, callback) { var config = this.config(); var endpoint = this.temporalDataEndpoint(); sign = this._sign(sign); // let's check if it's a user or an additional object if (typeof user.additional === 'undefined') { - user = { 'additional': user }; + user = {'additional': user}; } var payload = {