-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconnect.gs
55 lines (52 loc) · 1.78 KB
/
connect.gs
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
function tinkoffApi_(obj, token) {
if (!!obj) {
Utilities.sleep(1500);
const marketApiUrl = 'https://api-invest.tinkoff.ru/openapi/', // Production
sandboxApiUrl = 'https://api-invest.tinkoff.ru/openapi/sandbox/'; // Sandbox
var get_params = '';
if (!!obj.parametres) {
get_params = '?' + http_build_query(obj.parametres);
}
var fullUrl = `${marketApiUrl}${obj.path}${get_params}`,
auth_str = 'Bearer ' + token,
options = {
"muteHttpExceptions": true,
"headers": {
"Authorization": auth_str,
},
"method": obj.method,
"contentType": "application/json; charset=utf-8",
};
if (obj.data) {
options.payload = JSON.stringify(obj.data);
}
Logger.log(fullUrl);
Logger.log(JSON.stringify(options));
var response = UrlFetchApp.fetch(fullUrl, options);
Logger.log(response);
return JSON.parse(response);
} else {
return
}
function http_build_query(formdata, numeric_prefix, arg_separator) { // Generate URL-encoded query string
var key,
use_val,
use_key,
i = 0,
tmp_arr = [];
if (!arg_separator) {
arg_separator = '&';
}
for (key in formdata) {
use_key = escape(key);
use_val = escape((formdata[key].toString()));
use_val = use_val.replace(/%20/g, '+');
if (numeric_prefix && !isNaN(key)) {
use_key = numeric_prefix + i;
}
tmp_arr[i] = use_key + '=' + use_val;
i++;
}
return tmp_arr.join(arg_separator);
}
}