|
70 | 70 | dimensions = $.isArray(dimensions) ? dimensions : []; |
71 | 71 | var dimension = dimensions.length === 0 ? '' : dimensions[0]; |
72 | 72 | 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 | + }, |
74 | 79 | }; |
75 | 80 |
|
76 | 81 | /** |
|
139 | 144 | }); |
140 | 145 | }; |
141 | 146 |
|
| 147 | + |
142 | 148 | /** |
143 | 149 | * Creates a user instance and executes the specified method. |
144 | 150 | * |
|
209 | 215 | }); |
210 | 216 | }; |
211 | 217 |
|
| 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 | + |
212 | 295 | /** |
213 | 296 | * Method to lookup the specified dimensions information. |
214 | 297 | */ |
|
0 commit comments