Skip to content

Commit f5830af

Browse files
committed
added tags
1 parent d9a6507 commit f5830af

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

src/Breinify.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,43 +112,45 @@
112112
return _config.all();
113113
};
114114

115+
/**
116+
* Method to create a valid current unix timestamp.
117+
* @returns {number} the current unix timestamp (based on the system time)
118+
*/
119+
Breinify.unixTimestamp = function () {
120+
return Math.floor(new Date().getTime() / 1000);
121+
};
122+
115123
/**
116124
* Sends an activity to the Breinify server.
117125
*
118126
* @param user {object} the user-information
119127
* @param type {string|null} the type of activity
120128
* @param category {string|null} the category (can be null or undefined)
121129
* @param description {string|null} the description for the activity
130+
* @param tags {object} added the change to pass in tags
122131
* @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)
123132
* @param onReady {function|null} function to be executed after triggering the activity
124133
*/
125-
Breinify.activity = function (user, type, category, description, sign, onReady) {
134+
Breinify.activity = function (user, type, category, description, tags, sign, onReady) {
126135

127-
Breinify.activityUser(user, type, category, description, sign, function (data) {
136+
Breinify.activityUser(user, type, category, description, tags, sign, function (data) {
128137
var url = _config.get(ATTR_CONFIG.URL) + _config.get(ATTR_CONFIG.ACTIVITY_ENDPOINT);
129138
_privates.ajax(url, data, onReady, onReady);
130139
});
131140
};
132141

133-
/**
134-
* Method to create a valid current unix timestamp.
135-
* @returns {number} the current unix timestamp (based on the system time)
136-
*/
137-
Breinify.unixTimestamp = function () {
138-
return Math.floor(new Date().getTime() / 1000);
139-
};
140-
141142
/**
142143
* Creates a user instance and executes the specified method.
143144
*
144145
* @param user {object} the user-information
145146
* @param type {string|null} the type of activity
146147
* @param category {string|null} the category (can be null or undefined)
147148
* @param description {string|null} the description for the activity
149+
* @param tags {object} added the change to pass in tags
148150
* @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)
149151
* @param onReady {function|null} function to be executed after successful user creation
150152
*/
151-
Breinify.activityUser = function (user, type, category, description, sign, onReady) {
153+
Breinify.activityUser = function (user, type, category, description, tags, sign, onReady) {
152154

153155
var _onReady = function (user) {
154156
if ($.isFunction(onReady)) {
@@ -168,6 +170,7 @@
168170
type = typeof type === 'undefined' || type === null ? null : type;
169171
category = typeof category === 'undefined' || category === null ? _config.get(ATTR_CONFIG.CATEGORY) : category;
170172
description = typeof description === 'undefined' || description === null ? null : description;
173+
tags = BreinifyUtil.isSimpleObject(tags) ? tags : null;
171174
sign = typeof sign === 'boolean' ? sign : false;
172175

173176
// get the other values needed
@@ -191,7 +194,8 @@
191194
'activity': {
192195
'type': type,
193196
'category': category,
194-
'description': description
197+
'description': description,
198+
'tags': tags
195199
},
196200

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

src/BreinifyUtil.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
};
8989

9090
var BreinifyUtil = {
91-
9291
loc: {
9392

9493
params: function (paramListSeparator, paramSeparator, paramSplit, url) {
@@ -324,7 +323,7 @@
324323
}
325324
},
326325

327-
setText: function(cssSelector, text) {
326+
setText: function (cssSelector, text) {
328327
var $el = cssSelector instanceof $ ? cssSelector : $(cssSelector);
329328

330329
if ($el.is('input')) {
@@ -372,6 +371,46 @@
372371
} else {
373372
return false;
374373
}
374+
},
375+
376+
isSimpleObject: function (obj) {
377+
if (obj == null) {
378+
return true;
379+
} else if (!$.isPlainObject(obj)) {
380+
return false;
381+
}
382+
383+
// check the values of the object
384+
var result = true;
385+
$.each(obj, function (key, value) {
386+
var type = typeof value;
387+
if (value === null || type === 'boolean' || type === 'string' || type === 'number') {
388+
return true;
389+
} else if ($.isArray(value)) {
390+
391+
var globalArrayType = null;
392+
$.each(value, function (idx, arrayValue) {
393+
var arrayType = typeof arrayValue;
394+
395+
if (arrayValue === null) {
396+
return true;
397+
} else if (arrayType !== 'boolean' && arrayType !== 'string' && arrayType !== 'number') {
398+
result = false;
399+
} else if (globalArrayType === null) {
400+
globalArrayType = arrayType;
401+
} else if (globalArrayType !== arrayType) {
402+
result = false;
403+
}
404+
return result;
405+
});
406+
} else {
407+
result = false;
408+
}
409+
410+
return result;
411+
});
412+
413+
return result;
375414
}
376415
};
377416

src/snippets/suffix-global.js.snippet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
text: function() { return null; },
7474
setText: function() {},
7575
md5: function () { return null; },
76-
isEmpty: function() { return false; }
76+
isEmpty: function() { return false; },
77+
isSimpleObject: function() { return false; }
7778
};
7879

7980
window['Breinify'] = Breinify;

0 commit comments

Comments
 (0)