-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #840 from Regalijan/split-getplayerinfo
Split getPlayerInfo into smaller methods
- Loading branch information
Showing
11 changed files
with
309 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Includes | ||
const http = require('../util/http.js').func | ||
|
||
// Args | ||
exports.required = ['userId'] | ||
|
||
// Docs | ||
/** | ||
* ✅ Gets the number of followers a user has. | ||
* @category User | ||
* @alias getFollowerCount | ||
* @param { number } userId | ||
* @returns Promise<number> | ||
* @example const noblox = require("noblox.js") | ||
* const numberOfFollowers = await noblox.getFollowerCount(55549140) | ||
**/ | ||
|
||
// Define | ||
exports.func = function (userId) { | ||
const httpOpt = { | ||
url: `//friends.roblox.com/v1/users/${userId}/followers/count`, | ||
options: { | ||
json: true, | ||
method: 'GET', | ||
resolveWithFullResponse: true | ||
} | ||
} | ||
|
||
return http(httpOpt).then(function (res) { | ||
if (res.statusCode === 200) { return res.body.count } | ||
|
||
throw new Error( | ||
`Failed to retrieve follower count: (${res.statusCode}) ${res.body}` | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Includes | ||
const http = require('../util/http.js').func | ||
|
||
// Args | ||
exports.required = ['userId'] | ||
|
||
// Docs | ||
/** | ||
* ✅ Gets the number of users a user is following. | ||
* @category User | ||
* @alias getFollowingCount | ||
* @param { number } userId | ||
* @returns Promise<number> | ||
* @example const noblox = require("noblox.js") | ||
* const numberOfFollowings = await noblox.getFollowingCount(55549140) | ||
**/ | ||
|
||
// Define | ||
exports.func = function (userId) { | ||
const httpOpt = { | ||
url: `//friends.roblox.com/v1/users/${userId}/followings/count`, | ||
options: { | ||
json: true, | ||
method: 'GET', | ||
resolveWithFullResponse: true | ||
} | ||
} | ||
|
||
return http(httpOpt).then(function (res) { | ||
if (res.statusCode === 200) { return res.body.count } | ||
|
||
throw new Error( | ||
`Failed to retrieve following count: (${res.statusCode}) ${res.body}` | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Includes | ||
const http = require('../util/http.js').func | ||
|
||
// Args | ||
exports.required = ['userId'] | ||
|
||
// Docs | ||
/** | ||
* ✅ Gets the number of friends a user has. | ||
* @category User | ||
* @alias getFriendCount | ||
* @param { number } userId | ||
* @returns Promise<number> | ||
* @example const noblox = require("noblox.js") | ||
* const numberOfFriends = await noblox.getFriendCount(55549140) | ||
**/ | ||
|
||
// Define | ||
exports.func = function (userId) { | ||
const httpOpt = { | ||
url: `//friends.roblox.com/v1/users/${userId}/friends/count`, | ||
options: { | ||
json: true, | ||
method: 'GET', | ||
resolveWithFullResponse: true | ||
} | ||
} | ||
|
||
return http(httpOpt).then(function (res) { | ||
if (res.statusCode === 200) { return res.body.count } | ||
|
||
throw new Error( | ||
`Failed to retrieve friend count: (${res.statusCode}) ${res.body}` | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Includes | ||
const http = require('../util/http.js').func | ||
|
||
// Args | ||
exports.required = ['userId'] | ||
|
||
// Docs | ||
/** | ||
* ✅ Get base-level user profile information | ||
* @category User | ||
* @alias getUserInfo | ||
* @param { number } userId | ||
* @returns {Promise<UserInfo>} | ||
**/ | ||
|
||
// Define | ||
exports.func = function (userId) { | ||
const httpOpt = { | ||
url: `//users.roblox.com/v1/users/${userId}`, | ||
options: { | ||
json: true, | ||
method: 'GET', | ||
resolveWithFullResponse: true | ||
} | ||
} | ||
|
||
return http(httpOpt).then(function (res) { | ||
if (res.statusCode !== 200) { throw new Error(`Failed to fetch user information: ${res.body.errors?.join(', ')}`) } | ||
|
||
res.body.created = new Date(res.body.created) | ||
|
||
return res.body | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Includes | ||
const getPageResults = require('../util/getPageResults.js').func | ||
|
||
// Args | ||
exports.required = ['userId'] | ||
exports.optional = ['limit', 'sortOrder', 'pageCursor'] | ||
|
||
// Docs | ||
/** | ||
* ✅ Get a user's username history. | ||
* @category User | ||
* @alias getUsernameHistory | ||
* @param {number} userId | ||
* @param {Limit=} [limit=10] | ||
* @param {SortOrder=} [sortOrder=Asc] | ||
* @param {string} cursor | ||
* @returns {Promise<UsernameHistoryEntry[]>} | ||
* @example const noblox = require("noblox.js") | ||
* const history = await noblox.getUsernameHistory({ userId: 1, limit: 10, sortOrder: "Asc", cursor: "somecursorstring" }) | ||
**/ | ||
|
||
// Define | ||
function getUsernameHistory (userId, limit, sortOrder, cursor) { | ||
return getPageResults({ | ||
url: `//users.roblox.com/v1/users/${userId}/username-history`, | ||
query: {}, | ||
limit, | ||
pageCursor: cursor, | ||
sortOrder | ||
}) | ||
} | ||
|
||
exports.func = function (args) { | ||
return getUsernameHistory(args.userId, args.limit, args.sortOrder, args.cursor) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.