Add functions to support JSON endpoint.

This commit is contained in:
maxswa
2023-08-11 14:52:02 -04:00
parent c43858eac1
commit 5a2b0d9ad8
8 changed files with 472 additions and 19 deletions

View File

@@ -6,7 +6,8 @@ import {
STATS_URL,
SCORES_URL,
SKILLS,
ACTIVITIES
ACTIVITIES,
JSON_STATS_URL
} from './constants';
/**
@@ -14,10 +15,13 @@ import {
*
* @param gamemode Gamemode to fetch ranks for.
* @param rsn Username of the player.
* @param json If the JSON endpoint is desired instead of CSV.
* @returns Encoded stats URL.
*/
export const getStatsURL = (gamemode: Gamemode, rsn: string) =>
`${GAMEMODE_URL[gamemode]}${STATS_URL}${encodeURIComponent(rsn)}`;
export const getStatsURL = (gamemode: Gamemode, rsn: string, json = false) =>
`${GAMEMODE_URL[gamemode]}${
json ? JSON_STATS_URL : STATS_URL
}${encodeURIComponent(rsn)}`;
/**
* Will generate a player table URL for the official OSRS hiscores website.