From b0cc74274e8343530065e7263f272cfe423c4f0a Mon Sep 17 00:00:00 2001 From: Austin-Wahl Date: Tue, 18 Jun 2024 18:05:47 -0500 Subject: [PATCH] added BeatLeader Leaderboard API support. Accounted for undocumented errors thrown by BeatLeader --- docs/BeatLeader.Clans.html | 2 +- docs/BeatLeader.Leaderboards.html | 3 + docs/BeatLeader.html | 2 +- docs/BeatLeader_Clan.js.html | 52 +++--- docs/BeatLeader_Leaderboard.js.html | 160 +++++++++++++++++++ docs/ScoreSaber.Leaderboard.html | 2 +- docs/ScoreSaber.Players.html | 2 +- docs/ScoreSaber.Ranking.Public.html | 2 +- docs/ScoreSaber.Ranking.html | 2 +- docs/ScoreSaber.html | 2 +- docs/Scoresaber_leaderboard.js.html | 4 +- docs/Scoresaber_player.js.html | 4 +- docs/Scoresaber_ranking.js.html | 4 +- docs/data/search.json | 2 +- docs/index.html | 6 +- docs/index.js.html | 4 +- src/BeatLeader/Clan.js | 48 +++--- src/BeatLeader/Leaderboard.js | 157 +++++++++++++++++- src/BeatLeader/types/BeatLeader.d.ts | 2 + src/BeatLeader/utility/parseSearchOptions.js | 17 ++ src/index.d.ts | 2 +- 21 files changed, 398 insertions(+), 81 deletions(-) create mode 100644 docs/BeatLeader.Leaderboards.html create mode 100644 docs/BeatLeader_Leaderboard.js.html create mode 100644 src/BeatLeader/utility/parseSearchOptions.js diff --git a/docs/BeatLeader.Clans.html b/docs/BeatLeader.Clans.html index 4ef49ad..21fa26b 100644 --- a/docs/BeatLeader.Clans.html +++ b/docs/BeatLeader.Clans.html @@ -1,3 +1,3 @@ Namespace: Clans
On this page

BeatLeader. Clans

Methods

(static) get(searchOptions)

Retrieves a list of clans based on filters

Parameters:
NameTypeDescription
searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number.
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criterianame, pp, acc, rank, count, captures
orderOrder(Optional) Sorting orderdesc, asc
searchstring(Optional) Search query
Returns:

A promise with a list of clans

(static) getById(id, searchOptions, primary)

Fetches details of a specific clan identified by its ID.

Parameters:
NameTypeDescription
idnumber

ID of the clan to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, topPp, name, rank, acc, weightedAcc, top1Count, top1Score, weightedRank, topAcc, hmd, playCount, score, lastplay, maxStreak, replaysWatched, dailyImprovements, timing
orderOrder(Optional) Sorting orderdesc, asc
primaryboolean

Whether to include only players for whom this clan is primary, default is false

Returns:

A promise with a clan

(static) getByTag(tag, searchOptions, primary)

Retrieves details of a specific clan by tag

Parameters:
NameTypeDescription
tagstring

Tag of the clans to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, topPp, name, rank, acc, weightedAcc, top1Count, top1Score, weightedRank, topAcc, hmd, playCount, score, lastplay, maxStreak, replaysWatched, dailyImprovements, timing
orderOrder(Optional) Sorting orderdesc, asc
searchstring(Optional) Search query
primaryboolean

Whether to include only players for whom this clan is primary, default is false

Returns:

A promise with a clan

(static) getGlobalMap()

Fetches a global map showing clan captured maps and rankings.

Returns:

A promise with the Global Map

(static) getMapsById(id, searchOptions)

Fetches ranked maps(maps that can be captured on the global map) for where players of clan made scores identified by its ID, with optional sorting and filtering.

Parameters:
NameTypeDescription
idstring

ID of the clans to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, acc, rank, date, tohold, toconquer
leaderboardContextLeaderboardContext(Optional) Context of leaderboard. Default is Generalnone, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup
orderOrder(Optional) Sorting orderdesc, asc
Returns:

A promise with a list of ranked maps

(static) getMapsByTag(tag, searchOptions)

Retrieves a list of clans based on filters

Parameters:
NameTypeDescription
tagstring

Tag of the clans to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, acc, rank, date, tohold, toconquer
leaderboardContextLeaderboardContext(Optional) Context of leaderboard. Default is Generalnone, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup
orderOrder(Optional) Sorting orderdesc, asc
Returns:

A promise with a list of ranked maps

\ No newline at end of file +
On this page

BeatLeader. Clans

Methods

(static) get(searchOptions) → {Promise}

Retrieves a list of clans based on filters

Parameters:
NameTypeDescription
searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number.
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criterianame, pp, acc, rank, count, captures
orderOrder(Optional) Sorting orderdesc, asc
searchstring(Optional) Search query
Returns:

A promise with a list of clans

Type: 
Promise

(static) getById(id, searchOptions, primary) → {Promise}

Fetches details of a specific clan identified by its ID.

Parameters:
NameTypeDescription
idnumber

ID of the clan to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, topPp, name, rank, acc, weightedAcc, top1Count, top1Score, weightedRank, topAcc, hmd, playCount, score, lastplay, maxStreak, replaysWatched, dailyImprovements, timing
orderOrder(Optional) Sorting orderdesc, asc
primaryboolean

Whether to include only players for whom this clan is primary, default is false

Returns:

A promise with a clan

Type: 
Promise

(static) getByTag(tag, searchOptions, primary) → {Promise}

Retrieves details of a specific clan by tag

Parameters:
NameTypeDescription
tagstring

Tag of the clans to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, topPp, name, rank, acc, weightedAcc, top1Count, top1Score, weightedRank, topAcc, hmd, playCount, score, lastplay, maxStreak, replaysWatched, dailyImprovements, timing
orderOrder(Optional) Sorting orderdesc, asc
searchstring(Optional) Search query
primaryboolean

Whether to include only players for whom this clan is primary, default is false

Returns:

A promise with a clan

Type: 
Promise

(static) getGlobalMap() → {Promise}

Fetches a global map showing clan captured maps and rankings.

Returns:

A promise with the Global Map

Type: 
Promise

(static) getMapsById(id, searchOptions) → {Promise}

Fetches ranked maps(maps that can be captured on the global map) for where players of clan made scores identified by its ID, with optional sorting and filtering.

Parameters:
NameTypeDescription
idstring

ID of the clans to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, acc, rank, date, tohold, toconquer
leaderboardContextLeaderboardContext(Optional) Context of leaderboard. Default is Generalnone, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup
orderOrder(Optional) Sorting orderdesc, asc
Returns:

A promise with a list of ranked maps

Type: 
Promise

(static) getMapsByTag(tag, searchOptions) → {Promise}

Retrieves a list of clans based on filters

Parameters:
NameTypeDescription
tagstring

Tag of the clans to retrieve details for

searchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page number
countnumber(Optional) Number of items per page
sortByClanSortBy(Optional) Sorting criteriapp, acc, rank, date, tohold, toconquer
leaderboardContextLeaderboardContext(Optional) Context of leaderboard. Default is Generalnone, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup
orderOrder(Optional) Sorting orderdesc, asc
Returns:

A promise with a list of ranked maps

Type: 
Promise
\ No newline at end of file diff --git a/docs/BeatLeader.Leaderboards.html b/docs/BeatLeader.Leaderboards.html new file mode 100644 index 0000000..3edae7e --- /dev/null +++ b/docs/BeatLeader.Leaderboards.html @@ -0,0 +1,3 @@ +Namespace: Leaderboards
On this page

BeatLeader. Leaderboards

Methods

(static) get(leaderboardSearchOptions) → {Promise}

Retrieves a list of leaderboards

Parameters:
NameTypeDescription
leaderboardSearchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page numberN/A
countnumber(Optional) Number of items per pageN/A
sortByLeaderboardSortBy(Optional) Sorting criteria0, 1, 2, 3, 4, 5, 6, 7, 8, "date", "pp", "acc", "pauses", "rank", "maxStreak", "mistakes", "weight", "weightedPp"
orderOrderSorting order"asc", "desc"
searchstring(Optional) Search queryN/A
typeType(Optional) Type of itemN/A
modestring(Optional) Mode of itemN/A
difficultyDifficulties(Optional) Difficulty level"Standard", "OneSaber", "90Degree", "360Degree"
mapTypeMapsType(Optional) Map type0, 1, 2, "ranked", "unranked", "all"
allTypesOperation(Optional) Operation for all types0, 1, 2, "any", "all", "not"
mapRequirementsRequirementsString(Optional) Map requirements"none", "chroma", "noodles", "mappingExtensions", "cinema", "v3", "optionalProperties", "ignore"
allRequirementsOperation(Optional) Operation for all requirements0, 1, 2, "any", "all", "not"
songStatusSongStatus(Optional) Status of the song0, 2, 4, 8, 16, 32, "none", "curated", "mapOfTheWeek", "noodleMonday", "featuredOnCC", "beastSaberAwarded"
leaderboardContextLeaderboardContexts(Optional) Context of the leaderboard0, 2, 4, 8, 16, 32, 64, 128, "none", "general", "noMods", "noPause", "golf", "sCPM", "speedrun", "speedrunBackup"
mytypeMyType(Optional) Custom type0, 1, 2, 3, 4, 5, 6, "none", "played", "unplayed", "myNominated", "othersNominated", "myMaps"
stars_fromnumber(Optional) Minimum starsN/A
stars_tonumber(Optional) Maximum starsN/A
accrating_fromnumber(Optional) Minimum accuracy ratingN/A
accrating_tonumber(Optional) Maximum accuracy ratingN/A
passrating_fromnumber(Optional) Minimum pass ratingN/A
passrating_tonumber(Optional) Maximum pass ratingN/A
techrating_fromnumber(Optional) Minimum tech ratingN/A
techrating_tonumber(Optional) Maximum tech ratingN/A
date_fromnumber(Optional) Start dateN/A
mappernumber(Optional) Mapper IDN/A
overrideCurrentIdstring(Optional) Override current IDN/A
Returns:

A promise with a list of leaderboards

Type: 
Promise

(static) getById(id, leaderboardSearchOptions) → {Promise}

Retrieves a list of leaderboards

Parameters:
NameTypeDescription
idstring

ID of the leaderboard to retrieve details for

leaderboardSearchOptionsObject

Filters to narrow search. See options in table below

ParameterTypeDescriptionValid Values
pagenumber(Optional) Page numberN/A
countnumber(Optional) Number of items per pageN/A
sortByLeaderboardSortBy(Optional) Sorting criteria0, 1, 2, 3, 4, 5, 6, 7, 8, "date", "pp", "acc", "pauses", "rank", "maxStreak", "mistakes", "weight", "weightedPp"
orderOrderSorting order"asc", "desc"
scoreStatusScoreFilterStatus(Optional) Score status filter0, 1, "none", "suspicious"
leaderboardContextLeaderboardContexts(Optional) Context of the leaderboard0, 2, 4, 8, 16, 32, 64, 128, "none", "general", "noMods", "noPause", "golf", "sCPM", "speedrun", "speedrunBackup"
countriesArray(Optional) List of country codesN/A
searchstring(Optional) Search queryN/A
modifiersstring(Optional) ModifiersN/A
friendsboolean(Optional) Filter by friendsN/A
votersboolean(Optional) Filter by votersN/A
predictionboolean(Optional) Prediction filterN/A
Returns:

A promise with leaderboard details

Type: 
Promise

(static) getClanRankingsById(id, page, count) → {Promise}

Retrieves clan rankings for a leaderboard

Parameters:
NameTypeDescription
idstring

ID of the leaderboard to retrieve clan rankings for

pagenumber

Page number for pagination, default is 1

countnumber

Number of rankings per page, default is 10

Returns:

A promise with clan rankings

Type: 
Promise

(static) getScoregraphById(id) → {Promise}

Retrieves the score graph for a leaderboard

Parameters:
NameTypeDescription
idstring

ID of the leaderboard to retrieve the score graph for

Returns:

A promise with score graph data

Type: 
Promise
\ No newline at end of file diff --git a/docs/BeatLeader.html b/docs/BeatLeader.html index 72dccdf..406e56e 100644 --- a/docs/BeatLeader.html +++ b/docs/BeatLeader.html @@ -1,3 +1,3 @@ Namespace: BeatLeader
On this page

BeatLeader

Interact with the BeatLeader API using this NPM wrapper library. Currently supports all BeatLeader endpoints found under BeatLeaderAPI v1.

Namespaces

Clans
\ No newline at end of file +
On this page

BeatLeader

Interact with the BeatLeader API using this NPM wrapper library. Currently supports all BeatLeader endpoints found under BeatLeaderAPI v1.

Namespaces

Clans
Leaderboards
\ No newline at end of file diff --git a/docs/BeatLeader_Clan.js.html b/docs/BeatLeader_Clan.js.html index 01e8f8c..3233a35 100644 --- a/docs/BeatLeader_Clan.js.html +++ b/docs/BeatLeader_Clan.js.html @@ -1,6 +1,7 @@ Source: BeatLeader/Clan.js
On this page

BeatLeader_Clan.js

const {beatleader} = require('../api_urls.json').urls
+    
On this page

BeatLeader_Clan.js

const {beatleader} = require('../api_urls.json').urls
+const {parseSearchOptions} = require('./utility/parseSearchOptions')
 
 /**
  * @namespace BeatLeader.Clans
@@ -19,7 +20,7 @@
  * | sortBy    | ClanSortBy  | (Optional) Sorting criteria         | name, pp, acc, rank, count, captures |
  * | order     | Order       | (Optional) Sorting order            | desc, asc     |
  * | search    | string      | (Optional) Search query             |        |
- * @returns A promise with a list of clans
+ * @returns {Promise} A promise with a list of clans
  */
 async function get(searchOptions = {}) {
     try {
@@ -32,7 +33,8 @@
             return Promise.reject(new Error("Invalid request parameters"))
         if(res.status == 404)
             return Promise.reject(new Error("Clans not found"))
-        
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
         return res.json()
     } catch (error) {
         throw new Error(error)
@@ -53,7 +55,7 @@
  * | order     | Order       | (Optional) Sorting order            | desc, asc     |
  * | search    | string      | (Optional) Search query             |        |
  * @param {boolean} primary Whether to include only players for whom this clan is primary, default is false
- * @returns A promise with a clan
+ * @returns {Promise} A promise with a clan
  */
 async function getByTag(tag, searchOptions = {}, primary = false) {
     try {
@@ -66,7 +68,8 @@
         let res = await fetch(encodeURI(route))
         if(res.status == 404)
             return Promise.reject(new Error("Clan not found"))
-
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
         return res.json()
     } catch (error) {
         throw new Error(error)
@@ -86,7 +89,7 @@
  * | sortBy    | ClanSortBy  | (Optional) Sorting criteria         | pp, topPp, name, rank, acc, weightedAcc, top1Count, top1Score, weightedRank, topAcc, hmd, playCount, score, lastplay, maxStreak, replaysWatched, dailyImprovements, timing |
  * | order     | Order       | (Optional) Sorting order            | desc, asc     |
  * @param {boolean} primary Whether to include only players for whom this clan is primary, default is false
- * @returns A promise with a clan
+ * @returns {Promise} A promise with a clan
  */
 async function getById(id, searchOptions = {}, primary = false) {
     try {
@@ -99,7 +102,8 @@
         let res = await fetch(encodeURI(route))
         if(res.status == 404)
             return Promise.reject(new Error("Clan not found"))
-
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
         return res.json()
     } catch (error) {
         throw new Error(error)
@@ -119,7 +123,7 @@
  * | sortBy             | ClanSortBy         | (Optional) Sorting criteria                          | pp, acc, rank, date, tohold, toconquer |
  * | leaderboardContext | LeaderboardContext | (Optional) Context of leaderboard. Default is General| none, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup |
  * | order              | Order              | (Optional) Sorting order                             | desc, asc     |
- * @returns A promise with a list of ranked maps 
+ * @returns {Promise} A promise with a list of ranked maps 
  */
 async function getMapsByTag(tag, searchOptions = {}) {
     try {
@@ -131,7 +135,8 @@
         let res = await fetch(encodeURI(route))
         if(res.status == 404)
             return Promise.reject(new Error("Clan not found"))
-
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
         return res.json()
     } catch (error) {
         throw new Error(error)
@@ -151,7 +156,7 @@
  * | sortBy             | ClanSortBy         | (Optional) Sorting criteria                          | pp, acc, rank, date, tohold, toconquer |
  * | leaderboardContext | LeaderboardContext | (Optional) Context of leaderboard. Default is General| none, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup |
  * | order              | Order              | (Optional) Sorting order                             | desc, asc     |
- * @returns A promise with a list of ranked maps
+ * @returns {Promise} A promise with a list of ranked maps
  */
 async function getMapsById(id, searchOptions = {}) {
     try {
@@ -163,7 +168,8 @@
         let res = await fetch(encodeURI(route))
         if(res.status == 404)
             return Promise.reject(new Error("Clan not found"))
-
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
         return res.json()
     } catch (error) {
         throw new Error(error)
@@ -174,7 +180,7 @@
  * Fetches a global map showing clan captured maps and rankings.
  * @function getGlobalMap
  * @memberof BeatLeader.Clans
- * @returns A promise with the Global Map
+ * @returns {Promise} A promise with the Global Map
  */
 async function getGlobalMap() {
     try {
@@ -183,30 +189,14 @@
         let res = await fetch(encodeURI(route))
         if(res.status == 404)
             return Promise.reject(new Error("Global map not found"))
-
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
         return res.json()
     } catch (error) {
         throw new Error(error)
     }
 }
 
-// utility 
-function parseSearchOptions(searchOptions) {
-    let route = ''
-    if(Object.keys(searchOptions).length > 0) {
-        route += '?'
-        let i = 1
-        for(key in searchOptions) {
-            if(i < Object.keys(searchOptions).length)
-                route += `${key}=${searchOptions[key]}&`
-            else 
-                route += `${key}=${searchOptions[key]}`
-            i++
-        }
-    } 
-    return route
-}
-
 exports.BeatLeaderClans = {
     get: get,
     getByTag: getByTag,
@@ -214,4 +204,4 @@
     getMapsByTag: getMapsByTag,
     getMapsById: getMapsById,
     getGlobalMap: getGlobalMap
-}
\ No newline at end of file +}
\ No newline at end of file diff --git a/docs/BeatLeader_Leaderboard.js.html b/docs/BeatLeader_Leaderboard.js.html new file mode 100644 index 0000000..4c24403 --- /dev/null +++ b/docs/BeatLeader_Leaderboard.js.html @@ -0,0 +1,160 @@ +Source: BeatLeader/Leaderboard.js
On this page

BeatLeader_Leaderboard.js

const {beatleader} = require('../api_urls.json').urls
+const {parseSearchOptions} = require('./utility/parseSearchOptions')
+
+/**
+ * @namespace BeatLeader.Leaderboards
+ * @memberof BeatLeader
+ */
+
+/**
+ * Retrieves a list of leaderboards
+ * @function get
+ * @memberof BeatLeader.Leaderboards
+ * @param {Object} leaderboardSearchOptions Filters to narrow search. See options in table below
+ * | Parameter           | Type                    | Description                          | Valid Values                                                                                       |
+ * |---------------------|-------------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------|
+ * | page                | number                  | (Optional) Page number               | N/A                                                                                                 |
+ * | count               | number                  | (Optional) Number of items per page  | N/A                                                                                                 |
+ * | sortBy              | LeaderboardSortBy       | (Optional) Sorting criteria          | 0, 1, 2, 3, 4, 5, 6, 7, 8, "date", "pp", "acc", "pauses", "rank", "maxStreak", "mistakes", "weight", "weightedPp" |
+ * | order               | Order                   | Sorting order                        | "asc", "desc"                                                                                       |
+ * | search              | string                  | (Optional) Search query              | N/A                                                                                                 |
+ * | type                | Type                    | (Optional) Type of item              | N/A                                                                                                 |
+ * | mode                | string                  | (Optional) Mode of item              | N/A                                                                                                 |
+ * | difficulty          | Difficulties            | (Optional) Difficulty level          | "Standard", "OneSaber", "90Degree", "360Degree"                                                     |
+ * | mapType             | MapsType                | (Optional) Map type                  | 0, 1, 2, "ranked", "unranked", "all"                                                                |
+ * | allTypes            | Operation               | (Optional) Operation for all types   | 0, 1, 2, "any", "all", "not"                                                                        |
+ * | mapRequirements     | RequirementsString      | (Optional) Map requirements          | "none", "chroma", "noodles", "mappingExtensions", "cinema", "v3", "optionalProperties", "ignore"    |
+ * | allRequirements     | Operation               | (Optional) Operation for all requirements | 0, 1, 2, "any", "all", "not"                                                                    |
+ * | songStatus          | SongStatus              | (Optional) Status of the song        | 0, 2, 4, 8, 16, 32, "none", "curated", "mapOfTheWeek", "noodleMonday", "featuredOnCC", "beastSaberAwarded" |
+ * | leaderboardContext  | LeaderboardContexts     | (Optional) Context of the leaderboard | 0, 2, 4, 8, 16, 32, 64, 128, "none", "general", "noMods", "noPause", "golf", "sCPM", "speedrun", "speedrunBackup" |
+ * | mytype              | MyType                  | (Optional) Custom type               | 0, 1, 2, 3, 4, 5, 6, "none", "played", "unplayed", "myNominated", "othersNominated", "myMaps"      |
+ * | stars_from          | number                  | (Optional) Minimum stars             | N/A                                                                                                 |
+ * | stars_to            | number                  | (Optional) Maximum stars             | N/A                                                                                                 |
+ * | accrating_from      | number                  | (Optional) Minimum accuracy rating   | N/A                                                                                                 |
+ * | accrating_to        | number                  | (Optional) Maximum accuracy rating   | N/A                                                                                                 |
+ * | passrating_from     | number                  | (Optional) Minimum pass rating       | N/A                                                                                                 |
+ * | passrating_to       | number                  | (Optional) Maximum pass rating       | N/A                                                                                                 |
+ * | techrating_from     | number                  | (Optional) Minimum tech rating       | N/A                                                                                                 |
+ * | techrating_to       | number                  | (Optional) Maximum tech rating       | N/A                                                                                                 |
+ * | date_from           | number                  | (Optional) Start date                | N/A                                                                                                 |
+ * | mapper              | number                  | (Optional) Mapper ID                 | N/A                                                                                                 |
+ * | overrideCurrentId   | string                  | (Optional) Override current ID       | N/A                                                                                                 |
+ * @returns {Promise} A promise with a list of leaderboards
+ */
+async function get(leaderboardSearchOptions = {}) {
+    try {
+        let route = new URL(beatleader + 'leaderboards').href
+        let parsedSearchOptions = parseSearchOptions(leaderboardSearchOptions)
+        route += parsedSearchOptions
+
+        let res = await fetch(encodeURI(route))
+        if(res.status == 404)
+            return Promise.reject(new Error("Leaderboards not found"))
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
+        return res.json()
+    } catch (error) {
+        throw new Error(error)
+    }
+}
+
+/**
+ * Retrieves a list of leaderboards
+ * @function getById
+ * @memberof BeatLeader.Leaderboards
+ * @param {string} id ID of the leaderboard to retrieve details for
+ * @param {Object} leaderboardSearchOptions Filters to narrow search. See options in table below
+ * | Parameter           | Type                    | Description                          | Valid Values                                                                                       |
+ * |---------------------|-------------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------|
+ * | page                | number                  | (Optional) Page number               | N/A                                                                                                 |
+ * | count               | number                  | (Optional) Number of items per page  | N/A                                                                                                 |
+ * | sortBy              | LeaderboardSortBy       | (Optional) Sorting criteria          | 0, 1, 2, 3, 4, 5, 6, 7, 8, "date", "pp", "acc", "pauses", "rank", "maxStreak", "mistakes", "weight", "weightedPp" |
+ * | order               | Order                   | Sorting order                        | "asc", "desc"                                                                                       |
+ * | scoreStatus         | ScoreFilterStatus       | (Optional) Score status filter       | 0, 1, "none", "suspicious"                                                                                                 |
+ * | leaderboardContext  | LeaderboardContexts     | (Optional) Context of the leaderboard | 0, 2, 4, 8, 16, 32, 64, 128, "none", "general", "noMods", "noPause", "golf", "sCPM", "speedrun", "speedrunBackup" |
+ * | countries           | Array<string>           | (Optional) List of country codes     | N/A                                                                                                 |
+ * | search              | string                  | (Optional) Search query              | N/A                                                                                                 |
+ * | modifiers           | string                  | (Optional) Modifiers                 | N/A                                                                                                 |
+ * | friends             | boolean                 | (Optional) Filter by friends         | N/A                                                                                                 |
+ * | voters              | boolean                 | (Optional) Filter by voters          | N/A                                                                                                 |
+ * | prediction          | boolean                 | (Optional) Prediction filter         | N/A                                                                                                 |
+ * @returns {Promise} A promise with leaderboard details
+ */
+async function getById(id, leaderboardSearchOptions = {}) {
+    try {
+        let route = new URL(beatleader + 'leaderboard').href
+        route += `/${id}`
+        let parsedSearchOptions = parseSearchOptions(leaderboardSearchOptions)
+        route += parsedSearchOptions
+
+        let res = await fetch(encodeURI(route))
+        if(res.status == 404)
+            return Promise.reject(new Error("Leaderboard not found"))
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
+        return res.json()
+    } catch (error) {
+        throw new Error(error)
+    }
+}
+
+/**
+ * Retrieves clan rankings for a leaderboard
+ * @function getClanRankingsById
+ * @memberof BeatLeader.Leaderboards
+ * @param {string} id ID of the leaderboard to retrieve clan rankings for
+ * @param {number} page Page number for pagination, default is 1
+ * @param {number} count Number of rankings per page, default is 10
+ * @returns {Promise} A promise with clan rankings
+ */
+async function getClanRankingsById(id, page = 1, count = 10) {
+    try {
+        let route = new URL(beatleader + 'leaderboard/clanRankings').href
+        route += `/${id}?page=${page}&count=${count}`
+
+        let res = await fetch(encodeURI(route))
+        if(res.status == 404)
+            return Promise.reject(new Error("Clan rankings not found"))
+
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
+
+        return res.json()
+    } catch (error) {
+        throw new Error(error)
+    }
+}
+
+/**
+ * Retrieves the score graph for a leaderboard
+ * @function getScoregraphById
+ * @memberof BeatLeader.Leaderboards
+ * @param {string} id ID of the leaderboard to retrieve the score graph for
+ * @returns {Promise} A promise with score graph data
+ */
+async function getScoregraphById(id) {
+    try {
+        let route = new URL(beatleader + 'leaderboard').href
+        route += `/${id}/scoregraph`
+
+        let res = await fetch(encodeURI(route))
+        if(res.status == 404)
+            return Promise.reject(new Error("Score graph not found"))
+
+        if(res.status != 200)
+            return Promise.reject(new Error("Undocumented error: " + res.status))
+
+        return res.json()
+    } catch (error) {
+        throw new Error(error)
+    }
+}
+
+exports.BeatLeaderLeaderboards = {
+    get: get,
+    getById: getById,
+    getClanRankingsById: getClanRankingsById,
+    getScoregraphById: getScoregraphById
+}
\ No newline at end of file diff --git a/docs/ScoreSaber.Leaderboard.html b/docs/ScoreSaber.Leaderboard.html index 2e2acb5..dd21c58 100644 --- a/docs/ScoreSaber.Leaderboard.html +++ b/docs/ScoreSaber.Leaderboard.html @@ -1,3 +1,3 @@ Namespace: Leaderboard
On this page

ScoreSaber. Leaderboard

Allows interaction with the ScoreSaber Leaderboard API endpoints

Methods

(static) difficultiesByHash(mapHash) → {Promise.<Array>}

Gets a maps difficulties based on hash

Parameters:
NameTypeDescription
mapHashstring

Map hash

Returns:

Difficulties offered on by a map

Type: 
Promise.<Array>

(static) get(query, page, options) → {Promise.<Array>}

Gets a list of leaderboards based on filters

Parameters:
NameTypeDescription
querystring

Query for specific terms

pagenumber

Page of result

optionsobject

More Filters

PropertyTypeDescription
verifiedbooleanFilter by verified (️deprecation notice)
rankedbooleanIndicates if only ranked songs should be included.
qualifiedbooleanIndicates if only qualified songs should be included.
lovedbooleanIndicates if only loved songs should be included.
minStarnumberThe minimum star rating of songs to include.
maxStarnumberThe maximum star rating of songs to include.
category0 | 1 | 2 | 3 | 4Which category to sort by (0 = trending, date ranked = 1,
scores set = 2, star difficulty = 3, author = 4)
sort0 | 1The sorting order: 0 (Descending) or 1 (Ascending).
uniquebooleanOnly return one leaderboard of each id.
Returns:
Type: 
Promise.<Array>

(static) infoByHash(mapHash, difficulty, gameMode) → {Promise}

Gets leaderboard info based on map hash

Parameters:
NameTypeDescription
mapHashstring

Map hash

difficultynumber

(1 = Easy, 3 = Normal, 5 = Hard, 7 = Expert, 9 = Expert+)

gameModenumber

SoloStandard by default. Only supported mode by ScoreSaber

Returns:

Information on queried leaderboard

Type: 
Promise

(static) infoById(leaderboardId) → {Promise}

Gets leaderboard information based on leaderboard id

Parameters:
NameTypeDescription
leaderboardIdnumber

Leaderboard ID

Returns:

Information on queried leaderboard

Type: 
Promise

(static) scoresByHash(mapHash, difficulty, countries, search, page, gameMode, withMetadata) → {Promise.<Array>}

Gets a list of scores for a given hash

Parameters:
NameTypeDescription
mapHashstring

Map hash

difficultynumber

(1 = Easy, 3 = Normal, 5 = Hard, 7 = Expert, 9 = Expert+)

countriesArray

Filter by ISO 3166-1 alpha-2 code

searchstring

Query for specific terms

pagenumber

Page of result

gameModenumber

SoloStandard by default. Only supported mode by ScoreSaber

withMetadataboolean

True by default. Returns total number of results, page number, and items per page

Returns:

Scores on queried leaderboard

Type: 
Promise.<Array>

(static) scoresById(leaderboardId, countries, search, page, withMetadata) → {Promise.<Array>}

Gets a list of scores for a given map

Parameters:
NameTypeDescription
leaderboardIdnumber

Leaderboard ID

countriesArray

Filter by ISO 3166-1 alpha-2 code

searchstring

Query for specific terms

pagenumber

Page of result

withMetadataboolean

True by default. Returns total number of results, page number, and items per page

Returns:

Scores on queried leaderboard

Type: 
Promise.<Array>
\ No newline at end of file +
On this page

ScoreSaber. Leaderboard

Allows interaction with the ScoreSaber Leaderboard API endpoints

Methods

(static) difficultiesByHash(mapHash) → {Promise.<Array>}

Gets a maps difficulties based on hash

Parameters:
NameTypeDescription
mapHashstring

Map hash

Returns:

Difficulties offered on by a map

Type: 
Promise.<Array>

(static) get(query, page, options) → {Promise.<Array>}

Gets a list of leaderboards based on filters

Parameters:
NameTypeDescription
querystring

Query for specific terms

pagenumber

Page of result

optionsobject

More Filters

PropertyTypeDescription
verifiedbooleanFilter by verified (️deprecation notice)
rankedbooleanIndicates if only ranked songs should be included.
qualifiedbooleanIndicates if only qualified songs should be included.
lovedbooleanIndicates if only loved songs should be included.
minStarnumberThe minimum star rating of songs to include.
maxStarnumberThe maximum star rating of songs to include.
category0 | 1 | 2 | 3 | 4Which category to sort by (0 = trending, date ranked = 1,
scores set = 2, star difficulty = 3, author = 4)
sort0 | 1The sorting order: 0 (Descending) or 1 (Ascending).
uniquebooleanOnly return one leaderboard of each id.
Returns:
Type: 
Promise.<Array>

(static) infoByHash(mapHash, difficulty, gameMode) → {Promise}

Gets leaderboard info based on map hash

Parameters:
NameTypeDescription
mapHashstring

Map hash

difficultynumber

(1 = Easy, 3 = Normal, 5 = Hard, 7 = Expert, 9 = Expert+)

gameModenumber

SoloStandard by default. Only supported mode by ScoreSaber

Returns:

Information on queried leaderboard

Type: 
Promise

(static) infoById(leaderboardId) → {Promise}

Gets leaderboard information based on leaderboard id

Parameters:
NameTypeDescription
leaderboardIdnumber

Leaderboard ID

Returns:

Information on queried leaderboard

Type: 
Promise

(static) scoresByHash(mapHash, difficulty, countries, search, page, gameMode, withMetadata) → {Promise.<Array>}

Gets a list of scores for a given hash

Parameters:
NameTypeDescription
mapHashstring

Map hash

difficultynumber

(1 = Easy, 3 = Normal, 5 = Hard, 7 = Expert, 9 = Expert+)

countriesArray

Filter by ISO 3166-1 alpha-2 code

searchstring

Query for specific terms

pagenumber

Page of result

gameModenumber

SoloStandard by default. Only supported mode by ScoreSaber

withMetadataboolean

True by default. Returns total number of results, page number, and items per page

Returns:

Scores on queried leaderboard

Type: 
Promise.<Array>

(static) scoresById(leaderboardId, countries, search, page, withMetadata) → {Promise.<Array>}

Gets a list of scores for a given map

Parameters:
NameTypeDescription
leaderboardIdnumber

Leaderboard ID

countriesArray

Filter by ISO 3166-1 alpha-2 code

searchstring

Query for specific terms

pagenumber

Page of result

withMetadataboolean

True by default. Returns total number of results, page number, and items per page

Returns:

Scores on queried leaderboard

Type: 
Promise.<Array>
\ No newline at end of file diff --git a/docs/ScoreSaber.Players.html b/docs/ScoreSaber.Players.html index 0208928..ab686f2 100644 --- a/docs/ScoreSaber.Players.html +++ b/docs/ScoreSaber.Players.html @@ -1,3 +1,3 @@ Namespace: Players
On this page

ScoreSaber. Players

Allows interaction with the ScoreSaber Player API endpoints

Methods

(static) basicInfoById(playerId) → {Promise.<Array>}

Returns basic player info

Parameters:
NameTypeDescription
playerIdstring

Player ID

Returns:

Returns a Promise with basic info on a player

Type: 
Promise.<Array>

(static) count(search, countries) → {Promise.<Array>}

Returns an integer value of the number of players based on filters

Parameters:
NameTypeDescription
searchstring

Query for specific terms

countriesArray

Filter by ISO 3166-1 alpha-2 code

Returns:

Returns a Promise with a integer of the number of players found matching filtered results

Type: 
Promise.<Array>

(static) fullInfoById(playerId) → {Promise.<Array>}

Returns full player info

Parameters:
NameTypeDescription
playerIdstring

Player ID

Returns:

Returns a Promise with full info on a player

Type: 
Promise.<Array>

(static) get(search, page, countries, withMetadata) → {Promise.<Array>}

Gets a list of players based on filters

Parameters:
NameTypeDescription
searchstring

Query for specific terms

pagenumber

Page of result

countriesArray

Filter by ISO 3166-1 alpha-2 code

withMetadataboolean

True by default. Returns total number of results, page number, and items per page

Returns:

Returns a Promise with a list of players based on filters

Type: 
Promise.<Array>

(static) scoresById(playerId, limit, sort) → {Promise.<Array>}

Returns a list of a players scores

Parameters:
NameTypeDescription
playerIdstring

Player ID

limitnumber

Maximum number of results to be returned

sortstring

The sort order. Valid values are "top" and "recent".

Returns:

Returns a Promise with full info on a player

Type: 
Promise.<Array>
\ No newline at end of file +
On this page

ScoreSaber. Players

Allows interaction with the ScoreSaber Player API endpoints

Methods

(static) basicInfoById(playerId) → {Promise.<Array>}

Returns basic player info

Parameters:
NameTypeDescription
playerIdstring

Player ID

Returns:

Returns a Promise with basic info on a player

Type: 
Promise.<Array>

(static) count(search, countries) → {Promise.<Array>}

Returns an integer value of the number of players based on filters

Parameters:
NameTypeDescription
searchstring

Query for specific terms

countriesArray

Filter by ISO 3166-1 alpha-2 code

Returns:

Returns a Promise with a integer of the number of players found matching filtered results

Type: 
Promise.<Array>

(static) fullInfoById(playerId) → {Promise.<Array>}

Returns full player info

Parameters:
NameTypeDescription
playerIdstring

Player ID

Returns:

Returns a Promise with full info on a player

Type: 
Promise.<Array>

(static) get(search, page, countries, withMetadata) → {Promise.<Array>}

Gets a list of players based on filters

Parameters:
NameTypeDescription
searchstring

Query for specific terms

pagenumber

Page of result

countriesArray

Filter by ISO 3166-1 alpha-2 code

withMetadataboolean

True by default. Returns total number of results, page number, and items per page

Returns:

Returns a Promise with a list of players based on filters

Type: 
Promise.<Array>

(static) scoresById(playerId, limit, sort) → {Promise.<Array>}

Returns a list of a players scores

Parameters:
NameTypeDescription
playerIdstring

Player ID

limitnumber

Maximum number of results to be returned

sortstring

The sort order. Valid values are "top" and "recent".

Returns:

Returns a Promise with full info on a player

Type: 
Promise.<Array>
\ No newline at end of file diff --git a/docs/ScoreSaber.Ranking.Public.html b/docs/ScoreSaber.Ranking.Public.html index 754bbab..28ba757 100644 --- a/docs/ScoreSaber.Ranking.Public.html +++ b/docs/ScoreSaber.Ranking.Public.html @@ -1,3 +1,3 @@ Namespace: Public
On this page

ScoreSaber.Ranking. Public

Allows interaction with the publically available ScoreSaber Ranking API endpoints (not ranking team related functions)

Methods

(static) belowTop() → {Promise.<Array>}

Gets the rest of the rank requests

Returns:

Returns a Promise with the rest of the rank requests

Type: 
Promise.<Array>

(static) getRequestInfoByLeaderboardId(leaderboardId) → {Promise.<Array>}

Gets rank request info based on a Leaderboard ID

Parameters:
NameTypeDescription
leaderboardIdnumber

Leaderboard ID of map

Returns:

Returns a Promise with the rank request information

Type: 
Promise.<Array>

(static) getRequestInfoByRequestId(requestId) → {Promise.<Array>}

Gets rank request info based on request ID

Parameters:
NameTypeDescription
requestIdnumber

Rank request ID

Returns:

Returns a Promise with the rank request information

Type: 
Promise.<Array>

(static) top() → {Promise.<Array>}

Gets the top 6 rank requests

Returns:

Returns a Promise with the top 6 rank requests

Type: 
Promise.<Array>
\ No newline at end of file +
On this page

ScoreSaber.Ranking. Public

Allows interaction with the publically available ScoreSaber Ranking API endpoints (not ranking team related functions)

Methods

(static) belowTop() → {Promise.<Array>}

Gets the rest of the rank requests

Returns:

Returns a Promise with the rest of the rank requests

Type: 
Promise.<Array>

(static) getRequestInfoByLeaderboardId(leaderboardId) → {Promise.<Array>}

Gets rank request info based on a Leaderboard ID

Parameters:
NameTypeDescription
leaderboardIdnumber

Leaderboard ID of map

Returns:

Returns a Promise with the rank request information

Type: 
Promise.<Array>

(static) getRequestInfoByRequestId(requestId) → {Promise.<Array>}

Gets rank request info based on request ID

Parameters:
NameTypeDescription
requestIdnumber

Rank request ID

Returns:

Returns a Promise with the rank request information

Type: 
Promise.<Array>

(static) top() → {Promise.<Array>}

Gets the top 6 rank requests

Returns:

Returns a Promise with the top 6 rank requests

Type: 
Promise.<Array>
\ No newline at end of file diff --git a/docs/ScoreSaber.Ranking.html b/docs/ScoreSaber.Ranking.html index 551a456..b63d2d3 100644 --- a/docs/ScoreSaber.Ranking.html +++ b/docs/ScoreSaber.Ranking.html @@ -1,3 +1,3 @@ Namespace: Ranking
On this page

ScoreSaber. Ranking

\ No newline at end of file +
On this page

ScoreSaber. Ranking

\ No newline at end of file diff --git a/docs/ScoreSaber.html b/docs/ScoreSaber.html index 05da627..1cbd48e 100644 --- a/docs/ScoreSaber.html +++ b/docs/ScoreSaber.html @@ -1,3 +1,3 @@ Namespace: ScoreSaber
On this page

ScoreSaber

Interact with the ScoreSaber API using this NPM wrapper library. Currently supports all ScoreSaber endpoints except for authenticated routes to include: Website User, Website Auth, and Ranking Team, QAT, and NAT routes.

Namespaces

Leaderboard
Players
Ranking
\ No newline at end of file +
On this page

ScoreSaber

Interact with the ScoreSaber API using this NPM wrapper library. Currently supports all ScoreSaber endpoints except for authenticated routes to include: Website User, Website Auth, and Ranking Team, QAT, and NAT routes.

Namespaces

Leaderboard
Players
Ranking
\ No newline at end of file diff --git a/docs/Scoresaber_leaderboard.js.html b/docs/Scoresaber_leaderboard.js.html index 2dcd327..58b1be1 100644 --- a/docs/Scoresaber_leaderboard.js.html +++ b/docs/Scoresaber_leaderboard.js.html @@ -1,6 +1,6 @@ Source: Scoresaber/leaderboard.js
On this page

Scoresaber_leaderboard.js

let {scoresaber} = require('../api_urls.json').urls
+    
On this page

Scoresaber_leaderboard.js

let {scoresaber} = require('../api_urls.json').urls
 
 /**
  * Allows interaction with the ScoreSaber Leaderboard API endpoints
@@ -149,4 +149,4 @@
     scoresById: scoresById,
     scoresByHash: scoresByHash,
     difficultiesByHash: difficultiesByHash
-}
\ No newline at end of file +}
\ No newline at end of file diff --git a/docs/Scoresaber_player.js.html b/docs/Scoresaber_player.js.html index 63ea7cf..a5b3572 100644 --- a/docs/Scoresaber_player.js.html +++ b/docs/Scoresaber_player.js.html @@ -1,6 +1,6 @@ Source: Scoresaber/player.js
On this page

Scoresaber_player.js

let {scoresaber} = require('../api_urls.json').urls
+    
On this page

Scoresaber_player.js

let {scoresaber} = require('../api_urls.json').urls
 
 /**
  * Allows interaction with the ScoreSaber Player API endpoints
@@ -108,4 +108,4 @@
     basicInfoById: basicInfoById,
     fullInfoById: fullInfoById,
     scoresById: scoresById
-}
\ No newline at end of file +}
\ No newline at end of file diff --git a/docs/Scoresaber_ranking.js.html b/docs/Scoresaber_ranking.js.html index 59040df..8d22b61 100644 --- a/docs/Scoresaber_ranking.js.html +++ b/docs/Scoresaber_ranking.js.html @@ -1,6 +1,6 @@ Source: Scoresaber/ranking.js
On this page

Scoresaber_ranking.js

const {scoresaber} = require('../api_urls.json').urls
+    
On this page

Scoresaber_ranking.js

const {scoresaber} = require('../api_urls.json').urls
 /**
  * Allows interaction with the publically available ScoreSaber Ranking API endpoints (not ranking team related functions)
  * @namespace Ranking.Public
@@ -74,4 +74,4 @@
     belowTop: belowTop,
     getRequestInfoByRequestId: getRequestInfoByRequestId,
     getRequestInfoByLeaderboardId: getRequestInfoByLeaderboardId
-}
\ No newline at end of file +}
\ No newline at end of file diff --git a/docs/data/search.json b/docs/data/search.json index 6cf066a..d9b64fd 100644 --- a/docs/data/search.json +++ b/docs/data/search.json @@ -1 +1 @@ -{"list":[{"title":"BeatLeader","link":"BeatLeader","description":"

Interact with the BeatLeader API using this NPM wrapper library. Currently supports all BeatLeader endpoints found under BeatLeaderAPI v1.

"},{"title":"BeatLeader.Clans","link":"Clans"},{"title":"BeatLeader.Clans.get","link":"get","description":"

Retrieves a list of clans based on filters

"},{"title":"BeatLeader.Clans.getById","link":"getById","description":"

Fetches details of a specific clan identified by its ID.

"},{"title":"BeatLeader.Clans.getByTag","link":"getByTag","description":"

Retrieves details of a specific clan by tag

"},{"title":"BeatLeader.Clans.getGlobalMap","link":"getGlobalMap","description":"

Fetches a global map showing clan captured maps and rankings.

"},{"title":"BeatLeader.Clans.getMapsById","link":"getMapsById","description":"

Fetches ranked maps(maps that can be captured on the global map) for where players of clan made scores identified by its ID, with optional sorting and filtering.

"},{"title":"BeatLeader.Clans.getMapsByTag","link":"getMapsByTag","description":"

Retrieves a list of clans based on filters

"},{"title":"ScoreSaber","link":"ScoreSaber","description":"

Interact with the ScoreSaber API using this NPM wrapper library. Currently supports all ScoreSaber endpoints except for authenticated\nroutes to include: Website User, Website Auth, and Ranking Team, QAT, and NAT routes.

"},{"title":"ScoreSaber.Leaderboard","link":"Leaderboard","description":"

Allows interaction with the ScoreSaber Leaderboard API endpoints

"},{"title":"ScoreSaber.Leaderboard.difficultiesByHash","link":"difficultiesByHash","description":"

Gets a maps difficulties based on hash

"},{"title":"ScoreSaber.Leaderboard.get","link":"get","description":"

Gets a list of leaderboards based on filters

"},{"title":"ScoreSaber.Leaderboard.infoByHash","link":"infoByHash","description":"

Gets leaderboard info based on map hash

"},{"title":"ScoreSaber.Leaderboard.infoById","link":"infoById","description":"

Gets leaderboard information based on leaderboard id

"},{"title":"ScoreSaber.Leaderboard.scoresByHash","link":"scoresByHash","description":"

Gets a list of scores for a given hash

"},{"title":"ScoreSaber.Leaderboard.scoresById","link":"scoresById","description":"

Gets a list of scores for a given map

"},{"title":"ScoreSaber.Players","link":"Players","description":"

Allows interaction with the ScoreSaber Player API endpoints

"},{"title":"ScoreSaber.Players.basicInfoById","link":"basicInfoById","description":"

Returns basic player info

"},{"title":"ScoreSaber.Players.count","link":"count","description":"

Returns an integer value of the number of players based on filters

"},{"title":"ScoreSaber.Players.fullInfoById","link":"fullInfoById","description":"

Returns full player info

"},{"title":"ScoreSaber.Players.get","link":"get","description":"

Gets a list of players based on filters

"},{"title":"ScoreSaber.Players.scoresById","link":"scoresById","description":"

Returns a list of a players scores

"},{"title":"ScoreSaber.Ranking","link":"Ranking","description":"

Allows interaction with the ScoreSaber Ranking API endpoints

"},{"title":"ScoreSaber.Ranking.Public","link":"Public","description":"

Allows interaction with the publically available ScoreSaber Ranking API endpoints (not ranking team related functions)

"},{"title":"ScoreSaber.Ranking.Public.belowTop","link":"belowTop","description":"

Gets the rest of the rank requests

"},{"title":"ScoreSaber.Ranking.Public.getRequestInfoByLeaderboardId","link":"getRequestInfoByLeaderboardId","description":"

Gets rank request info based on a Leaderboard ID

"},{"title":"ScoreSaber.Ranking.Public.getRequestInfoByRequestId","link":"getRequestInfoByRequestId","description":"

Gets rank request info based on request ID

"},{"title":"ScoreSaber.Ranking.Public.top","link":"top","description":"

Gets the top 6 rank requests

"}]} \ No newline at end of file +{"list":[{"title":"BeatLeader","link":"BeatLeader","description":"

Interact with the BeatLeader API using this NPM wrapper library. Currently supports all BeatLeader endpoints found under BeatLeaderAPI v1.

"},{"title":"BeatLeader.Clans","link":"Clans"},{"title":"BeatLeader.Clans.get","link":"get","description":"

Retrieves a list of clans based on filters

"},{"title":"BeatLeader.Clans.getById","link":"getById","description":"

Fetches details of a specific clan identified by its ID.

"},{"title":"BeatLeader.Clans.getByTag","link":"getByTag","description":"

Retrieves details of a specific clan by tag

"},{"title":"BeatLeader.Clans.getGlobalMap","link":"getGlobalMap","description":"

Fetches a global map showing clan captured maps and rankings.

"},{"title":"BeatLeader.Clans.getMapsById","link":"getMapsById","description":"

Fetches ranked maps(maps that can be captured on the global map) for where players of clan made scores identified by its ID, with optional sorting and filtering.

"},{"title":"BeatLeader.Clans.getMapsByTag","link":"getMapsByTag","description":"

Retrieves a list of clans based on filters

"},{"title":"BeatLeader.Leaderboards","link":"Leaderboards"},{"title":"BeatLeader.Leaderboards.get","link":"get","description":"

Retrieves a list of leaderboards

"},{"title":"BeatLeader.Leaderboards.getById","link":"getById","description":"

Retrieves a list of leaderboards

"},{"title":"BeatLeader.Leaderboards.getClanRankingsById","link":"getClanRankingsById","description":"

Retrieves clan rankings for a leaderboard

"},{"title":"BeatLeader.Leaderboards.getScoregraphById","link":"getScoregraphById","description":"

Retrieves the score graph for a leaderboard

"},{"title":"ScoreSaber","link":"ScoreSaber","description":"

Interact with the ScoreSaber API using this NPM wrapper library. Currently supports all ScoreSaber endpoints except for authenticated\nroutes to include: Website User, Website Auth, and Ranking Team, QAT, and NAT routes.

"},{"title":"ScoreSaber.Leaderboard","link":"Leaderboard","description":"

Allows interaction with the ScoreSaber Leaderboard API endpoints

"},{"title":"ScoreSaber.Leaderboard.difficultiesByHash","link":"difficultiesByHash","description":"

Gets a maps difficulties based on hash

"},{"title":"ScoreSaber.Leaderboard.get","link":"get","description":"

Gets a list of leaderboards based on filters

"},{"title":"ScoreSaber.Leaderboard.infoByHash","link":"infoByHash","description":"

Gets leaderboard info based on map hash

"},{"title":"ScoreSaber.Leaderboard.infoById","link":"infoById","description":"

Gets leaderboard information based on leaderboard id

"},{"title":"ScoreSaber.Leaderboard.scoresByHash","link":"scoresByHash","description":"

Gets a list of scores for a given hash

"},{"title":"ScoreSaber.Leaderboard.scoresById","link":"scoresById","description":"

Gets a list of scores for a given map

"},{"title":"ScoreSaber.Players","link":"Players","description":"

Allows interaction with the ScoreSaber Player API endpoints

"},{"title":"ScoreSaber.Players.basicInfoById","link":"basicInfoById","description":"

Returns basic player info

"},{"title":"ScoreSaber.Players.count","link":"count","description":"

Returns an integer value of the number of players based on filters

"},{"title":"ScoreSaber.Players.fullInfoById","link":"fullInfoById","description":"

Returns full player info

"},{"title":"ScoreSaber.Players.get","link":"get","description":"

Gets a list of players based on filters

"},{"title":"ScoreSaber.Players.scoresById","link":"scoresById","description":"

Returns a list of a players scores

"},{"title":"ScoreSaber.Ranking","link":"Ranking","description":"

Allows interaction with the ScoreSaber Ranking API endpoints

"},{"title":"ScoreSaber.Ranking.Public","link":"Public","description":"

Allows interaction with the publically available ScoreSaber Ranking API endpoints (not ranking team related functions)

"},{"title":"ScoreSaber.Ranking.Public.belowTop","link":"belowTop","description":"

Gets the rest of the rank requests

"},{"title":"ScoreSaber.Ranking.Public.getRequestInfoByLeaderboardId","link":"getRequestInfoByLeaderboardId","description":"

Gets rank request info based on a Leaderboard ID

"},{"title":"ScoreSaber.Ranking.Public.getRequestInfoByRequestId","link":"getRequestInfoByRequestId","description":"

Gets rank request info based on request ID

"},{"title":"ScoreSaber.Ranking.Public.top","link":"top","description":"

Gets the top 6 rank requests

"}]} \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index f6403fb..d010609 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,14 +1,14 @@ Home
On this page

BeatSaberAPI-Node

Currently in development. BeatSaberAPI-Node is a Open Source Library that allows for easy interaction with different BeatSaber API's through a well documented Node.JS library.

Supported API's

  • ScoreSaber

Planned Support

  • BeatLeader
  • AccSaber
  • Challenge Saber

Installing

Run the following command

npm install beatsaberapi-node
+    
On this page

BeatSaberAPI-Node

Currently in development. BeatSaberAPI-Node is a Open Source Library that allows for easy interaction with different BeatSaber API's through a well documented Node.JS library.

Supported API's

  • ScoreSaber

Planned Support

  • BeatLeader
  • AccSaber
  • Challenge Saber

Installing

Run the following command

npm install beatsaberapi-node
 

After installing, besure to install dependencies

npm install
 

Implementing in your code

const BeatSaberNode = require('beatsaberapi-node');
 
 // example function call
-let res = BeatSaberWebWrapper.ScoreSaber.Ranking.Public.getRequestInfoByLeaderboardId('578412')
+let res = BeatSaberNode.ScoreSaber.Ranking.Public.getRequestInfoByLeaderboardId('578412')
 
 res.then(function resolved(data) {
     console.log(data)
 })
 

Documentation

You can build the documentation yourself by running the following command or visit the docs

npm run docs
-

In dev

\ No newline at end of file +
\ No newline at end of file diff --git a/docs/index.js.html b/docs/index.js.html index 561b2cf..0211213 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -1,6 +1,6 @@ Source: index.js
On this page

index.js

// scoresaber
+    
On this page

index.js

// scoresaber
 const {ScoreSaberLeaderboard} = require('./Scoresaber/leaderboard')
 const {ScoreSaberPlayers} = require('./Scoresaber/player')
 const {ScoreSaberRankingPublic} = require('./Scoresaber/ranking')
@@ -43,4 +43,4 @@
         Player: BeatLeaderPlayer,
         Scores: BeatLeaderPlayerScores,
     },
-}
\ No newline at end of file +}
\ No newline at end of file diff --git a/src/BeatLeader/Clan.js b/src/BeatLeader/Clan.js index c6b86e7..92a766b 100644 --- a/src/BeatLeader/Clan.js +++ b/src/BeatLeader/Clan.js @@ -1,4 +1,5 @@ const {beatleader} = require('../api_urls.json').urls +const {parseSearchOptions} = require('./utility/parseSearchOptions') /** * @namespace BeatLeader.Clans @@ -17,7 +18,7 @@ const {beatleader} = require('../api_urls.json').urls * | sortBy | ClanSortBy | (Optional) Sorting criteria | name, pp, acc, rank, count, captures | * | order | Order | (Optional) Sorting order | desc, asc | * | search | string | (Optional) Search query | | - * @returns A promise with a list of clans + * @returns {Promise} A promise with a list of clans */ async function get(searchOptions = {}) { try { @@ -30,7 +31,8 @@ async function get(searchOptions = {}) { return Promise.reject(new Error("Invalid request parameters")) if(res.status == 404) return Promise.reject(new Error("Clans not found")) - + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) return res.json() } catch (error) { throw new Error(error) @@ -51,7 +53,7 @@ async function get(searchOptions = {}) { * | order | Order | (Optional) Sorting order | desc, asc | * | search | string | (Optional) Search query | | * @param {boolean} primary Whether to include only players for whom this clan is primary, default is false - * @returns A promise with a clan + * @returns {Promise} A promise with a clan */ async function getByTag(tag, searchOptions = {}, primary = false) { try { @@ -64,7 +66,8 @@ async function getByTag(tag, searchOptions = {}, primary = false) { let res = await fetch(encodeURI(route)) if(res.status == 404) return Promise.reject(new Error("Clan not found")) - + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) return res.json() } catch (error) { throw new Error(error) @@ -84,7 +87,7 @@ async function getByTag(tag, searchOptions = {}, primary = false) { * | sortBy | ClanSortBy | (Optional) Sorting criteria | pp, topPp, name, rank, acc, weightedAcc, top1Count, top1Score, weightedRank, topAcc, hmd, playCount, score, lastplay, maxStreak, replaysWatched, dailyImprovements, timing | * | order | Order | (Optional) Sorting order | desc, asc | * @param {boolean} primary Whether to include only players for whom this clan is primary, default is false - * @returns A promise with a clan + * @returns {Promise} A promise with a clan */ async function getById(id, searchOptions = {}, primary = false) { try { @@ -97,7 +100,8 @@ async function getById(id, searchOptions = {}, primary = false) { let res = await fetch(encodeURI(route)) if(res.status == 404) return Promise.reject(new Error("Clan not found")) - + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) return res.json() } catch (error) { throw new Error(error) @@ -117,7 +121,7 @@ async function getById(id, searchOptions = {}, primary = false) { * | sortBy | ClanSortBy | (Optional) Sorting criteria | pp, acc, rank, date, tohold, toconquer | * | leaderboardContext | LeaderboardContext | (Optional) Context of leaderboard. Default is General| none, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup | * | order | Order | (Optional) Sorting order | desc, asc | - * @returns A promise with a list of ranked maps + * @returns {Promise} A promise with a list of ranked maps */ async function getMapsByTag(tag, searchOptions = {}) { try { @@ -129,7 +133,8 @@ async function getMapsByTag(tag, searchOptions = {}) { let res = await fetch(encodeURI(route)) if(res.status == 404) return Promise.reject(new Error("Clan not found")) - + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) return res.json() } catch (error) { throw new Error(error) @@ -149,7 +154,7 @@ async function getMapsByTag(tag, searchOptions = {}) { * | sortBy | ClanSortBy | (Optional) Sorting criteria | pp, acc, rank, date, tohold, toconquer | * | leaderboardContext | LeaderboardContext | (Optional) Context of leaderboard. Default is General| none, general, noMods, noPause, golf, sCPM, speedrun, speedrunBackup | * | order | Order | (Optional) Sorting order | desc, asc | - * @returns A promise with a list of ranked maps + * @returns {Promise} A promise with a list of ranked maps */ async function getMapsById(id, searchOptions = {}) { try { @@ -161,7 +166,8 @@ async function getMapsById(id, searchOptions = {}) { let res = await fetch(encodeURI(route)) if(res.status == 404) return Promise.reject(new Error("Clan not found")) - + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) return res.json() } catch (error) { throw new Error(error) @@ -172,7 +178,7 @@ async function getMapsById(id, searchOptions = {}) { * Fetches a global map showing clan captured maps and rankings. * @function getGlobalMap * @memberof BeatLeader.Clans - * @returns A promise with the Global Map + * @returns {Promise} A promise with the Global Map */ async function getGlobalMap() { try { @@ -181,30 +187,14 @@ async function getGlobalMap() { let res = await fetch(encodeURI(route)) if(res.status == 404) return Promise.reject(new Error("Global map not found")) - + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) return res.json() } catch (error) { throw new Error(error) } } -// utility -function parseSearchOptions(searchOptions) { - let route = '' - if(Object.keys(searchOptions).length > 0) { - route += '?' - let i = 1 - for(key in searchOptions) { - if(i < Object.keys(searchOptions).length) - route += `${key}=${searchOptions[key]}&` - else - route += `${key}=${searchOptions[key]}` - i++ - } - } - return route -} - exports.BeatLeaderClans = { get: get, getByTag: getByTag, diff --git a/src/BeatLeader/Leaderboard.js b/src/BeatLeader/Leaderboard.js index 8ff4431..8c00ed7 100644 --- a/src/BeatLeader/Leaderboard.js +++ b/src/BeatLeader/Leaderboard.js @@ -1,3 +1,158 @@ +const {beatleader} = require('../api_urls.json').urls +const {parseSearchOptions} = require('./utility/parseSearchOptions') + +/** + * @namespace BeatLeader.Leaderboards + * @memberof BeatLeader + */ + +/** + * Retrieves a list of leaderboards + * @function get + * @memberof BeatLeader.Leaderboards + * @param {Object} leaderboardSearchOptions Filters to narrow search. See options in table below + * | Parameter | Type | Description | Valid Values | + * |---------------------|-------------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------| + * | page | number | (Optional) Page number | N/A | + * | count | number | (Optional) Number of items per page | N/A | + * | sortBy | LeaderboardSortBy | (Optional) Sorting criteria | 0, 1, 2, 3, 4, 5, 6, 7, 8, "date", "pp", "acc", "pauses", "rank", "maxStreak", "mistakes", "weight", "weightedPp" | + * | order | Order | Sorting order | "asc", "desc" | + * | search | string | (Optional) Search query | N/A | + * | type | Type | (Optional) Type of item | N/A | + * | mode | string | (Optional) Mode of item | N/A | + * | difficulty | Difficulties | (Optional) Difficulty level | "Standard", "OneSaber", "90Degree", "360Degree" | + * | mapType | MapsType | (Optional) Map type | 0, 1, 2, "ranked", "unranked", "all" | + * | allTypes | Operation | (Optional) Operation for all types | 0, 1, 2, "any", "all", "not" | + * | mapRequirements | RequirementsString | (Optional) Map requirements | "none", "chroma", "noodles", "mappingExtensions", "cinema", "v3", "optionalProperties", "ignore" | + * | allRequirements | Operation | (Optional) Operation for all requirements | 0, 1, 2, "any", "all", "not" | + * | songStatus | SongStatus | (Optional) Status of the song | 0, 2, 4, 8, 16, 32, "none", "curated", "mapOfTheWeek", "noodleMonday", "featuredOnCC", "beastSaberAwarded" | + * | leaderboardContext | LeaderboardContexts | (Optional) Context of the leaderboard | 0, 2, 4, 8, 16, 32, 64, 128, "none", "general", "noMods", "noPause", "golf", "sCPM", "speedrun", "speedrunBackup" | + * | mytype | MyType | (Optional) Custom type | 0, 1, 2, 3, 4, 5, 6, "none", "played", "unplayed", "myNominated", "othersNominated", "myMaps" | + * | stars_from | number | (Optional) Minimum stars | N/A | + * | stars_to | number | (Optional) Maximum stars | N/A | + * | accrating_from | number | (Optional) Minimum accuracy rating | N/A | + * | accrating_to | number | (Optional) Maximum accuracy rating | N/A | + * | passrating_from | number | (Optional) Minimum pass rating | N/A | + * | passrating_to | number | (Optional) Maximum pass rating | N/A | + * | techrating_from | number | (Optional) Minimum tech rating | N/A | + * | techrating_to | number | (Optional) Maximum tech rating | N/A | + * | date_from | number | (Optional) Start date | N/A | + * | mapper | number | (Optional) Mapper ID | N/A | + * | overrideCurrentId | string | (Optional) Override current ID | N/A | + * @returns {Promise} A promise with a list of leaderboards + */ +async function get(leaderboardSearchOptions = {}) { + try { + let route = new URL(beatleader + 'leaderboards').href + let parsedSearchOptions = parseSearchOptions(leaderboardSearchOptions) + route += parsedSearchOptions + + let res = await fetch(encodeURI(route)) + if(res.status == 404) + return Promise.reject(new Error("Leaderboards not found")) + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) + return res.json() + } catch (error) { + throw new Error(error) + } +} + +/** + * Retrieves a list of leaderboards + * @function getById + * @memberof BeatLeader.Leaderboards + * @param {string} id ID of the leaderboard to retrieve details for + * @param {Object} leaderboardSearchOptions Filters to narrow search. See options in table below + * | Parameter | Type | Description | Valid Values | + * |---------------------|-------------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------| + * | page | number | (Optional) Page number | N/A | + * | count | number | (Optional) Number of items per page | N/A | + * | sortBy | LeaderboardSortBy | (Optional) Sorting criteria | 0, 1, 2, 3, 4, 5, 6, 7, 8, "date", "pp", "acc", "pauses", "rank", "maxStreak", "mistakes", "weight", "weightedPp" | + * | order | Order | Sorting order | "asc", "desc" | + * | scoreStatus | ScoreFilterStatus | (Optional) Score status filter | 0, 1, "none", "suspicious" | + * | leaderboardContext | LeaderboardContexts | (Optional) Context of the leaderboard | 0, 2, 4, 8, 16, 32, 64, 128, "none", "general", "noMods", "noPause", "golf", "sCPM", "speedrun", "speedrunBackup" | + * | countries | Array | (Optional) List of country codes | N/A | + * | search | string | (Optional) Search query | N/A | + * | modifiers | string | (Optional) Modifiers | N/A | + * | friends | boolean | (Optional) Filter by friends | N/A | + * | voters | boolean | (Optional) Filter by voters | N/A | + * | prediction | boolean | (Optional) Prediction filter | N/A | + * @returns {Promise} A promise with leaderboard details + */ +async function getById(id, leaderboardSearchOptions = {}) { + try { + let route = new URL(beatleader + 'leaderboard').href + route += `/${id}` + let parsedSearchOptions = parseSearchOptions(leaderboardSearchOptions) + route += parsedSearchOptions + + let res = await fetch(encodeURI(route)) + if(res.status == 404) + return Promise.reject(new Error("Leaderboard not found")) + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) + return res.json() + } catch (error) { + throw new Error(error) + } +} + +/** + * Retrieves clan rankings for a leaderboard + * @function getClanRankingsById + * @memberof BeatLeader.Leaderboards + * @param {string} id ID of the leaderboard to retrieve clan rankings for + * @param {number} page Page number for pagination, default is 1 + * @param {number} count Number of rankings per page, default is 10 + * @returns {Promise} A promise with clan rankings + */ +async function getClanRankingsById(id, page = 1, count = 10) { + try { + let route = new URL(beatleader + 'leaderboard/clanRankings').href + route += `/${id}?page=${page}&count=${count}` + + let res = await fetch(encodeURI(route)) + if(res.status == 404) + return Promise.reject(new Error("Clan rankings not found")) + + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) + + return res.json() + } catch (error) { + throw new Error(error) + } +} + +/** + * Retrieves the score graph for a leaderboard + * @function getScoregraphById + * @memberof BeatLeader.Leaderboards + * @param {string} id ID of the leaderboard to retrieve the score graph for + * @returns {Promise} A promise with score graph data + */ +async function getScoregraphById(id) { + try { + let route = new URL(beatleader + 'leaderboard').href + route += `/${id}/scoregraph` + + let res = await fetch(encodeURI(route)) + if(res.status == 404) + return Promise.reject(new Error("Score graph not found")) + + if(res.status != 200) + return Promise.reject(new Error("Undocumented error: " + res.status)) + + return res.json() + } catch (error) { + throw new Error(error) + } +} + exports.BeatLeaderLeaderboards = { - + get: get, + getById: getById, + getClanRankingsById: getClanRankingsById, + getScoregraphById: getScoregraphById } \ No newline at end of file diff --git a/src/BeatLeader/types/BeatLeader.d.ts b/src/BeatLeader/types/BeatLeader.d.ts index ddbf63f..7b862e5 100644 --- a/src/BeatLeader/types/BeatLeader.d.ts +++ b/src/BeatLeader/types/BeatLeader.d.ts @@ -573,6 +573,8 @@ export interface LeaderboardSearchOptions { type LeaderboardSortBy = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | "date" | "pp" | "acc" | "pauses" | "rank" | "maxStreak" | "mistakes" | "weight" | "weightedPp" +type RequirementsString = "none" | "chroma" | "noodles" | "mappingExtensions" | "cinema" | "v3" | "optionalProperties" | "ignore" + export interface LegacyModifiers { da: number, fs: number, diff --git a/src/BeatLeader/utility/parseSearchOptions.js b/src/BeatLeader/utility/parseSearchOptions.js new file mode 100644 index 0000000..127c253 --- /dev/null +++ b/src/BeatLeader/utility/parseSearchOptions.js @@ -0,0 +1,17 @@ +function parseSearchOptions(searchOptions) { + let route = '' + if(Object.keys(searchOptions).length > 0) { + route += '?' + let i = 1 + for(key in searchOptions) { + if(i < Object.keys(searchOptions).length) + route += `${key}=${searchOptions[key]}&` + else + route += `${key}=${searchOptions[key]}` + i++ + } + } + return route +} + +exports.parseSearchOptions = parseSearchOptions \ No newline at end of file diff --git a/src/index.d.ts b/src/index.d.ts index 8147f61..b35a4d7 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -48,7 +48,7 @@ export namespace BeatLeader { } export namespace Leaderboards { - function getById(id: string, leaderboardByIdSearchOptions: LeaderboardByIdSearchOption): Promise + function getById(id: string, leaderboardByIdSearchOptions?: LeaderboardByIdSearchOption): Promise function getClanRankingsById(id: string, page?: number, count?: number): Promise function get(leaderboardSearchOptions?: LeaderboardSearchOptions): Promise function getScoregraphById(id: string): Promise