From 251913fa9606ab7169fc074093907862c7dac1c5 Mon Sep 17 00:00:00 2001 From: Ethan <39052179+realCartar@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:42:33 +1000 Subject: [PATCH] Add getPlaceInfo() (#714) * Create getPlaceInfo.js * Update index.d.ts * Update jsDocs.ts * Update index.d.ts * Update getPlaceInfo.js * Update getPlaceInfo.js * Update index.d.ts * Update games.test.js * Update getPlaceInfo.js Fix Identation/Spacing * Update getPlaceInfo.js --- lib/games/getPlaceInfo.js | 48 +++++++++++++++++++++++++++++++++++++++ test/games.test.js | 25 ++++++++++++++++++++ typings/index.d.ts | 22 ++++++++++++++++++ typings/jsDocs.ts | 20 ++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 lib/games/getPlaceInfo.js diff --git a/lib/games/getPlaceInfo.js b/lib/games/getPlaceInfo.js new file mode 100644 index 00000000..23d280b8 --- /dev/null +++ b/lib/games/getPlaceInfo.js @@ -0,0 +1,48 @@ +// Includes +const http = require('../util/http.js').func + +// Args +exports.required = ['placeId'] +exports.optional = ['jar'] + +// Docs +/** + * 🔓 Get the info for a universe. + * @category Game + * @alias getPlaceInfo + * @param {number | Array} universeId - The id(s) of the place(s). + * @returns {Promise} + * @example const noblox = require("noblox.js") + * const universeInfo = await noblox.getPlaceInfo([ 10905034443 ]) +**/ + +function getPlaceInfo (placeIds, jar) { + return new Promise((resolve, reject) => { + if (typeof (placeIds) === 'number') placeIds = [placeIds] + + const httpOpt = { + url: `//games.roblox.com/v1/games/multiget-place-details?placeIds=${placeIds.join(',')}`, + options: { + json: true, + resolveWithFullResponse: true, + jar: jar, + method: 'GET' + } + } + + return http(httpOpt) + .then(function ({ statusCode, body }) { + if (statusCode === 200) { + resolve(body) + } else if (body && body.errors) { + reject(new Error(`[${statusCode}] ${body.errors[0].message} | placeIds: ${placeIds.join(',')} ${body.errors.field ? ` | ${body.errors.field} is incorrect` : ''}`)) + } else { + reject(new Error(`An unknown error occurred with getPlaceInfo() | [${statusCode}] placeIds: ${placeIds.join(',')}`)) + } + }).catch(reject) + }) +} + +exports.func = function (args) { + return getPlaceInfo(args.placeId, args.jar) +} diff --git a/test/games.test.js b/test/games.test.js index 2546fe40..ac4ee8c9 100644 --- a/test/games.test.js +++ b/test/games.test.js @@ -167,6 +167,31 @@ describe('Game Methods', () => { ) }) }) + +it('getPlaceInfo() should return an array of information about places', () => { + return getPlaceInfo(10905034443).then((res) => { + return expect(res).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + placeId: expect.any(Number), + name: expect.any(String), + sourceName: expect.any(String), + sourceDescription: expect.any(String), + url: expect.any(String), + builder: expect.any(String), + builderId: expect.any(Number), + hasVerifiedBadge: expect.any(Boolean), + isPlayable: expect.any(Boolean), + reasonProhibited: expect.any(String), + universeId: expect.any(Number), + universeRootPlaceId: expect.any(Number), + price: expect.any(Number), + imageToken: expect.any(String) + }) + ]) + ) + }) + }) // Dependency on getDeveloperProducts() which is broken as of 4.14.0 // eslint-disable-next-line jest/no-commented-out-tests diff --git a/typings/index.d.ts b/typings/index.d.ts index 6e2b7377..c216034c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -736,6 +736,23 @@ declare module "noblox.js" { isFavoritedByUser: boolean; favoritedCount: number; } + + interface PlaceInformation { + placeId: number; + name: string; + sourceName: string; + sourceDescription: string; + url: string; + builder: string; + builderId: number; + hasVerifiedBadge: boolean; + isPlayable: boolean; + reasonProhibited: string; + universeId: number; + universeRootPlaceId: number; + price: number; + imageToken: string; + } /// Group @@ -1854,6 +1871,11 @@ declare module "noblox.js" { */ function getUniverseInfo(universeIds: number[] | number, jar?: CookieJar): Promise; + /** + * 🔐 Returns information about the place(s) in question, such as name, description, etc. + */ + function getPlaceInfo(placeIds: number[] | number, jar?: CookieJar): Promise; + /** * 🔐 Update a developer product. */ diff --git a/typings/jsDocs.ts b/typings/jsDocs.ts index 3f8e2c86..c7d203e4 100644 --- a/typings/jsDocs.ts +++ b/typings/jsDocs.ts @@ -788,6 +788,26 @@ type UniverseInformation = { favoritedCount: number; } +/** + * @typedef + */ +type PlaceInformation = { + placeId: number; + name: string; + sourceName: string; + sourceDescription: string; + url: string; + builder: string; + builderId: number; + hasVerifiedBadge: boolean; + isPlayable: boolean; + reasonProhibited: string; + universeId: number; + universeRootPlaceId: number; + price: number; + imageToken: string; +} + /** * @typedef */