Skip to content

Commit

Permalink
Add getPlaceInfo() (#714)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
realCartar authored Oct 31, 2023
1 parent 7bba8f8 commit 251913f
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/games/getPlaceInfo.js
Original file line number Diff line number Diff line change
@@ -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<number>} universeId - The id(s) of the place(s).
* @returns {Promise<PlaceInformation[]>}
* @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)
}
25 changes: 25 additions & 0 deletions test/games.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1854,6 +1871,11 @@ declare module "noblox.js" {
*/
function getUniverseInfo(universeIds: number[] | number, jar?: CookieJar): Promise<UniverseInformation[]>;

/**
* 🔐 Returns information about the place(s) in question, such as name, description, etc.
*/
function getPlaceInfo(placeIds: number[] | number, jar?: CookieJar): Promise<PlaceInformation[]>;

/**
* 🔐 Update a developer product.
*/
Expand Down
20 changes: 20 additions & 0 deletions typings/jsDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 251913f

Please sign in to comment.