Skip to content

Commit

Permalink
new version 1.0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeisen committed Apr 16, 2019
1 parent a0074af commit ca82bf5
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 11 deletions.
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.19",
"version": "1.0.20",
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
"authors": [
"Philipp Meisen <philipp@breinify.com>",
Expand Down
23 changes: 18 additions & 5 deletions dist/breinify-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* breinify-api
* v1.0.19
* v1.0.20
**/
/*
* We inject a dependencyScope variable, which will be used
Expand Down Expand Up @@ -12900,7 +12900,7 @@ dependencyScope.jQuery = $;;
});

var BreinifyConfig = function (config) {
this.version = '1.0.19';
this.version = '1.0.20';

/*
* Validate the passed config-parameters.
Expand Down Expand Up @@ -13091,7 +13091,7 @@ dependencyScope.jQuery = $;;

var BreinifyUser = function (user, onReady) {
var instance = this;
instance.version = '1.0.19';
instance.version = '1.0.20';

// set the values provided
instance.setAll(user);
Expand Down Expand Up @@ -13593,8 +13593,21 @@ dependencyScope.jQuery = $;;
},

parseGetParameter: function (name, value) {

var base64;
if (typeof value !== 'string' || value === null) {
return null;
} else if (value.charAt(0) === '.') {
base64 = value.substr(1)
.replace('/~/g', '+')
.replace('/-/g', '/')
.replace('/_/g', '=');
} else {
base64 = decodeURIComponent(value);
}

try {
return JSON.parse(atob(decodeURIComponent(value)));
return JSON.parse(atob(base64));
} catch (e) {
return null;
}
Expand All @@ -13605,7 +13618,7 @@ dependencyScope.jQuery = $;;
* The one and only instance of the library.
*/
var Breinify = {
version: '1.0.19',
version: '1.0.20',
jQueryVersion: $.fn.jquery
};

Expand Down
6 changes: 3 additions & 3 deletions dist/breinify-api.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions specs/Breinify-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,123 @@ describe('Breinify', function () {
done();
});
});


//noinspection JSUnresolvedFunction
it('handlesGetParameters', function () {
var oldParams = Breinify.UTL.loc.params;
var oldActivity = Breinify.activity;

var test = [];
var value = {};

Breinify.activity = function (user, type, category, description, tags, sign, onReady) {

// create a unique new identifier for the test
test.push(true);

// add the information
value[test.length] = {
user: user,
type: type,
category: category,
description: description,
tags: tags,
sign: sign
};
};

// use some old configuration without any marker
Breinify.UTL.loc.params = function (done) {
return {
'brec': 'eyJ1c2VyIjogeyJlbWFpbCI6ICJwaGlsaXBwQG1laXNlbi5uZXQiLCJ1c2VySWQiOiAiNDAyODAxOTMxNTQifSwiYWN0aXZpdHkiOiB7InRhZ3MiOiB7InByb2R1Y3RQcmljZXMiOiBbMzkuOTldLCJwcm9kdWN0SWRzIjogWyIyMTg2Il0sIndpZGdldElkIjogIm1heUxpa2UyIiwid2lkZ2V0VHlwZSI6ICJpbWFnZSIsImNhbXBhaWduSWQiOiAiYmV2bW9GcmlkYXlFbWFpbHwyMDE5LTA0LTEyIiwiY2FtcGFpZ25UeXBlIjogImJldm1vRnJpZGF5RW1haWwifX19'
};
};
Breinify.setConfig({
'apiKey': '5555-064C-F007-4F92-A8DC-D06B-56B4-FAD8',
'category': 'other',
'handleParameters': true
});

// another old configuration without marker
Breinify.UTL.loc.params = function (done) {
return {
'brec': 'eyJ1c2VyIjogeyJlbWFpbCI6ICJwaGlsaXBwQG1laXNlbi5uZXQiLCJ1c2VySWQiOiAiNDAyODAxOTMxNTQifSwiYWN0aXZpdHkiOiB7InRhZ3MiOiB7InByb2R1Y3RQcmljZXMiOiBbMjYuOTldLCJwcm9kdWN0SWRzIjogWyI1MTIwNCJdLCJ3aWRnZXRJZCI6ICJtYXlMaWtlNCIsIndpZGdldFR5cGUiOiAiaW1hZ2UiLCJjYW1wYWlnbklkIjogImJldm1vRnJpZGF5RW1haWx8MjAxOS0wNC0xMiIsImNhbXBhaWduVHlwZSI6ICJiZXZtb0ZyaWRheUVtYWlsIn19fQ%3D%3D'
};
};
Breinify.setConfig({
'apiKey': '5555-064C-F007-4F92-A8DC-D06B-56B4-FAD8',
'category': 'other',
'handleParameters': true
});

// use some new configuration with the marker
Breinify.UTL.loc.params = function (done) {
return {
'brec': '.eyJhY3Rpdml0eSI6eyJ0eXBlIjoiY2xpY2tlZFJlY29tbWVuZGF0aW9uIiwidGFncyI6eyJwcm9kdWN0SWRzIjpbIjU0MTIzIl19fSwidXNlciI6eyJlbWFpbCI6InBoaWxpcHBAYnJlaW5pZnkuY29tIn19'
};
};
Breinify.setConfig({
'apiKey': '5555-064C-F007-4F92-A8DC-D06B-56B4-FAD8',
'category': 'other',
'handleParameters': true
});

// reset everything
Breinify.UTL.loc.params = oldParams;
Breinify.activity = oldActivity;

//noinspection JSUnresolvedFunction
expect(value).toEqual({
"1": {
"user": {
"email": "philipp@meisen.net",
"userId": "40280193154"
},
"type": "clickedRecommendation",
"category": null,
"description": null,
"tags": {
"productPrices": [39.99],
"productIds": ["2186"],
"widgetId": "mayLike2",
"widgetType": "image",
"campaignId": "bevmoFridayEmail|2019-04-12",
"campaignType": "bevmoFridayEmail"
},
"sign": null
},
"2": {
"user": {
"email": "philipp@meisen.net",
"userId": "40280193154"
},
"type": "clickedRecommendation",
"category": null,
"description": null,
"tags": {
"productPrices": [26.99],
"productIds": ["51204"],
"widgetId": "mayLike4",
"widgetType": "image",
"campaignId": "bevmoFridayEmail|2019-04-12",
"campaignType": "bevmoFridayEmail"
},
"sign": null
},
"3": {
"user": {
"email": "philipp@breinify.com"
},
"type": "clickedRecommendation",
"category": null,
"description": null,
"tags": {
"productIds": ["54123"]
},
"sign": null
}
});
});

});
15 changes: 14 additions & 1 deletion src/Breinify.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,21 @@
},

parseGetParameter: function (name, value) {

var base64;
if (typeof value !== 'string' || value === null) {
return null;
} else if (value.charAt(0) === '.') {
base64 = value.substr(1)
.replace('/~/g', '+')
.replace('/-/g', '/')
.replace('/_/g', '=');
} else {
base64 = decodeURIComponent(value);
}

try {
return JSON.parse(atob(decodeURIComponent(value)));
return JSON.parse(atob(base64));
} catch (e) {
return null;
}
Expand Down

0 comments on commit ca82bf5

Please sign in to comment.