-
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.
Migrate
setCookie
from /mobileapi/userinfo
to `/v1/users/authenti…
…cated`; add `getUserFunds` method (#824) * feat(breaking)!: add getUserFunds(); migrate setCookie() from getCurrentUser() to getAuthenticatedUser(); polyfill and deprecate getCurrentUser() + add console warnings for getCurrentUser usage BREAKING CHANGE: getCurrentUser's /mobileinfo api endpoint is being deprecated by Roblox on August 27th (https://devforum.roblox.com/t/official-list-of-deprecated-web-endpoints/62889/66), setCookie will now have a new response type * misc: promisify secondary calls, remove github PR hyperlink, fix setOptions typing * lint: apply linting rules
- Loading branch information
Showing
8 changed files
with
95 additions
and
24 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
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,44 @@ | ||
// Includes | ||
const http = require('../util/http.js').func | ||
|
||
// Args | ||
exports.required = ['userId'] | ||
exports.optional = ['jar'] | ||
|
||
// Docs | ||
/** | ||
* 🔓 Gets the amount of robux for the authenticated user. | ||
* @category User | ||
* @param {number} userId - Must match the userId of the authenticated user | ||
* @alias getUserFunds | ||
* @returns {Promise<number>} | ||
* @example const noblox = require("noblox.js") | ||
* // Login using your cookie | ||
* const currentUser = await noblox.setCookie(process.env.ROBLOXCOOKIE) | ||
* const robux = await noblox.getUserFunds(currentUser.id) | ||
*/ | ||
|
||
// Define | ||
function getUserFunds (userId, jar) { | ||
return http({ | ||
url: `//economy.roblox.com/v1/users/${userId}/currency`, | ||
options: { | ||
jar, | ||
resolveWithFullResponse: true | ||
} | ||
}) | ||
.then(({ statusCode, body }) => { | ||
const { robux, errors } = JSON.parse(body) | ||
if (statusCode === 200) { | ||
return robux | ||
} else if (statusCode === 400 || statusCode === 403) { | ||
throw new Error(`${errors[0].message} | userId: ${userId}`) | ||
} else { | ||
throw new Error(`An unknown error occurred with getUserFunds() | [${statusCode}] userId: ${userId}`) | ||
} | ||
}) | ||
} | ||
|
||
exports.func = function ({ userId, jar }) { | ||
return getUserFunds(userId, jar) | ||
} |
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
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