-
Notifications
You must be signed in to change notification settings - Fork 6
/
portal.js
77 lines (58 loc) · 2.18 KB
/
portal.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Author : Hussein Nasser
//Date : Jan-23-2018
//Twitter: @hnasr
class Portal{
constructor(url, username, password)
{
this.url = url;
this.username = username;
this.password = password;
}
connect()
{
let tokenUrl = this.url + "/sharing/rest/generateToken";
let token = null;
let postJson = {
username: this.username,
password: this.password,
referer: window.location.host,
expiration: 60,
f: "json"
}
return new Promise((resolve, reject) => makeRequest({method: 'POST', url: tokenUrl, params: postJson }).then(response=>
{
if (response.token !== undefined)
{
this.token = response.token;
resolve(this.token);
}
else
reject("Invalid token")
} ).catch(rejected=>reject("Fail to execute request")));
}
items()
{
return new Promise( (resolve, reject) => {
let userItemsUrl = this.url + "/sharing/rest/search";
let postJson = {
token: this.token,
num : 100,
q : "owner:" + this.username,
f : "json"
}
makeRequest({method: 'POST', url: userItemsUrl, params: postJson }).then(response => {
let myItems = response;
resolve(myItems.results);
})
})
}
loadItem (itemId)
{
let itemUrl = this.url + "/sharing/rest/content/items/" + itemId + "/data";
let postJson = {
token: this.token,
f: "json"
}
return makeRequest({method: 'POST', url: itemUrl , params : postJson })
}
}