Skip to content

Commit

Permalink
added legacy develop and groups apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Campbell authored and Cameron Campbell committed Oct 12, 2024
1 parent 36e44eb commit 7f8f714
Show file tree
Hide file tree
Showing 47 changed files with 652 additions and 444 deletions.
4 changes: 3 additions & 1 deletion docs/buildDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ const buildDocsForApis = async (apis: Directory[], apisName: "classic" | "cloud"

for (const method of methods) {
const methodName = method.getName()
allJsDocData[apisName][apiName][methodName] = await getJsDocData(method)
try {
allJsDocData[apisName][apiName][methodName] = await getJsDocData(method)
} catch {}
}
}
}
Expand Down
63 changes: 27 additions & 36 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,39 +810,8 @@
]
}
},
"legacyBadges": {
"updateBadge": {
"description": "Updates a badge.",
"tags": {
"endpoint": "PATCH /v1/badges/{badgeId}",
"example": "const { data: success } = await LegacyBadgesApi.updateBadge({ badgeId: 2124533401, description: \"hello\" });",
"exampleData": "",
"exampleRawBody": "{}\n"
},
"params": [
{
"name": "badgeId",
"type": "Identifier",
"description": "The ID of the badge to update."
},
{
"name": "name?",
"type": "string",
"description": "The new name for the badge."
},
{
"name": "description?",
"type": "string",
"description": "The new description for the badge."
},
{
"name": "enabled?",
"type": "boolean",
"description": "If the badge is to enabled."
}
]
}
},
"legacyBadges": {},
"legacyDevelop": {},
"legacyFollowings": {
"universeFollowingsForUser": {
"description": "Gets all universes that a user is following.",
Expand Down Expand Up @@ -924,6 +893,7 @@
]
}
},
"legacyGroups": {},
"luauExecution": {
"executeLuau": {
"description": "Executes a roblox luau script for a given place.",
Expand Down Expand Up @@ -3394,11 +3364,11 @@
}
]
},
"updateTeamCreateSettingsForUniverse": {
"setTeamCreateSettingsForUniverse": {
"description": "Updates team create settings for a universe.",
"tags": {
"endpoint": "PATCH /v1/universes/{universeId}/teamcreate",
"example": "const { data: success } = await ClassicDevelopApi.updateTeamCreateSettingsForUniverse({\n universeId: 6069031486,\n isEnabled: false,\n});",
"example": "const { data: success } = await ClassicDevelopApi.setTeamCreateSettingsForUniverse({\n universeId: 6069031486,\n isEnabled: false,\n});",
"exampleData": "",
"exampleRawBody": "{}\n"
},
Expand Down Expand Up @@ -4300,10 +4270,31 @@
}
]
},
"groupPayoutsUserEligibility": {
"description": "Gets the group payout eligibility for a group of users.",
"tags": {
"endpoint": "GET /v1/groups/{groupId}/users-payout-eligibility",
"example": "const { data: eligibility } = await ClassicEconomyApi.groupPayoutsUserEligibility({\n groupId: 14941564,\n userIds: [1412728377],\n});",
"exampleData": "{ \"1412728377\": \"Eligible\" }\n",
"exampleRawBody": "{ usersGroupPayoutEligibility: { \"1412728377\": \"Eligible\" } }\n"
},
"params": [
{
"name": "groupId",
"type": "Identifier",
"description": "The ID of the group."
},
{
"name": "userIds",
"type": "ArrayNonEmptyIfConst<UserId>",
"description": "The userIds to check for payout eligibility."
}
]
},
"groupTransactionHistory": {
"description": "Gets transaction history for a particular group.",
"tags": {
"endpoint": "GET /v1/group/${groupId}/transactions",
"endpoint": "GET /v2/group/${groupId}/transactions",
"example": "const { data: transactions } = await ClassicEconomyApi.groupTransactionHistory({\n groupId: 5850082,\n transactionType: \"Sale\",\n});",
"exampleData": "[\n {\n id: 14289110391,\n idHash: \"L1HiwSO1f1e68Xh1d50b91\",\n created: \"2022-07-09T21:35:43.013Z\",\n isPending: false,\n agent: { id: 473747714, type: \"User\", name: \"LoremIpsum\" },\n details: {\n id: 1116381,\n name: \"Buy 100 Coins\",\n type: \"DeveloperProduct\",\n place: {\n placeId: 1121711941,\n universeId: 8681831361,\n name: \"LoremIpsumGame\",\n },\n },\n currency: { amount: 0, type: \"Robux\" },\n purchaseToken: null,\n },\n]\n",
"exampleRawBody": "{\n previousPageCursor: null,\n nextPageCursor: \"eyJrZXkiOjEwLCJzb3J0T3JkZXIiOiJBc2MiLCJwYWdpbmdEaXJlY3Rpb24iOiJGb3J3YXJkIiwicGFnZU51bWJlciI6MiwiZGlzY3JpbWluYXRvciI6Imdyb3VwSWQ6NTg1MDA4MnRyYW5zYWN0aW9uVHlwZTpTYWxlIiwiY291bnQiOjEwfQpiYzljYmU0OTFiNjlmNTBmZDBiMGM3YzJmZTVlN2RkMGNlZjY5ZTQ4ZTRiODViZDNiMzBlZGM0NDNiZDMxMmU0\",\n data: [\n {\n id: 14289110391,\n idHash: \"L1HiwSO1f1e68Xh1d50b91\",\n created: \"2022-07-09T21:35:43.013Z\",\n isPending: false,\n agent: { id: 473747714, type: \"User\", name: \"LoremIpsum\" },\n details: {\n id: 1116381,\n name: \"Buy 100 Coins\",\n type: \"DeveloperProduct\",\n place: {\n placeId: 1121711941,\n universeId: 8681831361,\n name: \"LoremIpsumGame\",\n },\n },\n currency: { amount: 0, type: \"Robux\" },\n purchaseToken: null,\n },\n ],\n}\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "openblox",
"description": "Roblox API Wrapper For Both Classic And OpenCloud APIs.",
"type": "commonjs",
"version": "1.0.54",
"version": "1.0.56",
"license": "MIT",
"bugs": {
"url": "https://github.com/MightyPart/openblox/issues"
Expand Down
21 changes: 16 additions & 5 deletions src/apis/apiGroup/apiGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ const pollForResponse = async (url: string, operationPath: string, cloudKey: str
//////////////////////////////////////////////////////////////////////////////////


export const createApiGroup: CreateApiGroupFn = ({ name:groupName, baseUrl, defaultGetCursors:groupDefaultGetCursors }) => (
export const createApiGroup: CreateApiGroupFn = ({ name:groupName, baseUrl, defaultGetCursors:groupDefaultGetCursors }) => ({
// createApiMethod.
(handlerFn) => {
createApiMethod: (handlerFn) => {
const handlerFnArgs = getParams(handlerFn)
const handlerFnCursorArg =
handlerFnArgs.includes("cursor") ? "cursor" :
Expand All @@ -121,7 +121,7 @@ export const createApiGroup: CreateApiGroupFn = ({ name:groupName, baseUrl, defa

const thisDefaultGetCursors = groupDefaultGetCursors ?? defaultGetCursors

return async function callApiMethod(args) {
const createCallApiMethod = (_baseUrl: UrlSecure = baseUrl): CallApiMethod<any, any, boolean> => async function(args) {
const overrides = this
const cookie = overrides?.cookie || config?.cookie
const cloudKey = overrides?.cloudKey || config?.cloudKey
Expand All @@ -135,7 +135,7 @@ export const createApiGroup: CreateApiGroupFn = ({ name:groupName, baseUrl, defa
let formattedSearchParams = formatSearchParams(searchParams)
if (applyFieldMask && body && isObject(body)) formattedSearchParams += `&updateMask=${objectToFieldMask(body as Record<any, any>)}`

const url: UrlSecure = `${baseUrl}${path}${formattedSearchParams ? `?${new URLSearchParams(formattedSearchParams).toString()}` : ""}`
const url: UrlSecure = `${_baseUrl}${path}${formattedSearchParams ? `?${new URLSearchParams(formattedSearchParams).toString()}` : ""}`

// Adds credentials to headers.
if (cookie || cloudKey || oauthToken) {
Expand Down Expand Up @@ -179,5 +179,16 @@ export const createApiGroup: CreateApiGroupFn = ({ name:groupName, baseUrl, defa

return await main()
}

const callApiMethod = createCallApiMethod();

// To handle legacy open cloud endpoints which use classic endpoints but with different base urls.
(callApiMethod as any)._deriveWithDifferentBaseUrl = (baseUrl: UrlSecure) => createCallApiMethod(baseUrl)

return callApiMethod
},

addExistingApiMethod: <Method extends CallApiMethod<any, any, boolean>>(method: Method): Method => {
return (method as any)._deriveWithDifferentBaseUrl(baseUrl)
}
)
})
6 changes: 5 additions & 1 deletion src/apis/apiGroup/apiGroup.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ type ApiGroupProps = {
defaultGetCursors?: (rawData: any) => ([ previous: string | null, next: string | null ])
}

export type CreateApiGroupFn = (props: ApiGroupProps) => AddApiMethodFn
export type CreateApiGroupFn = (props: ApiGroupProps) => {
createApiMethod: AddApiMethodFn,

addExistingApiMethod: <Method extends CallApiMethod<any, any, boolean>>(method: Method) => Method
}
// -------------------------------------------------------------------------------------------------------------------


Expand Down
22 changes: 11 additions & 11 deletions src/apis/classic/badges/badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { PrettifiedBadgeAwardedDateForUserData, PrettifiedBadgeInfoData, Pr


// [ Variables ] /////////////////////////////////////////////////////////////////
const addApiMethod = createApiGroup({ name: "ClassicBadgesApi", baseUrl: "https://badges.roblox.com" })
const { createApiMethod } = createApiGroup({ name: "ClassicBadgesApi", baseUrl: "https://badges.roblox.com" })
//////////////////////////////////////////////////////////////////////////////////


Expand All @@ -33,7 +33,7 @@ const addApiMethod = createApiGroup({ name: "ClassicBadgesApi", baseUrl: "https:
* @exampleData {"id":2124533401,"name":"Tutorial Done","description":"Tutorial Lol","displayName":"Tutorial Done","displayDescription":"Tutorial Lol","enabled":true,"iconImageId":5316501478,"displayIconImageId":5316501478,"created":"2020-05-05T08:20:10.653Z","updated":"2023-08-26T12:43:15.280Z","statistics":{"pastDayAwardedCount":0,"awardedCount":394,"winRatePercentage":0},"awardingUniverse":{"id":1685831367,"name":"RoCamping","rootPlaceId":4922741943}}
* @exampleRawBody {"id":2124533401,"name":"Tutorial Done","description":"Tutorial Lol","displayName":"Tutorial Done","displayDescription":"Tutorial Lol","enabled":true,"iconImageId":5316501478,"displayIconImageId":5316501478,"created":"2020-05-05T08:20:10.653Z","updated":"2023-08-26T12:43:15.280Z","statistics":{"pastDayAwardedCount":0,"awardedCount":394,"winRatePercentage":0},"awardingUniverse":{"id":1685831367,"name":"RoCamping","rootPlaceId":4922741943}}
*/
export const badgeInfo = addApiMethod(async <BadgeId extends Identifier>(
export const badgeInfo = createApiMethod(async <BadgeId extends Identifier>(
{ badgeId }: { badgeId: BadgeId }
): ApiMethod<RawBadgeInfoData<BadgeId>, PrettifiedBadgeInfoData<BadgeId>> => ({
method: "GET",
Expand All @@ -60,7 +60,7 @@ export const badgeInfo = addApiMethod(async <BadgeId extends Identifier>(
* @exampleData true
* @exampleRawBody {}
*/
export const updateBadge = addApiMethod(async (
export const updateBadge = createApiMethod(async (
{ badgeId, name, description, enabled }: { badgeId: Identifier, name?: string, description?: string, enabled?: boolean }
): ApiMethod<{}, boolean> => ({
method: "PATCH",
Expand All @@ -80,7 +80,7 @@ export const updateBadge = addApiMethod(async (
* @exampleData {"badgeCreationPrice":100,"maxBadgeNameLength":50,"maxBadgeDescriptionLength":1000}
* @exampleRawBody {"badgeCreationPrice":100,"maxBadgeNameLength":50,"maxBadgeDescriptionLength":1000}
*/
export const badgesMetadata = addApiMethod(async (
export const badgesMetadata = createApiMethod(async (
): ApiMethod<{ badgeCreationPrice: number, maxBadgeNameLength: number, maxBadgeDescriptionLength: number }> => ({
method: "GET",
path: `/v1/badges/metadata`,
Expand All @@ -101,7 +101,7 @@ export const badgesMetadata = addApiMethod(async (
* @exampleData [{"id":2124533401,"name":"Tutorial Done","description":"true","displayName":"Tutorial Done","displayDescription":"true","enabled":true,"iconImageId":5316501478,"displayIconImageId":5316501478,"created":"2020-05-05T08:20:10.653Z","updated":"2024-07-16T22:34:44.021Z","statistics":{"pastDayAwardedCount":0,"awardedCount":394,"winRatePercentage":0},"awardingUniverse":{"id":1685831367,"name":"RoCamping","rootPlaceId":4922741943}}]
* @exampleRawBody {"previousPageCursor":null,"nextPageCursor":"eyJrZXkiOiJpZF8yendBQUFYSGo2OEVkem42aHpwayIsInNvcnRPcmRlciI6IkFzYyIsInBhZ2luZ0RpcmVjdGlvbiI6IkZvcndhcmQiLCJwYWdlTnVtYmVyIjoyLCJkaXNjcmltaW5hdG9yIjoidW5pdmVyc2VJZDoxNjg1ODMxMzY3IiwiY291bnQiOjEwfQplMzk4ODQzNTg5NGYxNzU4MTk1YmVlNWFhMDE5NTI1MmJiMjdhZDRiYzU5YzE3NjNjNjg3M2UxYmExNDdkMWZh","data":[{"id":2124533401,"name":"Tutorial Done","description":"true","displayName":"Tutorial Done","displayDescription":"true","enabled":true,"iconImageId":5316501478,"displayIconImageId":5316501478,"created":"2020-05-05T08:20:10.653+00:00","updated":"2024-07-16T22:34:44.021+00:00","statistics":{"pastDayAwardedCount":0,"awardedCount":394,"winRatePercentage":0},"awardingUniverse":{"id":1685831367,"name":"RoCamping","rootPlaceId":4922741943}}]}
*/
export const badgesForUniverse = addApiMethod(async <UniverseId extends Identifier>(
export const badgesForUniverse = createApiMethod(async <UniverseId extends Identifier>(
{ universeId, limit, sortOrder, cursor }: { universeId: UniverseId, limit?: 10 | 25 | 50 | 100, sortOrder?: SortOrder, cursor?: string }
): ApiMethod<RawPaginatedBadgesData<UniverseId>, PrettifiedPaginatedBadgesData<UniverseId>> => ({
method: "GET",
Expand All @@ -126,7 +126,7 @@ export const badgesForUniverse = addApiMethod(async <UniverseId extends Identifi
* @exampleData 5
* @exampleRawBody 5
*/
export const freeBadgesLeftForUniverse = addApiMethod(async (
export const freeBadgesLeftForUniverse = createApiMethod(async (
{ universeId }: { universeId: Identifier }
): ApiMethod<number> => ({
method: "GET",
Expand All @@ -148,7 +148,7 @@ export const freeBadgesLeftForUniverse = addApiMethod(async (
* @exampleData [{"id":2124533401,"name":"Tutorial Done","description":"true","displayName":"Tutorial Done","displayDescription":"true","enabled":true,"iconImageId":5316501478,"displayIconImageId":5316501478,"created":"2020-05-05T08:20:10.653Z","updated":"2024-07-16T22:34:44.021Z","statistics":{"pastDayAwardedCount":0,"awardedCount":394,"winRatePercentage":0},"awardingUniverse":{"id":1685831367,"name":"RoCamping","rootPlaceId":4922741943}}]
* @exampleRawBody {"previousPageCursor":null,"nextPageCursor":"eyJrZXkiOiJpZF8yendBQUFYSGo2OEVkem42aHpwayIsInNvcnRPcmRlciI6IkFzYyIsInBhZ2luZ0RpcmVjdGlvbiI6IkZvcndhcmQiLCJwYWdlTnVtYmVyIjoyLCJkaXNjcmltaW5hdG9yIjoidW5pdmVyc2VJZDoxNjg1ODMxMzY3IiwiY291bnQiOjEwfQplMzk4ODQzNTg5NGYxNzU4MTk1YmVlNWFhMDE5NTI1MmJiMjdhZDRiYzU5YzE3NjNjNjg3M2UxYmExNDdkMWZh","data":[{"id":2124533401,"name":"Tutorial Done","description":"true","displayName":"Tutorial Done","displayDescription":"true","enabled":true,"iconImageId":5316501478,"displayIconImageId":5316501478,"created":"2020-05-05T08:20:10.653+00:00","updated":"2024-07-16T22:34:44.021+00:00","statistics":{"pastDayAwardedCount":0,"awardedCount":394,"winRatePercentage":0},"awardingUniverse":{"id":1685831367,"name":"RoCamping","rootPlaceId":4922741943}}]}
*/
export const userBadges = addApiMethod(async (
export const userBadges = createApiMethod(async (
{ userId, limit, sortOrder, cursor }: { userId: Identifier, limit?: 10 | 25 | 50 | 100, sortOrder?: SortOrder, cursor?: string }
): ApiMethod<RawPaginatedBadgesData, PrettifiedPaginatedBadgesData> => ({
method: "GET",
Expand Down Expand Up @@ -177,7 +177,7 @@ export const userBadges = addApiMethod(async (
* @exampleData 2020-11-15T18:51:30.604Z
* @exampleRawBody {"badgeId":2124533401,"awardedDate":"2020-11-15T18:51:30.604064Z"}
*/
export const badgeAwardedDateForUser = addApiMethod(async <BadgeId extends Identifier>(
export const badgeAwardedDateForUser = createApiMethod(async <BadgeId extends Identifier>(
{ badgeId, userId }: { badgeId: BadgeId, userId: Identifier }
): ApiMethod<RawBadgeAwardedDateForUserData<BadgeId>, PrettifiedBadgeAwardedDateForUserData> => ({
method: "GET",
Expand All @@ -202,7 +202,7 @@ export const badgeAwardedDateForUser = addApiMethod(async <BadgeId extends Ident
* @exampleData {"2124533401":"2020-11-15T18:51:30.604Z"}
* @exampleRawBody {"data":[{"badgeId":2124533401,"awardedDate":"2020-11-15T18:51:30.604064Z"}]}
*/
export const badgesAwardedDatesForUser = addApiMethod(async <BadgeId extends Identifier>(
export const badgesAwardedDatesForUser = createApiMethod(async <BadgeId extends Identifier>(
{ badgeIds, userId }: { badgeIds: ArrayNonEmptyIfConst<BadgeId>, userId: Identifier }
): ApiMethod<RawBadgesAwardedDatesForUserData<BadgeId>, PrettifiedBadgesAwardedDatesForUserData<BadgeId>> => ({
method: "GET",
Expand All @@ -225,7 +225,7 @@ export const badgesAwardedDatesForUser = addApiMethod(async <BadgeId extends Ide
* @exampleData true
* @exampleRawBody {}
*/
export const removeBadgeFromUser = addApiMethod(async (
export const removeBadgeFromUser = createApiMethod(async (
{ badgeId, userId }: { badgeId: Identifier, userId: Identifier }
): ApiMethod<{}, boolean> => ({
method: "DELETE",
Expand All @@ -246,7 +246,7 @@ export const removeBadgeFromUser = addApiMethod(async (
* @exampleData true
* @exampleRawBody {}
*/
export const authenticatedUserRemoveBadge = addApiMethod(async (
export const authenticatedUserRemoveBadge = createApiMethod(async (
{ badgeId }: { badgeId: Identifier }
): ApiMethod<{}, boolean> => ({
method: "DELETE",
Expand Down
Loading

0 comments on commit 7f8f714

Please sign in to comment.