Skip to content

Commit

Permalink
support of optional field recommendationCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco committed Jan 3, 2017
1 parent 04a7c00 commit fc3f479
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following code-snippet shows how easy it is to utilize the different end-poi
```html

<!-- load the library -->
<script src="https://cdn.jsdelivr.net/breinify-api/1.0.11/breinify-api.min.js"></script>
<script src="https://cdn.jsdelivr.net/breinify-api/1.0.12/breinify-api.min.js"></script>
<script>
/*
* Configure the library (see 'further links' for a full list)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breinify-api",
"version": "1.0.11",
"version": "1.0.12",
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
"authors": [
"Philipp Meisen <[email protected]>",
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breinify-api",
"version": "1.0.11",
"version": "1.0.12",
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
"authors": [
"Philipp Meisen <[email protected]>",
Expand All @@ -17,8 +17,7 @@
"scripts": {
"test": "grunt test"
},
"dependencies": {
},
"dependencies": {},
"devDependencies": {
"cdnjs-importer": "^2.0.0-beta",
"grunt": "^0.4.5",
Expand All @@ -34,6 +33,6 @@
"grunt-sync-json": "^0.4.0",
"jasmine-jquery": "^2.1.1",
"jquery": "2.2.2",
"main-bower-files": "^2.11.1"
"main-bower-files": "^2.13.1"
}
}
26 changes: 26 additions & 0 deletions specs/Breinify-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,30 @@ describe('Breinify', function () {
done();
});
});

//noinspection JSUnresolvedFunction
it('creates the correct recommendation data request instance', function (done) {
Breinify.setConfig({
'url': 'https://api.breinify.com',
'apiKey': '41B2-F48C-156A-409A-B465-317F-A0B4-E0E8'
});

//noinspection JSCheckFunctionSignatures
Breinify.UTL.unixTimestamp = function () {
return 1451962516;
};
Breinify.recommendationUser({}, 10, "some category", false, function (data) {

//noinspection JSUnresolvedFunction
expect(data.apiKey).toBe('41B2-F48C-156A-409A-B465-317F-A0B4-E0E8');
//noinspection JSUnresolvedFunction
expect(data.unixTimestamp).toBe(1451962516);
//noinspection JSUnresolvedFunction
expect(data.recommendation.recommendationCategory).toBe('some category');
//noinspection JSUnresolvedFunction
expect(data.recommendation.numRecommendations).toBe(10);

done();
});
});
});
25 changes: 20 additions & 5 deletions src/Breinify.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
*
* @param user {object} the user-information
* @param nrOfRecommendations {number|null} the amount of recommendations to get
* @param category {string|null} contains an optional category for the recommendation
* @param sign {boolean|null} true if a signature should be added (needs the secret to be configured - not recommended in open systems), otherwise false (can be null or undefined)
* @param onReady {function|null} unction to be executed after triggering the recommendation request
*/
Expand All @@ -228,17 +229,27 @@

overload.overload({
'Object,Function': function (user, callback) {
Breinify.recommendationUser(user, 3, false, function (data) {
Breinify.recommendationUser(user, 3, null, false, function (data) {
_privates.ajax(url, data, callback, callback);
});
},
'Object,Number,Function': function (user, nrOfRecommendations, callback) {
Breinify.recommendationUser(user, nrOfRecommendations, false, function (data) {
Breinify.recommendationUser(user, nrOfRecommendations, null, false, function (data) {
_privates.ajax(url, data, callback, callback);
});
},
'Object,Number,String,Function': function (user, nrOfRecommendations, category, callback) {
Breinify.recommendationUser(user, nrOfRecommendations, category, false, function (data) {
_privates.ajax(url, data, callback, callback);
});
},
'Object,Number,Boolean,Function': function (user, nrOfRecommendations, sign, callback) {
Breinify.recommendationUser(user, nrOfRecommendations, sign, function (data) {
Breinify.recommendationUser(user, nrOfRecommendations, null, sign, function (data) {
_privates.ajax(url, data, callback, callback);
});
},
'Object,Number,String,Boolean,Function': function (user, nrOfRecommendations, category, sign, callback) {
Breinify.recommendationUser(user, nrOfRecommendations, category, sign, function (data) {
_privates.ajax(url, data, callback, callback);
});
}
Expand All @@ -250,10 +261,11 @@
*
* @param user {object} the user-information
* @param nrOfRecommendations {number|null} the amount of recommendations to get
* @param category {string|null} contains an optional category for the recommendation
* @param sign {boolean|null} true if a signature should be added (needs the secret to be configured - not recommended in open systems), otherwise false (can be null or undefined)
* @param onReady {function|null} function to be executed after successful user creation
*/
Breinify.recommendationUser = function (user, nrOfRecommendations, sign, onReady) {
Breinify.recommendationUser = function (user, nrOfRecommendations, category, sign, onReady) {

var _onReady = function (user) {
if ($.isFunction(onReady)) {
Expand Down Expand Up @@ -286,12 +298,15 @@
}
}

category = typeof category === 'undefined' || category === null ? '' : category;

// create the data set
var data = {
'user': user.all(),

'recommendation': {
'numRecommendations': nrOfRecommendations
'numRecommendations': nrOfRecommendations,
'recommendationCategory': category
},

'apiKey': _config.get(ATTR_CONFIG.API_KEY),
Expand Down

0 comments on commit fc3f479

Please sign in to comment.