-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
105 lines (91 loc) · 2.32 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const request = require('request-promise-native')
const baseUrl = 'https://orgmanager.miguelpiedrafita.com'
function makeOptions(params, method, uri, formData) {
if (params.token == false) {
throw new Error('token not found!')
}
var options = {
method: method,
baseUrl: params.baseUrl,
uri: uri,
headers: {
'user-agent': 'node-orgmanager-api',
'authorization': `Bearer ${params.token}`
},
formData: formData,
encoding: null,
transform: function(body, response, resolveWithFullResponse) {
if (body.toString() == '') {
body = '{}'
}
var data = JSON.parse(body)
return data
}
}
return options
}
class orgmanager {
constructor(token, iBaseUrl) {
this.token = token || false
this.baseUrl = iBaseUrl || baseUrl
}
async getRoot() {
var options = makeOptions(this, 'GET', '/api', {})
return await request(options)
}
//getRoot()
async getStats() {
var options = makeOptions(this, 'GET', '/api/stats', {})
return await request(options)
}
//getStats()
async getUser() {
var options = makeOptions(this, 'GET', '/api/user', {})
return await request(options)
}
//getUser()
async getOrgs() {
var options = makeOptions(this, 'GET', '/api/user/orgs', {})
return await request(options)
}
//getOrgs()
async getOrg(id) {
var options = makeOptions(this, 'GET', `/api/org/${id}`, {})
return await request(options)
}
//getOrg(id)
async regenerateToken(set) {
var options = makeOptions(this, 'GET', '/api/token/regenerate', {})
var data = await request(options)
if (set == true) {
this.token = data.newtoken
}
return response
}
//regenerateToken()
async changeOrgPassword(id, password) {
var options = makeOptions(this, 'POST', `/api/org/${id}`, {
password: password
})
return await request(options)
}
//changeOrgPassword(id, password)
async joinOrg(id, username) {
var options = makeOptions(this, 'POST', `/api/join/${id}`, {
username: username
})
return await request(options)
}
//joinOrg(id, username)
async updateOrg(id) {
var options = makeOptions(this, 'PUT', `/api/org/${id}`, {})
return await request(options)
}
//updateOrg(id)
async deleteOrg(id) {
var options = makeOptions(this, 'DELETE', `/api/org/${id}`, {})
return await request(options)
}
//deleteOrg(id)
}
module.exports = orgmanager