Skip to content

Commit 090c262

Browse files
author
Marco
committed
changes to support temporalData feature
1 parent eb49f68 commit 090c262

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/Breinify.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@
7272
return dimension + unixTimestamp + dimensions.length;
7373
},
7474

75-
//TODO --> when signature algorithm is defined!
76-
generateTemporalDataMessage: function (amount, unixTimestamp, type) {
77-
return type + unixTimestamp + amount;
78-
},
75+
generateTemporalDataMessage: function (localDateTime, timezone, unixTimestamp) {
76+
var paraLocalDateTime = typeof localDateTime === 'undefined' || localDateTime === null ? "" : localDateTime;
77+
var paraTimezone = typeof timezone === 'undefined' || timezone === null ? "" : timezone;
78+
79+
return unixTimestamp + "-" + paraLocalDateTime + "-" + paraTimezone;
80+
}
7981
};
8082

8183
/**
@@ -216,18 +218,18 @@
216218
};
217219

218220
/**
219-
* Sends an temporalData request to the Breinify server.
221+
* Sends an temporalData request to the Breinify backend.
220222
*
221223
* @param user {object} the user-information
222224
* @param timezone {string|null} contains the timezone (e.g. xxx)
223225
* @param localDateTime {string|null} contains the localDateTime
224226
* @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
227+
* @param onReady {function|null} function to be executed after triggering the temporalData request
226228
*/
227229
Breinify.temporalData = function (user, timezone, localDateTime, sign, onReady) {
228230
Breinify.temporalDataUser(user, timezone, localDateTime, sign, function (data) {
229231
var url = _config.get(ATTR_CONFIG.URL) + _config.get(ATTR_CONFIG.TEMPORALDATA_ENDPOINT);
230-
_privates.ajax(url, data, onLookUp, onLookUp);
232+
_privates.ajax(url, data, onReady, onReady);
231233
});
232234
};
233235

@@ -261,14 +263,23 @@
261263
localDateTime = typeof localDateTime === 'undefined' || localDateTime === null ? null : localDateTime;
262264
sign = typeof sign === 'boolean' ? sign : false;
263265

266+
if (timzone === null) {
267+
// get timezone from moment.js
268+
// moment().tz(moment.tz.guess()).format('z');
269+
}
270+
271+
if (localDateTime === null) {
272+
// get localDateTime from moment.js
273+
}
274+
264275
// get the other values needed
265276
var unixTimestamp = Breinify.unixTimestamp();
266277
var signature = null;
267278
if (sign) {
268279
// might be a different secret
269280
var secret = _config.get(ATTR_CONFIG.SECRET);
270281
if (typeof secret === 'string') {
271-
var message = _privates.generateTemporalDataMessage(1, unixTimestamp, type);
282+
var message = _privates.generateTemporalDataMessage(unixTimestamp, localDateTime, timezone);
272283
signature = _privates.determineSignature(message, _config.get(ATTR_CONFIG.SECRET))
273284
} else {
274285
_onReady(null);

src/BreinifyConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
}
3939
});
4040
attributes.add('TEMPORALDATA_ENDPOINT', {
41-
name: 'lookupEndpoint',
42-
defaultValue: '/lookup',
41+
name: 'temporaldataEndpoint',
42+
defaultValue: '/temporaldata',
4343
validate: function (value) {
4444
return value !== null && typeof value === 'string' && '' !== value.trim() && value.charAt(0) === '/';
4545
}

0 commit comments

Comments
 (0)