Skip to content

Commit 62f0940

Browse files
committed
Implement getFriendRequests
1 parent a7e4328 commit 62f0940

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

lib/user/getFriendRequests.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Includes
2+
var http = require('../util/http.js').func
3+
var getGeneralToken = require('../util/getGeneralToken.js').func
4+
5+
// Args
6+
exports.required = []
7+
exports.optional = ['sortOrder', 'limit', 'cursor', 'jar']
8+
9+
// Define
10+
function getFriendsRequests (jar, token, sortOrder, limit, cursor) {
11+
return new Promise((resolve, reject) => {
12+
var httpOpt = {
13+
url: '//friends.roblox.com/v1/my/friends/requests',
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) {
41+
const jar = args.jar
42+
const sortOrder = args.sortOrder || 'Asc'
43+
const limit = args.limit || (10).toString()
44+
const cursor = args.cursor || ''
45+
return getGeneralToken({ jar: jar })
46+
.then(function (xcsrf) {
47+
return getFriendsRequests(jar, xcsrf, sortOrder, limit, cursor)
48+
})
49+
}

0 commit comments

Comments
 (0)