Skip to content

Commit 01e2757

Browse files
committed
Implement getGroups function
1 parent 25e9fee commit 01e2757

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/user/getGroups.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Includes
2+
var http = require('../util/http.js').func
3+
var getGeneralToken = require('../util/getGeneralToken.js').func
4+
5+
// Args
6+
exports.required = ['userId']
7+
exports.optional = ['jar']
8+
9+
// Define
10+
function getGroups (jar, token, userId) {
11+
return new Promise((resolve, reject) => {
12+
var httpOpt = {
13+
url: `//api.roblox.com/users/${userId}/groups`,
14+
options: {
15+
method: 'GET',
16+
jar: jar,
17+
headers: {
18+
'X-CSRF-TOKEN': token
19+
},
20+
resolveWithFullResponse: true
21+
}
22+
}
23+
return http(httpOpt)
24+
.then(function (res) {
25+
if (res.statusCode === 200) {
26+
resolve(JSON.parse(res.body))
27+
} else {
28+
const body = JSON.parse(res.body) || {}
29+
if (body.errors && body.errors.length > 0) {
30+
var errors = body.errors.map((e) => {
31+
return e.message
32+
})
33+
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
34+
}
35+
}
36+
})
37+
})
38+
}
39+
40+
exports.func = function (args, senderUserId) {
41+
var jar = args.jar
42+
return getGeneralToken({ jar: jar })
43+
.then(function (xcsrf) {
44+
return getGroups(jar, xcsrf, args.userId)
45+
})
46+
}

0 commit comments

Comments
 (0)