Skip to content

Commit fc3f479

Browse files
author
Marco
committed
support of optional field recommendationCategory
1 parent 04a7c00 commit fc3f479

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The following code-snippet shows how easy it is to utilize the different end-poi
1818
```html
1919

2020
<!-- load the library -->
21-
<script src="https://cdn.jsdelivr.net/breinify-api/1.0.11/breinify-api.min.js"></script>
21+
<script src="https://cdn.jsdelivr.net/breinify-api/1.0.12/breinify-api.min.js"></script>
2222
<script>
2323
/*
2424
* Configure the library (see 'further links' for a full list)

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breinify-api",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
55
"authors": [
66
"Philipp Meisen <philipp@breinify.com>",

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breinify-api",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
55
"authors": [
66
"Philipp Meisen <philipp@breinify.com>",
@@ -17,8 +17,7 @@
1717
"scripts": {
1818
"test": "grunt test"
1919
},
20-
"dependencies": {
21-
},
20+
"dependencies": {},
2221
"devDependencies": {
2322
"cdnjs-importer": "^2.0.0-beta",
2423
"grunt": "^0.4.5",
@@ -34,6 +33,6 @@
3433
"grunt-sync-json": "^0.4.0",
3534
"jasmine-jquery": "^2.1.1",
3635
"jquery": "2.2.2",
37-
"main-bower-files": "^2.11.1"
36+
"main-bower-files": "^2.13.1"
3837
}
3938
}

specs/Breinify-spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,30 @@ describe('Breinify', function () {
8888
done();
8989
});
9090
});
91+
92+
//noinspection JSUnresolvedFunction
93+
it('creates the correct recommendation data request instance', function (done) {
94+
Breinify.setConfig({
95+
'url': 'https://api.breinify.com',
96+
'apiKey': '41B2-F48C-156A-409A-B465-317F-A0B4-E0E8'
97+
});
98+
99+
//noinspection JSCheckFunctionSignatures
100+
Breinify.UTL.unixTimestamp = function () {
101+
return 1451962516;
102+
};
103+
Breinify.recommendationUser({}, 10, "some category", false, function (data) {
104+
105+
//noinspection JSUnresolvedFunction
106+
expect(data.apiKey).toBe('41B2-F48C-156A-409A-B465-317F-A0B4-E0E8');
107+
//noinspection JSUnresolvedFunction
108+
expect(data.unixTimestamp).toBe(1451962516);
109+
//noinspection JSUnresolvedFunction
110+
expect(data.recommendation.recommendationCategory).toBe('some category');
111+
//noinspection JSUnresolvedFunction
112+
expect(data.recommendation.numRecommendations).toBe(10);
113+
114+
done();
115+
});
116+
});
91117
});

src/Breinify.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
*
221221
* @param user {object} the user-information
222222
* @param nrOfRecommendations {number|null} the amount of recommendations to get
223+
* @param category {string|null} contains an optional category for the recommendation
223224
* @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)
224225
* @param onReady {function|null} unction to be executed after triggering the recommendation request
225226
*/
@@ -228,17 +229,27 @@
228229

229230
overload.overload({
230231
'Object,Function': function (user, callback) {
231-
Breinify.recommendationUser(user, 3, false, function (data) {
232+
Breinify.recommendationUser(user, 3, null, false, function (data) {
232233
_privates.ajax(url, data, callback, callback);
233234
});
234235
},
235236
'Object,Number,Function': function (user, nrOfRecommendations, callback) {
236-
Breinify.recommendationUser(user, nrOfRecommendations, false, function (data) {
237+
Breinify.recommendationUser(user, nrOfRecommendations, null, false, function (data) {
238+
_privates.ajax(url, data, callback, callback);
239+
});
240+
},
241+
'Object,Number,String,Function': function (user, nrOfRecommendations, category, callback) {
242+
Breinify.recommendationUser(user, nrOfRecommendations, category, false, function (data) {
237243
_privates.ajax(url, data, callback, callback);
238244
});
239245
},
240246
'Object,Number,Boolean,Function': function (user, nrOfRecommendations, sign, callback) {
241-
Breinify.recommendationUser(user, nrOfRecommendations, sign, function (data) {
247+
Breinify.recommendationUser(user, nrOfRecommendations, null, sign, function (data) {
248+
_privates.ajax(url, data, callback, callback);
249+
});
250+
},
251+
'Object,Number,String,Boolean,Function': function (user, nrOfRecommendations, category, sign, callback) {
252+
Breinify.recommendationUser(user, nrOfRecommendations, category, sign, function (data) {
242253
_privates.ajax(url, data, callback, callback);
243254
});
244255
}
@@ -250,10 +261,11 @@
250261
*
251262
* @param user {object} the user-information
252263
* @param nrOfRecommendations {number|null} the amount of recommendations to get
264+
* @param category {string|null} contains an optional category for the recommendation
253265
* @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)
254266
* @param onReady {function|null} function to be executed after successful user creation
255267
*/
256-
Breinify.recommendationUser = function (user, nrOfRecommendations, sign, onReady) {
268+
Breinify.recommendationUser = function (user, nrOfRecommendations, category, sign, onReady) {
257269

258270
var _onReady = function (user) {
259271
if ($.isFunction(onReady)) {
@@ -286,12 +298,15 @@
286298
}
287299
}
288300

301+
category = typeof category === 'undefined' || category === null ? '' : category;
302+
289303
// create the data set
290304
var data = {
291305
'user': user.all(),
292306

293307
'recommendation': {
294-
'numRecommendations': nrOfRecommendations
308+
'numRecommendations': nrOfRecommendations,
309+
'recommendationCategory': category
295310
},
296311

297312
'apiKey': _config.get(ATTR_CONFIG.API_KEY),

0 commit comments

Comments
 (0)