Skip to content

Commit 06bdfca

Browse files
committed
added tags
1 parent f5830af commit 06bdfca

File tree

6 files changed

+85
-20
lines changed

6 files changed

+85
-20
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://libs.breinify.com/javascript/breinify-api.min.js"></script>
21+
<script src="https://cdn.jsdelivr.net/breinify-api/1.0.6/breinify-api.min.js"></script>
2222
<script>
2323
/*
2424
* Configure the library (see 'further links' for a full list)

dist/breinify-api.js

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12002,7 +12002,6 @@ dependencyScope.jQuery = $;;
1200212002
};
1200312003

1200412004
var BreinifyUtil = {
12005-
1200612005
loc: {
1200712006

1200812007
params: function (paramListSeparator, paramSeparator, paramSplit, url) {
@@ -12238,7 +12237,7 @@ dependencyScope.jQuery = $;;
1223812237
}
1223912238
},
1224012239

12241-
setText: function(cssSelector, text) {
12240+
setText: function (cssSelector, text) {
1224212241
var $el = cssSelector instanceof $ ? cssSelector : $(cssSelector);
1224312242

1224412243
if ($el.is('input')) {
@@ -12286,6 +12285,46 @@ dependencyScope.jQuery = $;;
1228612285
} else {
1228712286
return false;
1228812287
}
12288+
},
12289+
12290+
isSimpleObject: function (obj) {
12291+
if (obj == null) {
12292+
return true;
12293+
} else if (!$.isPlainObject(obj)) {
12294+
return false;
12295+
}
12296+
12297+
// check the values of the object
12298+
var result = true;
12299+
$.each(obj, function (key, value) {
12300+
var type = typeof value;
12301+
if (value === null || type === 'boolean' || type === 'string' || type === 'number') {
12302+
return true;
12303+
} else if ($.isArray(value)) {
12304+
12305+
var globalArrayType = null;
12306+
$.each(value, function (idx, arrayValue) {
12307+
var arrayType = typeof arrayValue;
12308+
12309+
if (arrayValue === null) {
12310+
return true;
12311+
} else if (arrayType !== 'boolean' && arrayType !== 'string' && arrayType !== 'number') {
12312+
result = false;
12313+
} else if (globalArrayType === null) {
12314+
globalArrayType = arrayType;
12315+
} else if (globalArrayType !== arrayType) {
12316+
result = false;
12317+
}
12318+
return result;
12319+
});
12320+
} else {
12321+
result = false;
12322+
}
12323+
12324+
return result;
12325+
});
12326+
12327+
return result;
1228912328
}
1229012329
};
1229112330

@@ -12832,43 +12871,45 @@ dependencyScope.jQuery = $;;
1283212871
return _config.all();
1283312872
};
1283412873

12874+
/**
12875+
* Method to create a valid current unix timestamp.
12876+
* @returns {number} the current unix timestamp (based on the system time)
12877+
*/
12878+
Breinify.unixTimestamp = function () {
12879+
return Math.floor(new Date().getTime() / 1000);
12880+
};
12881+
1283512882
/**
1283612883
* Sends an activity to the Breinify server.
1283712884
*
1283812885
* @param user {object} the user-information
1283912886
* @param type {string|null} the type of activity
1284012887
* @param category {string|null} the category (can be null or undefined)
1284112888
* @param description {string|null} the description for the activity
12889+
* @param tags {object} added the change to pass in tags
1284212890
* @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)
1284312891
* @param onReady {function|null} function to be executed after triggering the activity
1284412892
*/
12845-
Breinify.activity = function (user, type, category, description, sign, onReady) {
12893+
Breinify.activity = function (user, type, category, description, tags, sign, onReady) {
1284612894

12847-
Breinify.activityUser(user, type, category, description, sign, function (data) {
12895+
Breinify.activityUser(user, type, category, description, tags, sign, function (data) {
1284812896
var url = _config.get(ATTR_CONFIG.URL) + _config.get(ATTR_CONFIG.ACTIVITY_ENDPOINT);
1284912897
_privates.ajax(url, data, onReady, onReady);
1285012898
});
1285112899
};
1285212900

12853-
/**
12854-
* Method to create a valid current unix timestamp.
12855-
* @returns {number} the current unix timestamp (based on the system time)
12856-
*/
12857-
Breinify.unixTimestamp = function () {
12858-
return Math.floor(new Date().getTime() / 1000);
12859-
};
12860-
1286112901
/**
1286212902
* Creates a user instance and executes the specified method.
1286312903
*
1286412904
* @param user {object} the user-information
1286512905
* @param type {string|null} the type of activity
1286612906
* @param category {string|null} the category (can be null or undefined)
1286712907
* @param description {string|null} the description for the activity
12908+
* @param tags {object} added the change to pass in tags
1286812909
* @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)
1286912910
* @param onReady {function|null} function to be executed after successful user creation
1287012911
*/
12871-
Breinify.activityUser = function (user, type, category, description, sign, onReady) {
12912+
Breinify.activityUser = function (user, type, category, description, tags, sign, onReady) {
1287212913

1287312914
var _onReady = function (user) {
1287412915
if ($.isFunction(onReady)) {
@@ -12888,6 +12929,7 @@ dependencyScope.jQuery = $;;
1288812929
type = typeof type === 'undefined' || type === null ? null : type;
1288912930
category = typeof category === 'undefined' || category === null ? _config.get(ATTR_CONFIG.CATEGORY) : category;
1289012931
description = typeof description === 'undefined' || description === null ? null : description;
12932+
tags = BreinifyUtil.isSimpleObject(tags) ? tags : null;
1289112933
sign = typeof sign === 'boolean' ? sign : false;
1289212934

1289312935
// get the other values needed
@@ -12911,7 +12953,8 @@ dependencyScope.jQuery = $;;
1291112953
'activity': {
1291212954
'type': type,
1291312955
'category': category,
12914-
'description': description
12956+
'description': description,
12957+
'tags': tags
1291512958
},
1291612959

1291712960
'apiKey': _config.get(ATTR_CONFIG.API_KEY),
@@ -13078,7 +13121,8 @@ dependencyScope.jQuery = $;;
1307813121
text: function() { return null; },
1307913122
setText: function() {},
1308013123
md5: function () { return null; },
13081-
isEmpty: function() { return false; }
13124+
isEmpty: function() { return false; },
13125+
isSimpleObject: function() { return false; }
1308213126
};
1308313127

1308413128
window['Breinify'] = Breinify;

dist/breinify-api.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/step-by-step.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The file is integrated within a web-site by adding the needed script-tag, pointi
5353
It is also possible to omit the download and just point to the library file provided through a CDN (currently we do not publish the library to any CDN, but we will keep you updated) or Breinify's site.
5454

5555
```html
56-
<script src="https://libs.breinify.com/javascript/breinify-api.min.js"></script>
56+
<script src="https://cdn.jsdelivr.net/breinify-api/1.0.6/breinify-api.min.js"></script>
5757
```
5858

5959
**Note:** The library can also be loaded asynchroniously using the *async* and *onload* attribute (officially introduced in HTML5). In that case, the configuration of the library and all bindings should be performed after the library is loaded (i.e., within the *onload* function).

specs/Breinify-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Breinify', function () {
4848
};
4949
Breinify.activityUser({
5050
email: 'email@sample.com'
51-
}, 'search', null, null, true, function (data) {
51+
}, 'search', null, null, null, true, function (data) {
5252

5353
//noinspection JSUnresolvedFunction
5454
expect(data.apiKey).toBe('5D8B-064C-F007-4F92-A8DC-D06B-56B4-FAD8');

specs/BreinifyUtil-spec.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('BreinifyUtil', function () {
5757
expect(Breinify.UTL.cookie.get('undefined')).toBeNull();
5858
//noinspection JSUnresolvedFunction,JSUnresolvedVariable
5959
expect(Breinify.UTL.cookie.all()).toEqual({});
60-
60+
6161
// set some cookies
6262
Breinify.UTL.cookie.set('cookie', 'value');
6363
Breinify.UTL.cookie.set('cookie', 'lastValue');
@@ -98,4 +98,25 @@ describe('BreinifyUtil', function () {
9898
//noinspection JSUnresolvedFunction,JSUnresolvedVariable
9999
expect(Breinify.UTL.isEmpty(null)).toBe(true);
100100
});
101+
102+
103+
//noinspection JSUnresolvedFunction
104+
it('simple object works', function () {
105+
//noinspection JSUnresolvedFunction
106+
expect(Breinify.UTL.isSimpleObject(null)).toBe(true);
107+
//noinspection JSUnresolvedFunction
108+
expect(Breinify.UTL.isSimpleObject({})).toBe(true);
109+
//noinspection JSUnresolvedFunction
110+
expect(Breinify.UTL.isSimpleObject({'array': ['string1']})).toBe(true);
111+
//noinspection JSUnresolvedFunction
112+
expect(Breinify.UTL.isSimpleObject({'array': ['string1', 'string2']})).toBe(true);
113+
//noinspection JSUnresolvedFunction
114+
expect(Breinify.UTL.isSimpleObject({'array': [1, 2]})).toBe(true);
115+
//noinspection JSUnresolvedFunction
116+
expect(Breinify.UTL.isSimpleObject({'array': [1, 2, null, 3]})).toBe(true);
117+
//noinspection JSUnresolvedFunction
118+
expect(Breinify.UTL.isSimpleObject({'array': [1, 2, null, '3']})).toBe(false);
119+
//noinspection JSUnresolvedFunction
120+
expect(Breinify.UTL.isSimpleObject({'val1': 1, 'val2': 2, 'val3': []})).toBe(true);
121+
});
101122
});

0 commit comments

Comments
 (0)