comprodls-sdk 2.11.7 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.eslintrc +28 -28
  2. package/.npmignore +5 -0
  3. package/README.md +371 -371
  4. package/dist/comprodls-sdk.js +11493 -11301
  5. package/dist/comprodls-sdk.min.js +18 -18
  6. package/grunt/publish.js +148 -148
  7. package/lib/comprodls.js +146 -146
  8. package/lib/config/index.js +337 -336
  9. package/lib/helpers/index.js +29 -29
  10. package/lib/helpers/lib/api/converter.js +119 -119
  11. package/lib/helpers/lib/api/index.js +120 -120
  12. package/lib/helpers/lib/api/validations.js +72 -72
  13. package/lib/helpers/lib/errors.js +129 -129
  14. package/lib/helpers/lib/utils.js +23 -23
  15. package/lib/helpers/lib/validator.js +100 -100
  16. package/lib/open_access/index.js +121 -121
  17. package/lib/services/activity/activity.js +209 -209
  18. package/lib/services/activity/attempt.js +431 -431
  19. package/lib/services/activity/index.js +28 -28
  20. package/lib/services/analytics/index.js +1555 -1555
  21. package/lib/services/attempts/index.js +342 -342
  22. package/lib/services/auth/classProduct.js +37 -37
  23. package/lib/services/auth/index.js +2541 -2535
  24. package/lib/services/collab/index.js +468 -468
  25. package/lib/services/drive/index.js +144 -144
  26. package/lib/services/integrations/index.js +279 -116
  27. package/lib/services/invitations/index.js +313 -313
  28. package/lib/services/lrs/index.js +459 -459
  29. package/lib/services/product/index.js +267 -267
  30. package/lib/services/pub/index.js +407 -407
  31. package/lib/services/push/index.js +187 -187
  32. package/lib/services/push/pubnubClientWrapper.js +557 -557
  33. package/lib/services/push/sessionStorage.js +64 -64
  34. package/lib/services/pushX/index.js +190 -190
  35. package/lib/services/pushX/pubnubClientWrapper.js +211 -211
  36. package/lib/services/sisevents/index.js +113 -113
  37. package/lib/services/spaces/index.js +976 -929
  38. package/lib/services/superuser/index.js +175 -175
  39. package/lib/services/workflows/index.js +464 -464
  40. package/lib/services/xapi/index.js +232 -232
  41. package/lib/token/index.js +114 -114
  42. package/lib/token/validations.js +88 -88
  43. package/package-lock.json +5095 -0
  44. package/package.json +1 -1
  45. package/test.js +50 -50
  46. package/.vscode/launch.json +0 -23
  47. package/npm-debug.log.189866131 +0 -0
  48. package/npm-debug.log.712840116 +0 -26
@@ -1,431 +1,431 @@
1
- /*************************************************************************
2
- *
3
- * COMPRO CONFIDENTIAL
4
- * __________________
5
- *
6
- * [2015] - [2020] Compro Technologies Private Limited
7
- * All Rights Reserved.
8
- *
9
- * NOTICE: All information contained herein is, and remains
10
- * the property of Compro Technologies Private Limited. The
11
- * intellectual and technical concepts contained herein are
12
- * proprietary to Compro Technologies Private Limited and may
13
- * be covered by U.S. and Foreign Patents, patents in process,
14
- * and are protected by trade secret or copyright law.
15
- *
16
- * Dissemination of this information or reproduction of this material
17
- * is strictly forbidden unless prior written permission is obtained
18
- * from Compro Technologies Pvt. Ltd..
19
- ***************************************************************************/
20
- /***********************************************************
21
- * comproDLS SDK Activity Attempt Manager
22
- * Functions for calling Activity Attempt APIs.
23
- ************************************************************/
24
-
25
- var request = require('superagent');
26
- var q = require('q');
27
-
28
- var helpers = require('../../helpers');
29
- var DLSError = helpers.errors.DLSError;
30
- var extend = require('extend');
31
-
32
- module.exports = Attempt;
33
- /*********************************
34
- * Constructor
35
- **********************************/
36
-
37
- function Attempt(productId, activityId, attemptId, authCredentials, classId, config) {
38
- this.productId = productId;
39
- this.activityId = activityId;
40
- this.attemptId = attemptId;
41
- this.classId = classId;
42
- this.config = config;
43
-
44
- var authCredentials;
45
-
46
-
47
- function getProperties() {
48
- return this.authCredentials;
49
- }
50
-
51
- function setProperties(authCredentials) {
52
-
53
- this.authCredentials = authCredentials;
54
-
55
- }
56
-
57
- //Privilaged Methods
58
- Attempt.prototype.getAuthCredentials = function () {
59
- return getProperties();
60
- };
61
-
62
- Attempt.prototype.setAuthCredentials = function (orgid, token) {
63
- var authCredentials = new Object();
64
- authCredentials.orgId = orgid;
65
- authCredentials.token = token;
66
-
67
- setProperties(authCredentials);
68
- };
69
- };
70
-
71
- /*********************************
72
- * Method Implementations
73
- **********************************/
74
-
75
-
76
- Attempt.prototype.start = function (params) {
77
- var self = this;
78
-
79
- var orgid = this.getAuthCredentials().orgId;
80
- var token = this.getAuthCredentials().token;
81
- //Initializing promise
82
- var dfd = q.defer();
83
- //Validations
84
- var err = helpers.validations.isAuthenticated(orgid, token);
85
- if (err) {
86
- dfd.reject(err);
87
- } else {
88
-
89
- //Passed all validations, Contruct API url
90
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.newAttemptAPI;
91
- url = helpers.api.constructAPIUrl(url, {
92
- "orgId" : orgid,
93
- "productId" : self.productId,
94
- "activityId" : self.activityId
95
- });
96
- url = helpers.api.addClassIdQueryParam(url, self.classId);
97
-
98
- //Construct parameters
99
- if(params == undefined || params == null)
100
- params = {};
101
-
102
- //Setup request with URL and Params
103
- var req = request.post(url).send(params);
104
-
105
- //Setup token in Authorization header
106
- req = helpers.api.setupAPIToken(req, token);
107
-
108
- // setting up traceid
109
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
110
-
111
- //Call start attempt Api
112
- req.end(function (err, response) {
113
- if (err) {
114
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
115
- dfd.reject(err);
116
- } else {
117
- var responseBody = response.body;
118
- self.attemptId = responseBody.uuid;
119
- extend(true, self, responseBody);
120
- var resObject = new Object();
121
- resObject.attempt = self;
122
- dfd.resolve(resObject);
123
- }
124
- });
125
- }
126
- return dfd.promise;
127
-
128
- };
129
-
130
- Attempt.prototype.getAttemptInfo = function () {
131
- var orgid = this.getAuthCredentials().orgId;
132
- var token = this.getAuthCredentials().token;
133
- var self = this;
134
-
135
- //Initializing promise
136
- var dfd = q.defer();
137
-
138
- //Validations
139
- var err = helpers.validations.isAuthenticated(orgid, token);
140
- if (err) {
141
- dfd.reject(err);
142
- } else {
143
-
144
- //Passed all validations, Contruct API url
145
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.existingAttemptAPI;
146
- url = helpers.api.constructAPIUrl(url, {
147
- "orgId" : orgid,
148
- "productId" : self.productId,
149
- "activityId" : self.activityId,
150
- "attemptId" : self.attemptId
151
- });
152
- url = helpers.api.addClassIdQueryParam(url, self.classId);
153
- //Setup request with URL and Params
154
- var req = request.get(url);
155
-
156
- //Setup token in Authorization header
157
- req = helpers.api.setupAPIToken(req, token);
158
-
159
- // setting up traceid
160
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
161
-
162
- //Call GET attempt INFO Api
163
- req.end(function (err, response) {
164
- if (err) {
165
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
166
- dfd.reject(err);
167
- } else {
168
- var responseBody = response.body;
169
- self.attemptId = responseBody.uuid;
170
- extend(true, self, responseBody);
171
- var resObject = new Object();
172
- resObject.attempt = self;
173
- dfd.resolve(resObject);
174
- }
175
- });
176
- }
177
- return dfd.promise;
178
- };
179
-
180
- Attempt.prototype.getState = function () {
181
- var orgid = this.getAuthCredentials().orgId;
182
- var token = this.getAuthCredentials().token;
183
- var self = this;
184
-
185
- //Initializing promise
186
- var dfd = q.defer();
187
-
188
- //Validations
189
- var err = helpers.validations.isAuthenticated(orgid, token);
190
- if (err) {
191
- dfd.reject(err);
192
- } else {
193
-
194
- //Passed all validations, Contruct API url
195
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.existingAttemptAPI;
196
- url = helpers.api.constructAPIUrl(url, {
197
- "orgId" : orgid,
198
- "productId" : self.productId,
199
- "activityId" : self.activityId,
200
- "attemptId" : self.attemptId
201
- });
202
- url = helpers.api.addClassIdQueryParam(url, self.classId);
203
- //Setup request with URL and Params
204
- var req = request.get(url);
205
-
206
- //Setup token in Authorization header
207
- req = helpers.api.setupAPIToken(req, token);
208
-
209
- // setting up traceid
210
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
211
-
212
- //Call GET saved state Api
213
- req.end(function (err, response) {
214
- if (err) {
215
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
216
- dfd.reject(err);
217
- } else {
218
- var responseBody = response.body;
219
- var resObject = new Object();
220
- resObject.state = responseBody.data.savedstate.state;
221
- dfd.resolve(resObject);
222
- }
223
- });
224
- }
225
- return dfd.promise;
226
- };
227
-
228
- Attempt.prototype.saveState = function (state) {
229
- var orgid = this.getAuthCredentials().orgId;
230
- var token = this.getAuthCredentials().token;
231
- var self = this;
232
-
233
- //Initializing promise
234
- var dfd = q.defer();
235
-
236
- //Validations
237
- var err = helpers.validations.isAuthenticated(orgid, token);
238
- if (err) {
239
- dfd.reject(err);
240
- } else {
241
-
242
- //Passed all validations, Contruct API url
243
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.existingAttemptAPI;
244
- url = helpers.api.constructAPIUrl(url, {
245
- "orgId" : orgid,
246
- "productId" : self.productId,
247
- "activityId" : self.activityId,
248
- "attemptId" : self.attemptId
249
- });
250
- url = helpers.api.addClassIdQueryParam(url, self.classId);
251
-
252
- //Setup request with URL and Params
253
- var req = request.put(url).send(state);
254
-
255
- //Setup token in Authorization header
256
- req = helpers.api.setupAPIToken(req, token);
257
-
258
- // setting up traceid
259
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
260
-
261
- //Call PUT saved state Api
262
- req.end(function (err, response) {
263
- if (err) {
264
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
265
- dfd.reject(err);
266
- } else {
267
- var responseBody = response.body;
268
- var resObject = new Object();
269
- resObject.status = responseBody;
270
- dfd.resolve(resObject);
271
- }
272
- });
273
- }
274
- return dfd.promise;
275
- };
276
-
277
-
278
- Attempt.prototype.getUserResponse = function () {
279
- var orgid = this.getAuthCredentials().orgId;
280
- var token = this.getAuthCredentials().token;
281
- var self = this;
282
-
283
- //Initializing promise
284
- var dfd = q.defer();
285
-
286
- //Validations
287
- var err = helpers.validations.isAuthenticated(orgid, token);
288
- if (err) {
289
- dfd.reject(err);
290
- } else {
291
-
292
- //Passed all validations, Contruct API url
293
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.userResponseAPI;
294
- url = helpers.api.constructAPIUrl(url, {
295
- "orgId" : orgid,
296
- "productId" : self.productId,
297
- "activityId" : self.activityId,
298
- "attemptId" : self.attemptId
299
- });
300
- url = helpers.api.addClassIdQueryParam(url, self.classId);
301
-
302
- //Setup request with URL and Params
303
- var req = request.get(url);
304
-
305
- //Setup token in Authorization header
306
- req = helpers.api.setupAPIToken(req, token);
307
-
308
- // setting up traceid
309
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
310
-
311
- //Call GET Userresponse Api
312
- req.end(function (err, response) {
313
- if (err) {
314
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
315
- dfd.reject(err);
316
- } else {
317
- var responseBody = response.body;
318
- var resObject = new Object();
319
- resObject.userresponse = responseBody;
320
- dfd.resolve(resObject);
321
- }
322
- });
323
- }
324
- return dfd.promise;
325
- };
326
-
327
- Attempt.prototype.saveUserResponse = function (userresponse) {
328
- var orgid = this.getAuthCredentials().orgId;
329
- var token = this.getAuthCredentials().token;
330
- var self = this;
331
-
332
- //Initializing promise
333
- var dfd = q.defer();
334
-
335
- //Validations
336
- var err = helpers.validations.isAuthenticated(orgid, token);
337
- if (err) {
338
- dfd.reject(err);
339
- } else {
340
-
341
- //Passed all validations, Contruct API url
342
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.userResponseAPI;
343
- url = helpers.api.constructAPIUrl(url, {
344
- "orgId" : orgid,
345
- "productId" : self.productId,
346
- "activityId" : self.activityId,
347
- "attemptId" : self.attemptId
348
- });
349
-
350
- url = helpers.api.addClassIdQueryParam(url, self.classId);
351
-
352
- //Setup request with URL and Params
353
- var req = request.put(url).send(userresponse);
354
-
355
- //Setup token in Authorization header
356
- req = helpers.api.setupAPIToken(req, token);
357
-
358
- // setting up traceid
359
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
360
-
361
- //Call PUT Userresponse Api
362
- req.end(function (err, response) {
363
- if (err) {
364
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
365
- dfd.reject(err);
366
- } else {
367
- var responseBody = response.body;
368
- var resObject = new Object();
369
- resObject.status = responseBody;
370
- dfd.resolve(resObject);
371
- }
372
- });
373
- }
374
- return dfd.promise;
375
- };
376
-
377
- Attempt.prototype.submit = function (userresponse) {
378
-
379
- var orgid = this.getAuthCredentials().orgId;
380
- var token = this.getAuthCredentials().token;
381
- var self = this;
382
- //Initializing promise
383
- var dfd = q.defer();
384
- //Validations
385
- var err = helpers.validations.isAuthenticated(orgid, token);
386
- if (err) {
387
- dfd.reject(err);
388
- } else {
389
-
390
- //Passed all validations, Contruct API url
391
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.submitAttemptAPI;
392
- url = helpers.api.constructAPIUrl(url, {
393
- "orgId" : orgid,
394
- "productId" : self.productId,
395
- "activityId" : self.activityId,
396
- "attemptId" : self.attemptId
397
- });
398
- url = helpers.api.addClassIdQueryParam(url, self.classId);
399
-
400
- //Setup request with URL and Params
401
- var req;
402
- if(userresponse == undefined || userresponse == null)
403
- {
404
- req = request.post(url).send({});
405
- }
406
- else
407
- {
408
- req = request.post(url).send(userresponse);
409
- }
410
-
411
- //Setup token in Authorization header
412
- req = helpers.api.setupAPIToken(req, token);
413
-
414
- // setting up traceid
415
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
416
-
417
- //Call submit attempt Api
418
- req.end(function (err, response) {
419
- if (err) {
420
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
421
- dfd.reject(err);
422
- } else {
423
- var responseBody = response.body;
424
- var resObject = new Object();
425
- resObject.status = responseBody;
426
- dfd.resolve(resObject);
427
- }
428
- });
429
- }
430
- return dfd.promise;
431
- };
1
+ /*************************************************************************
2
+ *
3
+ * COMPRO CONFIDENTIAL
4
+ * __________________
5
+ *
6
+ * [2015] - [2020] Compro Technologies Private Limited
7
+ * All Rights Reserved.
8
+ *
9
+ * NOTICE: All information contained herein is, and remains
10
+ * the property of Compro Technologies Private Limited. The
11
+ * intellectual and technical concepts contained herein are
12
+ * proprietary to Compro Technologies Private Limited and may
13
+ * be covered by U.S. and Foreign Patents, patents in process,
14
+ * and are protected by trade secret or copyright law.
15
+ *
16
+ * Dissemination of this information or reproduction of this material
17
+ * is strictly forbidden unless prior written permission is obtained
18
+ * from Compro Technologies Pvt. Ltd..
19
+ ***************************************************************************/
20
+ /***********************************************************
21
+ * comproDLS SDK Activity Attempt Manager
22
+ * Functions for calling Activity Attempt APIs.
23
+ ************************************************************/
24
+
25
+ var request = require('superagent');
26
+ var q = require('q');
27
+
28
+ var helpers = require('../../helpers');
29
+ var DLSError = helpers.errors.DLSError;
30
+ var extend = require('extend');
31
+
32
+ module.exports = Attempt;
33
+ /*********************************
34
+ * Constructor
35
+ **********************************/
36
+
37
+ function Attempt(productId, activityId, attemptId, authCredentials, classId, config) {
38
+ this.productId = productId;
39
+ this.activityId = activityId;
40
+ this.attemptId = attemptId;
41
+ this.classId = classId;
42
+ this.config = config;
43
+
44
+ var authCredentials;
45
+
46
+
47
+ function getProperties() {
48
+ return this.authCredentials;
49
+ }
50
+
51
+ function setProperties(authCredentials) {
52
+
53
+ this.authCredentials = authCredentials;
54
+
55
+ }
56
+
57
+ //Privilaged Methods
58
+ Attempt.prototype.getAuthCredentials = function () {
59
+ return getProperties();
60
+ };
61
+
62
+ Attempt.prototype.setAuthCredentials = function (orgid, token) {
63
+ var authCredentials = new Object();
64
+ authCredentials.orgId = orgid;
65
+ authCredentials.token = token;
66
+
67
+ setProperties(authCredentials);
68
+ };
69
+ };
70
+
71
+ /*********************************
72
+ * Method Implementations
73
+ **********************************/
74
+
75
+
76
+ Attempt.prototype.start = function (params) {
77
+ var self = this;
78
+
79
+ var orgid = this.getAuthCredentials().orgId;
80
+ var token = this.getAuthCredentials().token;
81
+ //Initializing promise
82
+ var dfd = q.defer();
83
+ //Validations
84
+ var err = helpers.validations.isAuthenticated(orgid, token);
85
+ if (err) {
86
+ dfd.reject(err);
87
+ } else {
88
+
89
+ //Passed all validations, Contruct API url
90
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.newAttemptAPI;
91
+ url = helpers.api.constructAPIUrl(url, {
92
+ "orgId" : orgid,
93
+ "productId" : self.productId,
94
+ "activityId" : self.activityId
95
+ });
96
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
97
+
98
+ //Construct parameters
99
+ if(params == undefined || params == null)
100
+ params = {};
101
+
102
+ //Setup request with URL and Params
103
+ var req = request.post(url).send(params);
104
+
105
+ //Setup token in Authorization header
106
+ req = helpers.api.setupAPIToken(req, token);
107
+
108
+ // setting up traceid
109
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
110
+
111
+ //Call start attempt Api
112
+ req.end(function (err, response) {
113
+ if (err) {
114
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
115
+ dfd.reject(err);
116
+ } else {
117
+ var responseBody = response.body;
118
+ self.attemptId = responseBody.uuid;
119
+ extend(true, self, responseBody);
120
+ var resObject = new Object();
121
+ resObject.attempt = self;
122
+ dfd.resolve(resObject);
123
+ }
124
+ });
125
+ }
126
+ return dfd.promise;
127
+
128
+ };
129
+
130
+ Attempt.prototype.getAttemptInfo = function () {
131
+ var orgid = this.getAuthCredentials().orgId;
132
+ var token = this.getAuthCredentials().token;
133
+ var self = this;
134
+
135
+ //Initializing promise
136
+ var dfd = q.defer();
137
+
138
+ //Validations
139
+ var err = helpers.validations.isAuthenticated(orgid, token);
140
+ if (err) {
141
+ dfd.reject(err);
142
+ } else {
143
+
144
+ //Passed all validations, Contruct API url
145
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.existingAttemptAPI;
146
+ url = helpers.api.constructAPIUrl(url, {
147
+ "orgId" : orgid,
148
+ "productId" : self.productId,
149
+ "activityId" : self.activityId,
150
+ "attemptId" : self.attemptId
151
+ });
152
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
153
+ //Setup request with URL and Params
154
+ var req = request.get(url);
155
+
156
+ //Setup token in Authorization header
157
+ req = helpers.api.setupAPIToken(req, token);
158
+
159
+ // setting up traceid
160
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
161
+
162
+ //Call GET attempt INFO Api
163
+ req.end(function (err, response) {
164
+ if (err) {
165
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
166
+ dfd.reject(err);
167
+ } else {
168
+ var responseBody = response.body;
169
+ self.attemptId = responseBody.uuid;
170
+ extend(true, self, responseBody);
171
+ var resObject = new Object();
172
+ resObject.attempt = self;
173
+ dfd.resolve(resObject);
174
+ }
175
+ });
176
+ }
177
+ return dfd.promise;
178
+ };
179
+
180
+ Attempt.prototype.getState = function () {
181
+ var orgid = this.getAuthCredentials().orgId;
182
+ var token = this.getAuthCredentials().token;
183
+ var self = this;
184
+
185
+ //Initializing promise
186
+ var dfd = q.defer();
187
+
188
+ //Validations
189
+ var err = helpers.validations.isAuthenticated(orgid, token);
190
+ if (err) {
191
+ dfd.reject(err);
192
+ } else {
193
+
194
+ //Passed all validations, Contruct API url
195
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.existingAttemptAPI;
196
+ url = helpers.api.constructAPIUrl(url, {
197
+ "orgId" : orgid,
198
+ "productId" : self.productId,
199
+ "activityId" : self.activityId,
200
+ "attemptId" : self.attemptId
201
+ });
202
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
203
+ //Setup request with URL and Params
204
+ var req = request.get(url);
205
+
206
+ //Setup token in Authorization header
207
+ req = helpers.api.setupAPIToken(req, token);
208
+
209
+ // setting up traceid
210
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
211
+
212
+ //Call GET saved state Api
213
+ req.end(function (err, response) {
214
+ if (err) {
215
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
216
+ dfd.reject(err);
217
+ } else {
218
+ var responseBody = response.body;
219
+ var resObject = new Object();
220
+ resObject.state = responseBody.data.savedstate.state;
221
+ dfd.resolve(resObject);
222
+ }
223
+ });
224
+ }
225
+ return dfd.promise;
226
+ };
227
+
228
+ Attempt.prototype.saveState = function (state) {
229
+ var orgid = this.getAuthCredentials().orgId;
230
+ var token = this.getAuthCredentials().token;
231
+ var self = this;
232
+
233
+ //Initializing promise
234
+ var dfd = q.defer();
235
+
236
+ //Validations
237
+ var err = helpers.validations.isAuthenticated(orgid, token);
238
+ if (err) {
239
+ dfd.reject(err);
240
+ } else {
241
+
242
+ //Passed all validations, Contruct API url
243
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.existingAttemptAPI;
244
+ url = helpers.api.constructAPIUrl(url, {
245
+ "orgId" : orgid,
246
+ "productId" : self.productId,
247
+ "activityId" : self.activityId,
248
+ "attemptId" : self.attemptId
249
+ });
250
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
251
+
252
+ //Setup request with URL and Params
253
+ var req = request.put(url).send(state);
254
+
255
+ //Setup token in Authorization header
256
+ req = helpers.api.setupAPIToken(req, token);
257
+
258
+ // setting up traceid
259
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
260
+
261
+ //Call PUT saved state Api
262
+ req.end(function (err, response) {
263
+ if (err) {
264
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
265
+ dfd.reject(err);
266
+ } else {
267
+ var responseBody = response.body;
268
+ var resObject = new Object();
269
+ resObject.status = responseBody;
270
+ dfd.resolve(resObject);
271
+ }
272
+ });
273
+ }
274
+ return dfd.promise;
275
+ };
276
+
277
+
278
+ Attempt.prototype.getUserResponse = function () {
279
+ var orgid = this.getAuthCredentials().orgId;
280
+ var token = this.getAuthCredentials().token;
281
+ var self = this;
282
+
283
+ //Initializing promise
284
+ var dfd = q.defer();
285
+
286
+ //Validations
287
+ var err = helpers.validations.isAuthenticated(orgid, token);
288
+ if (err) {
289
+ dfd.reject(err);
290
+ } else {
291
+
292
+ //Passed all validations, Contruct API url
293
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.userResponseAPI;
294
+ url = helpers.api.constructAPIUrl(url, {
295
+ "orgId" : orgid,
296
+ "productId" : self.productId,
297
+ "activityId" : self.activityId,
298
+ "attemptId" : self.attemptId
299
+ });
300
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
301
+
302
+ //Setup request with URL and Params
303
+ var req = request.get(url);
304
+
305
+ //Setup token in Authorization header
306
+ req = helpers.api.setupAPIToken(req, token);
307
+
308
+ // setting up traceid
309
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
310
+
311
+ //Call GET Userresponse Api
312
+ req.end(function (err, response) {
313
+ if (err) {
314
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
315
+ dfd.reject(err);
316
+ } else {
317
+ var responseBody = response.body;
318
+ var resObject = new Object();
319
+ resObject.userresponse = responseBody;
320
+ dfd.resolve(resObject);
321
+ }
322
+ });
323
+ }
324
+ return dfd.promise;
325
+ };
326
+
327
+ Attempt.prototype.saveUserResponse = function (userresponse) {
328
+ var orgid = this.getAuthCredentials().orgId;
329
+ var token = this.getAuthCredentials().token;
330
+ var self = this;
331
+
332
+ //Initializing promise
333
+ var dfd = q.defer();
334
+
335
+ //Validations
336
+ var err = helpers.validations.isAuthenticated(orgid, token);
337
+ if (err) {
338
+ dfd.reject(err);
339
+ } else {
340
+
341
+ //Passed all validations, Contruct API url
342
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.userResponseAPI;
343
+ url = helpers.api.constructAPIUrl(url, {
344
+ "orgId" : orgid,
345
+ "productId" : self.productId,
346
+ "activityId" : self.activityId,
347
+ "attemptId" : self.attemptId
348
+ });
349
+
350
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
351
+
352
+ //Setup request with URL and Params
353
+ var req = request.put(url).send(userresponse);
354
+
355
+ //Setup token in Authorization header
356
+ req = helpers.api.setupAPIToken(req, token);
357
+
358
+ // setting up traceid
359
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
360
+
361
+ //Call PUT Userresponse Api
362
+ req.end(function (err, response) {
363
+ if (err) {
364
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
365
+ dfd.reject(err);
366
+ } else {
367
+ var responseBody = response.body;
368
+ var resObject = new Object();
369
+ resObject.status = responseBody;
370
+ dfd.resolve(resObject);
371
+ }
372
+ });
373
+ }
374
+ return dfd.promise;
375
+ };
376
+
377
+ Attempt.prototype.submit = function (userresponse) {
378
+
379
+ var orgid = this.getAuthCredentials().orgId;
380
+ var token = this.getAuthCredentials().token;
381
+ var self = this;
382
+ //Initializing promise
383
+ var dfd = q.defer();
384
+ //Validations
385
+ var err = helpers.validations.isAuthenticated(orgid, token);
386
+ if (err) {
387
+ dfd.reject(err);
388
+ } else {
389
+
390
+ //Passed all validations, Contruct API url
391
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.submitAttemptAPI;
392
+ url = helpers.api.constructAPIUrl(url, {
393
+ "orgId" : orgid,
394
+ "productId" : self.productId,
395
+ "activityId" : self.activityId,
396
+ "attemptId" : self.attemptId
397
+ });
398
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
399
+
400
+ //Setup request with URL and Params
401
+ var req;
402
+ if(userresponse == undefined || userresponse == null)
403
+ {
404
+ req = request.post(url).send({});
405
+ }
406
+ else
407
+ {
408
+ req = request.post(url).send(userresponse);
409
+ }
410
+
411
+ //Setup token in Authorization header
412
+ req = helpers.api.setupAPIToken(req, token);
413
+
414
+ // setting up traceid
415
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
416
+
417
+ //Call submit attempt Api
418
+ req.end(function (err, response) {
419
+ if (err) {
420
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
421
+ dfd.reject(err);
422
+ } else {
423
+ var responseBody = response.body;
424
+ var resObject = new Object();
425
+ resObject.status = responseBody;
426
+ dfd.resolve(resObject);
427
+ }
428
+ });
429
+ }
430
+ return dfd.promise;
431
+ };