@itutoring/itutoring_application_js_api 1.5.6 → 1.5.8

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.
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/iTutoring_Application_API-js.iml" filepath="$PROJECT_DIR$/.idea/iTutoring_Application_API-js.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
package/README.md CHANGED
@@ -3,4 +3,4 @@
3
3
  This package contains a javascript API for iTutoring Application.
4
4
  In order to use this API you need to obtain an API key.
5
5
 
6
- API Documentation for iTutoring Application can be found here: TO BE SOON
6
+ API Documentation for iTutoring Application can be found here: Private only
package/apiController.js CHANGED
@@ -2,7 +2,7 @@ import CookiesManager from "./CookiesManager";
2
2
  import { R_KEYs } from "./objects/Enums";
3
3
 
4
4
  /**
5
- * Main class for comunicating with our backend REST api.
5
+ * Main class for communicating with our backend REST api.
6
6
  */
7
7
  class APIController
8
8
  {
@@ -15,17 +15,17 @@ class APIController
15
15
 
16
16
  /**
17
17
  * R_KEY MUST be loaded before calling this method!
18
- * @returns Returns apropriate rest url based on current server.
18
+ * @returns Returns appropriate rest url based on current server.
19
19
  */
20
20
  static REST_URL()
21
21
  {
22
- if (location.hostname == 'localhost' || this.#R_KEY == R_KEYs.r_key_test)
22
+ if (location.hostname === 'localhost' || this.#R_KEY === R_KEYs.r_key_test)
23
23
  {
24
24
  return "https://api.test.itutoring.cz/";
25
25
 
26
26
  }
27
27
 
28
- if (this.#R_KEY == R_KEYs.r_key_live)
28
+ if (this.#R_KEY === R_KEYs.r_key_live)
29
29
  {
30
30
  return "https://api.itutoring.cz/";
31
31
  }
@@ -33,8 +33,8 @@ class APIController
33
33
 
34
34
  static CreateVisitorSession()
35
35
  {
36
- var id = Date.now();
37
- var date = new Date();
36
+ const id = Date.now();
37
+ const date = new Date();
38
38
  date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
39
39
 
40
40
  CookiesManager.SetCookie("session", id, date.toUTCString());
@@ -53,13 +53,13 @@ class APIController
53
53
  if (this.UserSource != null)
54
54
  return;
55
55
 
56
- var urlParams = new URLSearchParams(window.location.search);
56
+ const urlParams = new URLSearchParams(window.location.search);
57
57
  if (urlParams.has("o"))
58
58
  {
59
- var source = urlParams.get("o");
59
+ const source = urlParams.get("o");
60
60
  if (this.UserSource == null)
61
61
  {
62
- var date = new Date();
62
+ const date = new Date();
63
63
  date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
64
64
  CookiesManager.SetCookie("_o", source, date.toUTCString());
65
65
  this.UserSource = source;
@@ -67,6 +67,41 @@ class APIController
67
67
  }
68
68
  }
69
69
 
70
+ static ResolveResponse(request)
71
+ {
72
+ const json = JSON.parse(request.responseText);
73
+ if (json.code ===200)
74
+ {
75
+ // check for redirect
76
+ if (json.data === "redirect" && json.url !== undefined)
77
+ {
78
+ window.location.href = json.url;
79
+ }
80
+ return (json.data);
81
+ }
82
+ if (json.code === 400)
83
+ {
84
+ console.log("API Error:");
85
+ console.log("Error: " + json.error_message);
86
+ console.log("ErrorCode: " + json.error_code);
87
+ console.log("StackTrace: " + json.stack_trace);
88
+ const error = {
89
+ error: {
90
+ message: json.error_message,
91
+ code: json.error_code,
92
+ stackTrace: json.stack_trace
93
+ }
94
+ };
95
+ if (APIController.onErrorReceived !== null && APIController.onErrorReceived !== undefined)
96
+ {
97
+ APIController.onErrorReceived(error);
98
+ }
99
+
100
+ return (JSON.stringify(error));
101
+ }
102
+ }
103
+
104
+
70
105
  /**
71
106
  *
72
107
  * @param module "Name of API module"
@@ -81,44 +116,16 @@ class APIController
81
116
 
82
117
  return new Promise(resolve =>
83
118
  {
84
- var args = APIController.GetArgsFromArray(data);
119
+ const args = APIController.GetArgsFromArray(data);
85
120
 
86
- var request = new XMLHttpRequest();
121
+ const request = new XMLHttpRequest();
87
122
  request.withCredentials = true;
88
123
  request.open("GET", APIController.REST_URL() + module + "/" + method + "?" + args, true);
89
124
  request.onreadystatechange = function ()
90
125
  {
91
- if (request.readyState == 4)
126
+ if (request.readyState === 4)
92
127
  {
93
- var json = JSON.parse(request.responseText);
94
- if (json.code ==200)
95
- {
96
- // check for redirect
97
- if (json.data == "redirect" && json.url != undefined)
98
- {
99
- window.location.href = json.url;
100
- }
101
- resolve(json.data);
102
- }
103
- if (json.code == 400)
104
- {
105
- console.log("API Error:");
106
- console.log("Error: " + json.error_message);
107
- console.log("ErrorCode: " + json.error_code);
108
- console.log("StackTrace: " + json.stack_trace);
109
- var error = {
110
- error: {
111
- message: json.error_message,
112
- code: json.error_code,
113
- stackTrace: json.stack_trace
114
- }
115
- };
116
- resolve(JSON.stringify(error));
117
- if (APIController.onErrorReceived != null)
118
- {
119
- APIController.onErrorReceived(error);
120
- }
121
- }
128
+ resolve(APIController.ResolveResponse(request));
122
129
  }
123
130
  }
124
131
 
@@ -134,10 +141,11 @@ class APIController
134
141
  }
135
142
 
136
143
  /**
137
- *
144
+ *
138
145
  * @param module "Name of API module"
139
146
  * @param method "Name of API method "
140
147
  * @param data "data must be as array - key, value pair. They'll be passed into the request"
148
+ * @param file
141
149
  * @returns "Response from server"
142
150
  */
143
151
  static async Post(module, method, data, file = null)
@@ -147,53 +155,25 @@ class APIController
147
155
 
148
156
  return new Promise(resolve =>
149
157
  {
150
- var formData = new FormData();
158
+ let formData = new FormData();
151
159
  if (file != null)
152
160
  {
153
- var formData = new FormData();
161
+ formData = new FormData();
154
162
  formData.append("file", file);
155
163
 
156
164
 
157
165
  }
158
166
 
159
- var args = APIController.GetArgsFromArray(data);
167
+ const args = APIController.GetArgsFromArray(data);
160
168
 
161
- var request = new XMLHttpRequest();
169
+ const request = new XMLHttpRequest();
162
170
  request.open("POST", APIController.REST_URL() + module + "/" + method, true);
163
171
 
164
172
  request.onreadystatechange = function ()
165
173
  {
166
- if (request.readyState == 4)
174
+ if (request.readyState === 4)
167
175
  {
168
- var json = JSON.parse(request.responseText);
169
- if (json.code ==200)
170
- {
171
- // check for redirect
172
- if (json.data == "redirect" && json.url != undefined)
173
- {
174
- window.location.href = json.url;
175
- }
176
- resolve(json.data);
177
- }
178
- if (json.code == 400)
179
- {
180
- console.log("API Error:");
181
- console.log("Error: " + json.error_message);
182
- console.log("ErrorCode: " + json.error_code);
183
- console.log("StackTrace: " + json.stack_trace);
184
- var error = {
185
- error: {
186
- message: json.error_message,
187
- code: json.error_code,
188
- stackTrace: json.stack_trace
189
- }
190
- };
191
- resolve(JSON.stringify(error));
192
- if (APIController.onErrorReceived != null)
193
- {
194
- APIController.onErrorReceived(error);
195
- }
196
- }
176
+ resolve(APIController.ResolveResponse(request));
197
177
  }
198
178
  }
199
179
 
@@ -219,7 +199,7 @@ class APIController
219
199
 
220
200
  static GetArgsFromArray(args)
221
201
  {
222
- var argsString = "";
202
+ let argsString = "";
223
203
 
224
204
  if (args != null)
225
205
  {
@@ -239,12 +219,12 @@ class APIController
239
219
  {
240
220
  return new Promise(resolve =>
241
221
  {
242
- if (APIController.#R_KEY != "-1")
222
+ if (APIController.#R_KEY !== "-1")
243
223
  {
244
224
  resolve(APIController.#R_KEY);
245
225
  }
246
226
 
247
- // For localhost don't use xml config, but automaticly
227
+ // For localhost don't use xml config, but automatically
248
228
  // return test key.
249
229
  if (location.hostname === "localhost")
250
230
  {
@@ -255,9 +235,9 @@ class APIController
255
235
  {
256
236
  fetch('/key_config.xml').then(response => response.text()).then((data) =>
257
237
  {
258
- var parser = new DOMParser();
259
- var rKeyXML = parser.parseFromString(data, "text/xml");
260
- var rKey = rKeyXML.getElementsByTagName("key")[0].childNodes[0].nodeValue;
238
+ const parser = new DOMParser();
239
+ const rKeyXML = parser.parseFromString(data, "text/xml");
240
+ const rKey = rKeyXML.getElementsByTagName("key")[0].childNodes[0].nodeValue;
261
241
 
262
242
  APIController.#R_KEY = rKey;
263
243
  resolve(APIController.#R_KEY);
@@ -270,13 +250,13 @@ class APIController
270
250
  {
271
251
  return new Promise(resolve =>
272
252
  {
273
- if (APIController.#CLIENT_KEY != "-1")
253
+ if (APIController.#CLIENT_KEY !== "-1")
274
254
  {
275
255
  resolve(APIController.#CLIENT_KEY);
276
256
  }
277
257
 
278
258
  let keyPath = '/client_key.xml';
279
- // For localhost use different xml file (to make suer we won't revwrite the server key when uploading websites)
259
+ // For localhost use different xml file (to make suer we won't rewrite the server key when uploading websites)
280
260
  if (location.hostname === "localhost")
281
261
  {
282
262
  keyPath = '/local_client_key.xml'
@@ -284,9 +264,9 @@ class APIController
284
264
 
285
265
  fetch(keyPath).then(response => response.text()).then((data) =>
286
266
  {
287
- var parser = new DOMParser();
288
- var keyXML = parser.parseFromString(data, "text/xml");
289
- var key = keyXML.getElementsByTagName("key")[0].childNodes[0].nodeValue;
267
+ const parser = new DOMParser();
268
+ const keyXML = parser.parseFromString(data, "text/xml");
269
+ const key = keyXML.getElementsByTagName("key")[0].childNodes[0].nodeValue;
290
270
 
291
271
  APIController.#CLIENT_KEY = key;
292
272
  resolve(APIController.#CLIENT_KEY);
@@ -297,14 +277,14 @@ class APIController
297
277
 
298
278
  static async GetCurrentHostURl()
299
279
  {
300
- if (location.hostname == 'localhost')
280
+ if (location.hostname === 'localhost')
301
281
  {
302
282
  return "http://localhost:3000";
303
283
  }
304
284
  else
305
285
  {
306
286
  var r_key = await this.GetLocalRKey();
307
- if (r_key == R_KEYs.r_key_test)
287
+ if (r_key === R_KEYs.r_key_test)
308
288
  {
309
289
  return "https://test.itutoring.cz";
310
290
  }
@@ -317,7 +297,7 @@ class APIController
317
297
 
318
298
  static IntToBool(value)
319
299
  {
320
- return value == 1 ? true : false;
300
+ return value === 1;
321
301
  }
322
302
 
323
303
  static BoolToInt(value)
package/index.d.ts CHANGED
@@ -39,6 +39,8 @@ import AuthUser from "./objects/AuthUser";
39
39
  import Authentication from "./modules/Authentication";
40
40
  import AttendanceEvent from "./objects/AttendanceEvent";
41
41
  import Toolkit from "./toolkit/Toolkit";
42
+ import Pricing from "./modules/Pricing";
43
+ import Reviews from "./modules/Reviews";
42
44
 
43
45
  import
44
46
  {
@@ -79,6 +81,8 @@ export
79
81
  Toolkit,
80
82
  TeacherProfileModule,
81
83
  LectorDatabase,
84
+ Pricing,
85
+ Reviews,
82
86
 
83
87
  Course,
84
88
  CourseReservation,
package/index.js CHANGED
@@ -37,6 +37,8 @@ import Authentication from "./modules/Authentication";
37
37
  import AttendanceEvent from "./objects/AttendanceEvent";
38
38
  import Toolkit from "./toolkit/Toolkit";
39
39
  import TeacherProfileModule from "./modules/TeacherProfileModule";
40
+ import Pricing from "./modules/Pricing";
41
+ import Reviews from "./modules/Reviews";
40
42
 
41
43
  import
42
44
  {
@@ -77,6 +79,8 @@ export
77
79
  Toolkit,
78
80
  TeacherProfileModule,
79
81
  LectorDatabase,
82
+ Pricing,
83
+ Reviews,
80
84
 
81
85
  Course,
82
86
  CourseReservation,
@@ -1,11 +1,19 @@
1
1
  import APIController from "../apiController";
2
2
 
3
+ /**
4
+ * @deprecated Use general Reviews class instead.
5
+ */
3
6
  class GoogleReviews
4
7
  {
5
- static #MODULE = "GoogleReviews";
8
+ static #MODULE = "Reviews";
6
9
 
7
10
  static #GET_RANDOM_REVIEW = "GetRandomReview";
8
11
 
12
+ /**
13
+ * @deprecated Use general Reviews class instead.
14
+ * @param {*} last_review_timestamp
15
+ * @returns
16
+ */
9
17
  static async GetRandomReview(last_review_timestamp = -1)
10
18
  {
11
19
  var review = await APIController.Get(this.#MODULE, this.#GET_RANDOM_REVIEW, {
@@ -17,6 +17,7 @@ class LectorDatabase
17
17
  static #ADD_MODULE_ACCESS = "AddModuleAccess";
18
18
  static #REMOVE_MODULE_ACCESS = "RemoveModuleAccess";
19
19
  static #GET_COUNT_OF_LECTORS = "GetCountOfLectors";
20
+ static #GET_PUBLIC_PROFILES = "GetPublicProfiles";
20
21
 
21
22
  /**
22
23
  * desc: Get count of lectors
@@ -142,6 +143,20 @@ class LectorDatabase
142
143
  'access': access,
143
144
  });
144
145
  }
146
+
147
+ /**
148
+ * desc: Get public profiles
149
+ * @param {number} offset
150
+ * @param {number} maxCount
151
+ * @returns {Promise<array>}
152
+ */
153
+ static async getPublicProfiles(offset = 0, maxCount = -1)
154
+ {
155
+ return await APIController.Get(this.#MODULE, this.#GET_PUBLIC_PROFILES, {
156
+ 'offset': offset,
157
+ 'maxCount': maxCount,
158
+ });
159
+ }
145
160
  }
146
161
 
147
162
  export default LectorDatabase;
@@ -0,0 +1,62 @@
1
+ import APIController from "../apiController";
2
+
3
+ class Pricing
4
+ {
5
+ static #MODULE = 'Pricing';
6
+
7
+ static #GET_PRICE_TABLE = 'GetPriceTable';
8
+ static #GET_LESSON_PRICE = 'GetLessonPrice';
9
+ static #GET_LESSON_PRICE_OFFER = 'GetLessonPriceOffer';
10
+
11
+ /**
12
+ * desc: Get price table
13
+ *
14
+ * @returns
15
+ */
16
+ static async getPriceTable()
17
+ {
18
+ var priceTable = await APIController.Get(this.#MODULE, this.#GET_PRICE_TABLE, {});
19
+
20
+ return priceTable;
21
+ }
22
+
23
+ /**
24
+ * desc: Get lesson price
25
+ *
26
+ * @param {*} type
27
+ * @param {*} len
28
+ * @param {*} count
29
+ * @returns
30
+ */
31
+ static async getLessonPrice(type, len, count)
32
+ {
33
+ var price = await APIController.Get(this.#MODULE, this.#GET_LESSON_PRICE, {
34
+ 'type': type,
35
+ 'len': len,
36
+ 'count': count,
37
+ });
38
+
39
+ return price;
40
+ }
41
+
42
+ /**
43
+ * desc: Get lesson price offer
44
+ *
45
+ * @param {*} type
46
+ * @param {*} len
47
+ * @param {*} count
48
+ * @returns
49
+ */
50
+ static async getLessonPriceOffer(type, len, count)
51
+ {
52
+ var price = await APIController.Get(this.#MODULE, this.#GET_LESSON_PRICE_OFFER, {
53
+ 'type': type,
54
+ 'len': len,
55
+ 'count': count,
56
+ });
57
+
58
+ return price;
59
+ }
60
+ }
61
+
62
+ export default Pricing;
@@ -0,0 +1,45 @@
1
+ import APIController from "../apiController";
2
+
3
+ class Reviews
4
+ {
5
+ static #MODULE = "Reviews";
6
+
7
+ static #GET_RANDOM_REVIEW = "GetRandomReview";
8
+ static #GET_REVIEWS = "GetReviews";
9
+ static #GET_RATING = "GetRating";
10
+
11
+ /**
12
+ * desc: Get random review
13
+ * @returns
14
+ */
15
+ static async GetRandomReview()
16
+ {
17
+ const review = await APIController.Get(this.#MODULE, this.#GET_RANDOM_REVIEW, {});
18
+
19
+ return JSON.parse(review);
20
+ }
21
+
22
+ /**
23
+ * desc: Get reviews
24
+ * @returns
25
+ */
26
+ static async GetReviews()
27
+ {
28
+ const reviews = await APIController.Get(this.#MODULE, this.#GET_REVIEWS, {});
29
+
30
+ return JSON.parse(reviews);
31
+ }
32
+
33
+ /**
34
+ * desc: Get rating
35
+ * @returns
36
+ */
37
+ static async GetRating()
38
+ {
39
+ const rating = await APIController.Get(this.#MODULE, this.#GET_RATING, {});
40
+
41
+ return JSON.parse(rating);
42
+ }
43
+ }
44
+
45
+ export default Reviews;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itutoring/itutoring_application_js_api",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "Javascript API for iTutoring Application",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",