-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequester.js
58 lines (58 loc) · 1.83 KB
/
requester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
exports.__esModule = true;
exports.cRequester = void 0;
var cRequester = /** @class */ (function () {
function cRequester(obj) {
this.debugging = false;
this.token = obj.token;
}
cRequester.prototype.responseText = function (obj) {
try {
var result = {
ok: true,
messenger: this.messenger,
mask: obj.responseType,
date: Math.round(new Date().getTime() / 1000),
statusText: this.responseTransformer({
expr: obj.responseType,
responce: obj.responseText
})
};
if (this.debugging)
console.log(result);
return result;
}
catch (error) {
return this.errorHandler(error);
}
};
cRequester.prototype.errorHandler = function (error) {
var result = {
ok: false,
messenger: null,
mask: null,
date: Math.round(new Date().getTime() / 1000),
statusText: error
};
console.log(result);
return result;
};
cRequester.prototype.responseTransformer = function (obj) {
return obj.responce;
};
cRequester.prototype.paramToString = function (obj) {
var first = true;
var string = '';
for (var key in obj.param) {
string += (first) ? '?' : '&';
string += (typeof obj.param[key] === 'object' &&
!Array.isArray(obj.param[key]) &&
obj.param[key] !== null) ? key + '=' + encodeURIComponent(JSON.stringify(obj.param[key]))
: key + '=' + encodeURIComponent(obj.param[key]);
first = false;
}
return string;
};
return cRequester;
}());
exports.cRequester = cRequester;