Skip to content

Commit eb49f68

Browse files
author
Marco
committed
adding first changes regarding temporaldata
1 parent 07076ee commit eb49f68

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

src/Breinify.js

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@
7070
dimensions = $.isArray(dimensions) ? dimensions : [];
7171
var dimension = dimensions.length === 0 ? '' : dimensions[0];
7272
return dimension + unixTimestamp + dimensions.length;
73-
}
73+
},
74+
75+
//TODO --> when signature algorithm is defined!
76+
generateTemporalDataMessage: function (amount, unixTimestamp, type) {
77+
return type + unixTimestamp + amount;
78+
},
7479
};
7580

7681
/**
@@ -139,6 +144,7 @@
139144
});
140145
};
141146

147+
142148
/**
143149
* Creates a user instance and executes the specified method.
144150
*
@@ -209,6 +215,83 @@
209215
});
210216
};
211217

218+
/**
219+
* Sends an temporalData request to the Breinify server.
220+
*
221+
* @param user {object} the user-information
222+
* @param timezone {string|null} contains the timezone (e.g. xxx)
223+
* @param localDateTime {string|null} contains the localDateTime
224+
* @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)
225+
* @param onReady {function|null} function to be executed after triggering the activity
226+
*/
227+
Breinify.temporalData = function (user, timezone, localDateTime, sign, onReady) {
228+
Breinify.temporalDataUser(user, timezone, localDateTime, sign, function (data) {
229+
var url = _config.get(ATTR_CONFIG.URL) + _config.get(ATTR_CONFIG.TEMPORALDATA_ENDPOINT);
230+
_privates.ajax(url, data, onLookUp, onLookUp);
231+
});
232+
};
233+
234+
/**
235+
* Creates a user instance and executes the specified method.
236+
*
237+
* @param user {object} the user-information
238+
* @param timezone {string|null} contains the timezone (e.g. xxx)
239+
* @param localDateTime {string|null} contains the localDateTime
240+
* @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)
241+
* @param onReady {function|null} function to be executed after successful user creation
242+
*/
243+
Breinify.temporalDataUser = function (user, timezone, localDateTime, sign, onReady) {
244+
245+
var _onReady = function (user) {
246+
if ($.isFunction(onReady)) {
247+
onReady(user);
248+
}
249+
};
250+
251+
// get the user information
252+
new BreinifyUser(user, function (user) {
253+
254+
if (!user.validate()) {
255+
_onReady(null);
256+
return;
257+
}
258+
259+
// get some default values for the passed parameters - if not set
260+
timezone = typeof timezone === 'undefined' || timezone === null ? null : timezone;
261+
localDateTime = typeof localDateTime === 'undefined' || localDateTime === null ? null : localDateTime;
262+
sign = typeof sign === 'boolean' ? sign : false;
263+
264+
// get the other values needed
265+
var unixTimestamp = Breinify.unixTimestamp();
266+
var signature = null;
267+
if (sign) {
268+
// might be a different secret
269+
var secret = _config.get(ATTR_CONFIG.SECRET);
270+
if (typeof secret === 'string') {
271+
var message = _privates.generateTemporalDataMessage(1, unixTimestamp, type);
272+
signature = _privates.determineSignature(message, _config.get(ATTR_CONFIG.SECRET))
273+
} else {
274+
_onReady(null);
275+
return;
276+
}
277+
}
278+
279+
// create the data set
280+
var data = {
281+
'user': user.all(),
282+
'apiKey': _config.get(ATTR_CONFIG.API_KEY),
283+
'signature': signature,
284+
'unixTimestamp': unixTimestamp,
285+
'timezone': timezone,
286+
'localDataTime': localDateTime
287+
};
288+
289+
if ($.isFunction(onReady)) {
290+
_onReady(data);
291+
}
292+
});
293+
};
294+
212295
/**
213296
* Method to lookup the specified dimensions information.
214297
*/

src/BreinifyConfig.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
return value !== null && typeof value === 'string' && '' !== value.trim() && value.charAt(0) === '/';
3838
}
3939
});
40+
attributes.add('TEMPORALDATA_ENDPOINT', {
41+
name: 'lookupEndpoint',
42+
defaultValue: '/lookup',
43+
validate: function (value) {
44+
return value !== null && typeof value === 'string' && '' !== value.trim() && value.charAt(0) === '/';
45+
}
46+
});
4047
attributes.add('CATEGORY', {
4148
name: 'category',
4249
defaultValue: 'other',

0 commit comments

Comments
 (0)