|
| 1 | +import { LinkSelfHref, LocalizedString, request } from "../../shared/index.ts"; |
| 2 | + |
| 3 | +interface Seasons extends LinkSelfHref { |
| 4 | + season: { |
| 5 | + href: string; |
| 6 | + }[]; |
| 7 | + current_season: number; |
| 8 | + service_current_season: number; |
| 9 | + service_season_state: string; |
| 10 | + last_update_time: string; |
| 11 | + generated_by: string; |
| 12 | +} |
| 13 | + |
| 14 | +interface Season extends LinkSelfHref { |
| 15 | + leaderboard: { |
| 16 | + team_size?: number; |
| 17 | + ladder: { |
| 18 | + href: string; |
| 19 | + }; |
| 20 | + hardcore?: boolean; |
| 21 | + hero_class_string?: LocalizedString; |
| 22 | + }[]; |
| 23 | + season_id: number; |
| 24 | + last_update_time: string; |
| 25 | + generated_by: string; |
| 26 | +} |
| 27 | + |
| 28 | +interface LeaderboardData { |
| 29 | + id: string; |
| 30 | + string?: string; |
| 31 | + number?: number; |
| 32 | + timestamp?: number; |
| 33 | +} |
| 34 | + |
| 35 | +interface LeaderboardBase extends LinkSelfHref { |
| 36 | + row: { |
| 37 | + player: { |
| 38 | + key: string; |
| 39 | + accountId: number; |
| 40 | + data: LeaderboardData[]; |
| 41 | + }[]; |
| 42 | + order: 1; |
| 43 | + data: LeaderboardData[]; |
| 44 | + }[]; |
| 45 | + key: string; |
| 46 | + title: LocalizedString; |
| 47 | + column: { |
| 48 | + id: string; |
| 49 | + hidden: boolean; |
| 50 | + order: number; |
| 51 | + label: LocalizedString; |
| 52 | + type: string; |
| 53 | + }[]; |
| 54 | + last_update_time: string; |
| 55 | + generated_by: string; |
| 56 | +} |
| 57 | + |
| 58 | +interface SeasonLeaderboard extends LeaderboardBase { |
| 59 | + achievement_points: boolean; |
| 60 | + season: number; |
| 61 | +} |
| 62 | + |
| 63 | +interface EraLeaderboard extends LeaderboardBase { |
| 64 | + greater_rift: boolean; |
| 65 | + greater_rift_solo_class: string; |
| 66 | + era: number; |
| 67 | +} |
| 68 | + |
| 69 | +interface Eras extends LinkSelfHref { |
| 70 | + era: { |
| 71 | + href: string; |
| 72 | + }[]; |
| 73 | + current_era: number; |
| 74 | + last_update_time: string; |
| 75 | + generated_by: string; |
| 76 | +} |
| 77 | + |
| 78 | +interface Era extends LinkSelfHref { |
| 79 | + leaderboard: { |
| 80 | + team_size?: number; |
| 81 | + ladder: { |
| 82 | + href: string; |
| 83 | + }; |
| 84 | + hardcore?: boolean; |
| 85 | + hero_class_string?: LocalizedString; |
| 86 | + }[]; |
| 87 | + era_id: number; |
| 88 | + era_start_date: number; |
| 89 | + last_update_time: string; |
| 90 | + generated_by: string; |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * Returns an index of available seasons. |
| 95 | + * |
| 96 | + * @returns A promise that resolves to an object representing an index of available seasons. |
| 97 | + */ |
| 98 | +export async function seasons(): Promise<Seasons> { |
| 99 | + return await request({ |
| 100 | + method: "GET", |
| 101 | + url: "/data/d3/season/", |
| 102 | + }); |
| 103 | +} |
| 104 | + |
| 105 | +/** |
| 106 | + * Returns an index of available seasons. |
| 107 | + * |
| 108 | + * @param seasonId - The season for the leaderboard list. |
| 109 | + * @returns A promise that resolves to an object representing the data for a league. |
| 110 | + */ |
| 111 | +export async function season(seasonId: number): Promise<Season> { |
| 112 | + return await request({ |
| 113 | + method: "GET", |
| 114 | + url: `/data/d3/season/${seasonId}`, |
| 115 | + }); |
| 116 | +} |
| 117 | + |
| 118 | +/** |
| 119 | + * Returns a the specified leaderboard for the specified season. |
| 120 | + * |
| 121 | + * @param seasonId - The season for the leaderboard. |
| 122 | + * @param leaderboard - The leaderboard to retrieve. |
| 123 | + * @returns A promise that resolves to an object representing the data for a the specified leaderboard for the specified season. |
| 124 | + */ |
| 125 | +export async function seasonLeaderboard(seasonId: number, leaderboard: string): Promise<SeasonLeaderboard> { |
| 126 | + return await request({ |
| 127 | + method: "GET", |
| 128 | + url: `/data/d3/season/${seasonId}/leaderboard/${leaderboard}`, |
| 129 | + }); |
| 130 | +} |
| 131 | + |
| 132 | +/** |
| 133 | + * Returns an index of available eras. |
| 134 | + * |
| 135 | + * @returns A promise that resolves to an object representing an index of available eras. |
| 136 | + */ |
| 137 | +export async function eras(): Promise<Eras> { |
| 138 | + return await request({ |
| 139 | + method: "GET", |
| 140 | + url: "/data/d3/era/", |
| 141 | + }); |
| 142 | +} |
| 143 | + |
| 144 | +/** |
| 145 | + * Returns a leaderboard list for a particular era. |
| 146 | + * |
| 147 | + * @param eraId - The era to retrieve. |
| 148 | + * @returns A promise that resolves to an object representing a leaderboard list for a particular era. |
| 149 | + */ |
| 150 | +export async function era(eraId: number): Promise<Era> { |
| 151 | + return await request({ |
| 152 | + method: "GET", |
| 153 | + url: `/data/d3/era/${eraId}`, |
| 154 | + }); |
| 155 | +} |
| 156 | + |
| 157 | +/** |
| 158 | + * Returns the specified leaderboard for the specified era. |
| 159 | + * |
| 160 | + * @param eraId - The era for the leaderboard. |
| 161 | + * @param leaderboard - The leaderboard to retrieve. |
| 162 | + * @returns A promise that resolves to an object representing the data for a the specified leaderboard for the specified era. |
| 163 | + */ |
| 164 | +export async function eraLeaderboard(eraId: number, leaderboard: string): Promise<EraLeaderboard> { |
| 165 | + return await request({ |
| 166 | + method: "GET", |
| 167 | + url: `/data/d3/era/${eraId}/leaderboard/${leaderboard}`, |
| 168 | + }); |
| 169 | +} |
0 commit comments