Skip to content

Commit 14f94da

Browse files
committed
feat: add rank endpoints with solo/flex metrics
- add League-V4 rank lookup by puuid - expose solo/flex split with derived winRate - include LP, wins, losses, and win rate in endpoint test output - document new rank APIs and queue mapping in README
1 parent 3a946dc commit 14f94da

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ fetchStaticData();
100100

101101
- `getAccountByRiotId(riotId, [tagLine], [region])`: Fetch account by Riot ID (e.g., `Timmsy#BRUV`).
102102
- `getSummonerByPuuid(puuid, [region])`: Get summoner data by PUUID.
103+
- `getRankEntriesByPuuid(puuid, [region])`: Get all League-V4 rank entries for a player PUUID.
104+
- `getRankByPuuid(puuid, [region])`: Get rank split by Solo and Flex queues from a PUUID.
103105
- `getMatchlistByPuuid(puuid, [options], [region])`: Get match history (options: `{ start, count }`).
104106
- `getMatchById(matchId, [region])`: Get full match payload (`metadata` + `info`) by match ID.
105107
- `getMatchTimelineById(matchId, [region])`: Get timeline payload by match ID.
@@ -118,6 +120,10 @@ fetchStaticData();
118120
- `getMatchlistByPuuidAll`: `{ delayMs, maxMatches }`
119121
- `getMatchesWithDetailsByPuuid`: `{ pageDelayMs, detailDelayMs, maxMatches }`
120122

123+
Rank queue mapping used by helper methods:
124+
- Solo Queue: `RANKED_SOLO_5x5`
125+
- Flex Queue: `RANKED_FLEX_SR`
126+
121127
### DataDragon
122128

123129
- `getChampions()`: Fetch all champion data.

endpoints/riot.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2+
const SOLO_QUEUE = 'RANKED_SOLO_5x5';
3+
const FLEX_QUEUE = 'RANKED_FLEX_SR';
4+
const withRankMetrics = (entry) => {
5+
if (!entry) return null;
6+
const wins = Number(entry.wins) || 0;
7+
const losses = Number(entry.losses) || 0;
8+
const gamesPlayed = wins + losses;
9+
const winRate = gamesPlayed > 0 ? Number(((wins / gamesPlayed) * 100).toFixed(2)) : 0;
10+
return { ...entry, winRate };
11+
};
212

313
module.exports = (client, defaultRegion, regionMap) => ({
414
/**
@@ -46,6 +56,37 @@ module.exports = (client, defaultRegion, regionMap) => ({
4656
}
4757
},
4858

59+
/**
60+
* Fetch all ranked entries for a player PUUID.
61+
* @param {string} puuid - Player PUUID.
62+
* @param {string} [region] - Region code used to resolve platform routing.
63+
* @returns {Promise<object[]>} Ranked entries from League-V4.
64+
*/
65+
async getRankEntriesByPuuid(puuid, region = defaultRegion) {
66+
const platform = regionMap[region].platform;
67+
try {
68+
const response = await client.get(`/lol/league/v4/entries/by-puuid/${encodeURIComponent(puuid)}`, {
69+
baseURL: `https://${platform}`,
70+
});
71+
return response.data;
72+
} catch (error) {
73+
throw this._handleError(error);
74+
}
75+
},
76+
77+
/**
78+
* Fetch ranked info split into Solo and Flex queues.
79+
* @param {string} puuid - Player PUUID.
80+
* @param {string} [region] - Region code used to resolve platform routing.
81+
* @returns {Promise<{solo: object|null, flex: object|null, entries: object[]}>} Queue-split rank payload.
82+
*/
83+
async getRankByPuuid(puuid, region = defaultRegion) {
84+
const entries = await this.getRankEntriesByPuuid(puuid, region);
85+
const solo = withRankMetrics(entries.find((entry) => entry.queueType === SOLO_QUEUE) || null);
86+
const flex = withRankMetrics(entries.find((entry) => entry.queueType === FLEX_QUEUE) || null);
87+
return { solo, flex, entries };
88+
},
89+
4990
/**
5091
* Fetch match IDs for a PUUID from Match-V5.
5192
* @param {string} puuid - Player PUUID.

test-endpoints.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ async function run() {
1717
summonerLevel: summoner.summonerLevel,
1818
});
1919

20+
const rank = await riot.getRankByPuuid(account.puuid);
21+
console.log('[PASS] getRankByPuuid:', {
22+
solo: rank.solo ? `${rank.solo.tier} ${rank.solo.rank} | ${rank.solo.leaguePoints} LP | ${rank.solo.wins}W-${rank.solo.losses}L | ${rank.solo.winRate}% WR` : null,
23+
flex: rank.flex ? `${rank.flex.tier} ${rank.flex.rank} | ${rank.flex.leaguePoints} LP | ${rank.flex.wins}W-${rank.flex.losses}L | ${rank.flex.winRate}% WR` : null,
24+
});
25+
2026
const matchIds = await riot.getMatchlistByPuuid(account.puuid, { start: 0, count: 3 });
2127
console.log('[PASS] getMatchlistByPuuid:', matchIds.length, 'match ids');
2228

0 commit comments

Comments
 (0)