UNPKG

noblox-bonk

Version:
49 lines (45 loc) 1.25 kB
// Includes const http = require('../util/http.js').func // Args exports.required = ['userId'] exports.optional = ['jar'] // Docs /** * ✅ Get the friends of a user * @category User * @alias getFriends * @param {number} userId - The id of the user whose friends are being returned. * @returns {Promise<Friends>} * @example const noblox = require("noblox.js") * let friends = await noblox.getFriends(123456) **/ // Define function getFriends (jar, userId) { return new Promise((resolve, reject) => { const httpOpt = { url: `//friends.roblox.com/v1/users/${userId}/friends`, options: { method: 'GET', jar: jar, resolveWithFullResponse: true } } return http(httpOpt) .then(function (res) { if (res.statusCode === 200) { resolve(JSON.parse(res.body)) } else { const body = JSON.parse(res.body) || {} if (body.errors && body.errors.length > 0) { const errors = body.errors.map((e) => { return e.message }) reject(new Error(`${res.statusCode} ${errors.join(', ')}`)) } } }) }) } exports.func = function (args) { return getFriends(args.jar, args.userId) }