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,121 +1,121 @@
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 Open Access Manager Module
22
- * Provides Open Access functions for the SDK
23
- ************************************************************/
24
- var q = require('q');
25
- var request = require('superagent');
26
- var helpers = require('../helpers');
27
- var DLSError = helpers.errors.DLSError;
28
-
29
- /*************************************
30
- * Setting up Exports/Public functions
31
- *************************************/
32
-
33
- // These functions need to be moved to the corresponding adapter
34
- // They were created here since these functions requires the orgid but not token, But the initialiation function required both token and orgid to be initialized, Now we have improved the initialization function for orgid.
35
-
36
- exports.getClassEnrolmentsStat = getClassEnrolmentsStat;
37
- exports.getSingleInvitation = getSingleInvitation;
38
-
39
- /*********************************
40
- * Public Function definitions
41
- **********************************/
42
-
43
- /**
44
- * options = {
45
- * classid: 'string',
46
- * role: 'string
47
- * }
48
- **/
49
- function getClassEnrolmentsStat(organizationId, options) {
50
- var self = this;
51
- //Initializing promise
52
- var dfd = q.defer(), err = {};
53
- //Validations
54
- if(organizationId && options && options.classid) {
55
- //Passed all validations, Contruct API url
56
- var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getClassEnrolmentsStat;
57
- url = helpers.api.constructAPIUrl(url, { orgId: organizationId });
58
-
59
- //Setup request with URL
60
- var requestAPI = request.get(url).query(options);
61
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
62
-
63
- requestAPI.end(function(err, response) {
64
- if(err) {
65
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
66
- dfd.reject(err);
67
- }
68
- else { dfd.resolve(response.body); }
69
- });
70
- }
71
- else {
72
- err.message = err.description = 'Mandatory params not found in request body : [orgid, classid]';
73
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
74
- dfd.reject(err);
75
- }
76
- return dfd.promise;
77
- }
78
-
79
- /* options = {
80
- "context_id": "string", //class id to be invited -required
81
- "invitationid" : "string", //unique invitation id which is to be fetched -required
82
- "context" : "string", //context for invitation e.g. class_enrollment -required
83
- };
84
- */
85
- function getSingleInvitation(organizationId, options) {
86
- var self = this;
87
- var err = {};
88
- // Initializing promise
89
- var dfd = q.defer();
90
- if (organizationId && options && options.context_id && options.context &&
91
- options.invitationid) {
92
- // Passed all validations, Contruct API url
93
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getSingleInvitation;
94
- //Contruct path parameters
95
- url = helpers.api.constructAPIUrl(url,
96
- { orgId: organizationId, invitationId: options.invitationid });
97
- var queryParam = { context: options.context, context_id: options.context_id };
98
-
99
- // Setup request with URL and Params
100
- var requestAPI = request.get(url).query(queryParam);
101
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
102
-
103
- requestAPI.end(function (error, response) {
104
- if (error) {
105
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
106
- dfd.reject(err);
107
- }
108
- else {
109
- dfd.resolve(response.body);
110
- }
111
- });
112
- }
113
- else {
114
- err.message = err.description = 'organizationId or context_id or context '+
115
- 'or invitationid not found in request options.';
116
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
117
- dfd.reject(err);
118
- }
119
- return dfd.promise;
120
- }
121
-
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 Open Access Manager Module
22
+ * Provides Open Access functions for the SDK
23
+ ************************************************************/
24
+ var q = require('q');
25
+ var request = require('superagent');
26
+ var helpers = require('../helpers');
27
+ var DLSError = helpers.errors.DLSError;
28
+
29
+ /*************************************
30
+ * Setting up Exports/Public functions
31
+ *************************************/
32
+
33
+ // These functions need to be moved to the corresponding adapter
34
+ // They were created here since these functions requires the orgid but not token, But the initialiation function required both token and orgid to be initialized, Now we have improved the initialization function for orgid.
35
+
36
+ exports.getClassEnrolmentsStat = getClassEnrolmentsStat;
37
+ exports.getSingleInvitation = getSingleInvitation;
38
+
39
+ /*********************************
40
+ * Public Function definitions
41
+ **********************************/
42
+
43
+ /**
44
+ * options = {
45
+ * classid: 'string',
46
+ * role: 'string
47
+ * }
48
+ **/
49
+ function getClassEnrolmentsStat(organizationId, options) {
50
+ var self = this;
51
+ //Initializing promise
52
+ var dfd = q.defer(), err = {};
53
+ //Validations
54
+ if(organizationId && options && options.classid) {
55
+ //Passed all validations, Contruct API url
56
+ var url = self.config.DEFAULT_HOSTS['ANALYTICS'] + self.config.ANALYTICS_API_URLS.getClassEnrolmentsStat;
57
+ url = helpers.api.constructAPIUrl(url, { orgId: organizationId });
58
+
59
+ //Setup request with URL
60
+ var requestAPI = request.get(url).query(options);
61
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
62
+
63
+ requestAPI.end(function(err, response) {
64
+ if(err) {
65
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
66
+ dfd.reject(err);
67
+ }
68
+ else { dfd.resolve(response.body); }
69
+ });
70
+ }
71
+ else {
72
+ err.message = err.description = 'Mandatory params not found in request body : [orgid, classid]';
73
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
74
+ dfd.reject(err);
75
+ }
76
+ return dfd.promise;
77
+ }
78
+
79
+ /* options = {
80
+ "context_id": "string", //class id to be invited -required
81
+ "invitationid" : "string", //unique invitation id which is to be fetched -required
82
+ "context" : "string", //context for invitation e.g. class_enrollment -required
83
+ };
84
+ */
85
+ function getSingleInvitation(organizationId, options) {
86
+ var self = this;
87
+ var err = {};
88
+ // Initializing promise
89
+ var dfd = q.defer();
90
+ if (organizationId && options && options.context_id && options.context &&
91
+ options.invitationid) {
92
+ // Passed all validations, Contruct API url
93
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getSingleInvitation;
94
+ //Contruct path parameters
95
+ url = helpers.api.constructAPIUrl(url,
96
+ { orgId: organizationId, invitationId: options.invitationid });
97
+ var queryParam = { context: options.context, context_id: options.context_id };
98
+
99
+ // Setup request with URL and Params
100
+ var requestAPI = request.get(url).query(queryParam);
101
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
102
+
103
+ requestAPI.end(function (error, response) {
104
+ if (error) {
105
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
106
+ dfd.reject(err);
107
+ }
108
+ else {
109
+ dfd.resolve(response.body);
110
+ }
111
+ });
112
+ }
113
+ else {
114
+ err.message = err.description = 'organizationId or context_id or context '+
115
+ 'or invitationid not found in request options.';
116
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
117
+ dfd.reject(err);
118
+ }
119
+ return dfd.promise;
120
+ }
121
+
@@ -1,209 +1,209 @@
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
- /***********************************************************
22
- * comproDLS SDK Activity API Adaptor
23
- * Functions for calling Activity API.
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
- * Public Function definitions
33
- **********************************/
34
- module.exports = Activity;
35
-
36
- var attempt = require('./attempt');
37
-
38
- function Activity(productId, activityId, classId) {
39
- //When Activity constructor is called, check for instance type
40
- //comproDLS.Activity() will give instance type as ComproDLS
41
- //So the control goes to else
42
- if (this instanceof Activity) {
43
- this.productId = productId; //Here this is instance of Activity
44
- this.activityId = activityId; //Here this is instance of Activity
45
- this.classId = classId;
46
-
47
- } else { //New object of Activity is created and its instance type is Activity
48
- var act = new Activity(productId, activityId, classId);
49
- act.token = this.token; //Here this is instance of ComproDLS
50
- act.orgId = this.orgId; //Here this is instance of ComproDLS
51
- act.config = this.config;
52
- return act;
53
- }
54
- };
55
-
56
- Activity.prototype.getDetails = function () {
57
- var self = this;
58
-
59
- //Initializing promise
60
- var dfd = q.defer();
61
-
62
- //Validations
63
- var err = helpers.validations.isAuthenticated(this.orgId, this.token);
64
- if (err) {
65
- dfd.reject(err);
66
- } else {
67
-
68
- //Passed all validations, Contruct API url
69
- var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.activityDetailsAPI;
70
-
71
- url = helpers.api.constructAPIUrl(url, {
72
- "orgId" : self.orgId,
73
- "productId" : self.productId,
74
- "activityId" : self.activityId
75
- });
76
- url = helpers.api.addClassIdQueryParam(url, self.classId);
77
-
78
- //Setup request with URL and Params
79
- var req = request.get(url);
80
-
81
- //Setup token in Authorization header
82
- req = helpers.api.setupAPIToken(req, self.token);
83
-
84
- // setting up traceid
85
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
86
-
87
- //Call GET activity details Api
88
- req.end(function (err, response) {
89
- if (err) {
90
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
91
- dfd.reject(err);
92
- } else {
93
- var responseBody = response.body;
94
- var resObject = new Object();
95
- resObject.activity = responseBody;
96
- dfd.resolve(resObject);
97
- }
98
- });
99
- }
100
- return dfd.promise;
101
- }
102
-
103
- Activity.prototype.loadAttempt = function (attemptId) {
104
- var oldAttempt = new attempt(this.productId, this.activityId, attemptId, null, this.classId, this.config);
105
- oldAttempt.setAuthCredentials(this.orgId, this.token);
106
- return oldAttempt.getAttemptInfo();
107
- }
108
-
109
- Activity.prototype.getAttempt = function (attemptId) {
110
- var oldAttempt = new attempt(this.productId, this.activityId, attemptId, null, this.classId, this.config);
111
- oldAttempt.setAuthCredentials(this.orgId, this.token);
112
- return oldAttempt;
113
- }
114
-
115
- Activity.prototype.newAttempt = function (params) {
116
- var newAttempt = new attempt(this.productId, this.activityId, null, null, this.classId, this.config);
117
- newAttempt.setAuthCredentials(this.orgId, this.token);
118
- return newAttempt.start(params);
119
- }
120
-
121
- Activity.prototype.getAllQuestions = function () {
122
- var self = this;
123
-
124
- //Initializing promise
125
- var dfd = q.defer();
126
-
127
- //Validations
128
- var err = helpers.validations.isAuthenticated(this.orgId, this.token);
129
- if (err) {
130
- dfd.reject(err);
131
- } else {
132
-
133
- //Passed all validations, Contruct API url
134
- var url = self.config.DEFAULT_HOSTS['PRODUCT'] + self.config.PRODUCT_API_URLS.activityAPI;
135
- url = helpers.api.constructAPIUrl(url, {
136
- "orgId" : self.orgId,
137
- "productId" : self.productId,
138
- "activityId" : self.activityId
139
- });
140
- url = helpers.api.addClassIdQueryParam(url, self.classId);
141
- //Setup request with URL and Params
142
- var req = request.get(url);
143
-
144
- //Setup token in Authorization header
145
- req = helpers.api.setupAPIToken(req, self.token);
146
-
147
- // Setting trace id
148
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
149
-
150
- //Call GET activity details Api
151
- req.end(function (err, response) {
152
- if (err) {
153
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
154
- dfd.reject(err);
155
- } else {
156
- var responseBody = response.body;
157
- var resObject = new Object();
158
- resObject.questions = responseBody.items;
159
- dfd.resolve(resObject);
160
- }
161
- });
162
- }
163
- return dfd.promise;
164
- }
165
-
166
- Activity.prototype.getQuestionsCount = function () {
167
- var self = this;
168
-
169
- //Initializing promise
170
- var dfd = q.defer();
171
-
172
- //Validations
173
- var err = helpers.validations.isAuthenticated(this.orgId, this.token);
174
- if (err) {
175
- dfd.reject(err);
176
- } else {
177
-
178
- //Passed all validations, Contruct API url
179
- var url = self.config.DEFAULT_HOSTS['PRODUCT'] + self.config.PRODUCT_API_URLS.activityAPI;
180
- url = helpers.api.constructAPIUrl(url, {
181
- "orgId" : self.orgId,
182
- "productId" : self.productId,
183
- "activityId" : self.activityId
184
- });
185
- url = helpers.api.addClassIdQueryParam(url, self.classId);
186
- //Setup request with URL and Params
187
- var req = request.get(url);
188
-
189
- //Setup token in Authorization header
190
- req = helpers.api.setupAPIToken(req, self.token);
191
-
192
- // Setting trace id
193
- if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
194
-
195
- //Call GET activity details Api
196
- req.end(function (err, response) {
197
- if (err) {
198
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
199
- dfd.reject(err);
200
- } else {
201
- var responseBody = {"count": response.body.items.length};
202
- var resObject = new Object();
203
- resObject.count = responseBody;
204
- dfd.resolve(resObject);
205
- }
206
- });
207
- }
208
- return dfd.promise;
209
- }
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
+ /***********************************************************
22
+ * comproDLS SDK Activity API Adaptor
23
+ * Functions for calling Activity API.
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
+ * Public Function definitions
33
+ **********************************/
34
+ module.exports = Activity;
35
+
36
+ var attempt = require('./attempt');
37
+
38
+ function Activity(productId, activityId, classId) {
39
+ //When Activity constructor is called, check for instance type
40
+ //comproDLS.Activity() will give instance type as ComproDLS
41
+ //So the control goes to else
42
+ if (this instanceof Activity) {
43
+ this.productId = productId; //Here this is instance of Activity
44
+ this.activityId = activityId; //Here this is instance of Activity
45
+ this.classId = classId;
46
+
47
+ } else { //New object of Activity is created and its instance type is Activity
48
+ var act = new Activity(productId, activityId, classId);
49
+ act.token = this.token; //Here this is instance of ComproDLS
50
+ act.orgId = this.orgId; //Here this is instance of ComproDLS
51
+ act.config = this.config;
52
+ return act;
53
+ }
54
+ };
55
+
56
+ Activity.prototype.getDetails = function () {
57
+ var self = this;
58
+
59
+ //Initializing promise
60
+ var dfd = q.defer();
61
+
62
+ //Validations
63
+ var err = helpers.validations.isAuthenticated(this.orgId, this.token);
64
+ if (err) {
65
+ dfd.reject(err);
66
+ } else {
67
+
68
+ //Passed all validations, Contruct API url
69
+ var url = self.config.DEFAULT_HOSTS['ACTIVITY'] + self.config.ACTIVITY_API_URLS.activityDetailsAPI;
70
+
71
+ url = helpers.api.constructAPIUrl(url, {
72
+ "orgId" : self.orgId,
73
+ "productId" : self.productId,
74
+ "activityId" : self.activityId
75
+ });
76
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
77
+
78
+ //Setup request with URL and Params
79
+ var req = request.get(url);
80
+
81
+ //Setup token in Authorization header
82
+ req = helpers.api.setupAPIToken(req, self.token);
83
+
84
+ // setting up traceid
85
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
86
+
87
+ //Call GET activity details Api
88
+ req.end(function (err, response) {
89
+ if (err) {
90
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
91
+ dfd.reject(err);
92
+ } else {
93
+ var responseBody = response.body;
94
+ var resObject = new Object();
95
+ resObject.activity = responseBody;
96
+ dfd.resolve(resObject);
97
+ }
98
+ });
99
+ }
100
+ return dfd.promise;
101
+ }
102
+
103
+ Activity.prototype.loadAttempt = function (attemptId) {
104
+ var oldAttempt = new attempt(this.productId, this.activityId, attemptId, null, this.classId, this.config);
105
+ oldAttempt.setAuthCredentials(this.orgId, this.token);
106
+ return oldAttempt.getAttemptInfo();
107
+ }
108
+
109
+ Activity.prototype.getAttempt = function (attemptId) {
110
+ var oldAttempt = new attempt(this.productId, this.activityId, attemptId, null, this.classId, this.config);
111
+ oldAttempt.setAuthCredentials(this.orgId, this.token);
112
+ return oldAttempt;
113
+ }
114
+
115
+ Activity.prototype.newAttempt = function (params) {
116
+ var newAttempt = new attempt(this.productId, this.activityId, null, null, this.classId, this.config);
117
+ newAttempt.setAuthCredentials(this.orgId, this.token);
118
+ return newAttempt.start(params);
119
+ }
120
+
121
+ Activity.prototype.getAllQuestions = function () {
122
+ var self = this;
123
+
124
+ //Initializing promise
125
+ var dfd = q.defer();
126
+
127
+ //Validations
128
+ var err = helpers.validations.isAuthenticated(this.orgId, this.token);
129
+ if (err) {
130
+ dfd.reject(err);
131
+ } else {
132
+
133
+ //Passed all validations, Contruct API url
134
+ var url = self.config.DEFAULT_HOSTS['PRODUCT'] + self.config.PRODUCT_API_URLS.activityAPI;
135
+ url = helpers.api.constructAPIUrl(url, {
136
+ "orgId" : self.orgId,
137
+ "productId" : self.productId,
138
+ "activityId" : self.activityId
139
+ });
140
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
141
+ //Setup request with URL and Params
142
+ var req = request.get(url);
143
+
144
+ //Setup token in Authorization header
145
+ req = helpers.api.setupAPIToken(req, self.token);
146
+
147
+ // Setting trace id
148
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
149
+
150
+ //Call GET activity details Api
151
+ req.end(function (err, response) {
152
+ if (err) {
153
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
154
+ dfd.reject(err);
155
+ } else {
156
+ var responseBody = response.body;
157
+ var resObject = new Object();
158
+ resObject.questions = responseBody.items;
159
+ dfd.resolve(resObject);
160
+ }
161
+ });
162
+ }
163
+ return dfd.promise;
164
+ }
165
+
166
+ Activity.prototype.getQuestionsCount = function () {
167
+ var self = this;
168
+
169
+ //Initializing promise
170
+ var dfd = q.defer();
171
+
172
+ //Validations
173
+ var err = helpers.validations.isAuthenticated(this.orgId, this.token);
174
+ if (err) {
175
+ dfd.reject(err);
176
+ } else {
177
+
178
+ //Passed all validations, Contruct API url
179
+ var url = self.config.DEFAULT_HOSTS['PRODUCT'] + self.config.PRODUCT_API_URLS.activityAPI;
180
+ url = helpers.api.constructAPIUrl(url, {
181
+ "orgId" : self.orgId,
182
+ "productId" : self.productId,
183
+ "activityId" : self.activityId
184
+ });
185
+ url = helpers.api.addClassIdQueryParam(url, self.classId);
186
+ //Setup request with URL and Params
187
+ var req = request.get(url);
188
+
189
+ //Setup token in Authorization header
190
+ req = helpers.api.setupAPIToken(req, self.token);
191
+
192
+ // Setting trace id
193
+ if(self.traceid) { req.set('X-Amzn-Trace-Id', self.traceid); }
194
+
195
+ //Call GET activity details Api
196
+ req.end(function (err, response) {
197
+ if (err) {
198
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
199
+ dfd.reject(err);
200
+ } else {
201
+ var responseBody = {"count": response.body.items.length};
202
+ var resObject = new Object();
203
+ resObject.count = responseBody;
204
+ dfd.resolve(resObject);
205
+ }
206
+ });
207
+ }
208
+ return dfd.promise;
209
+ }