ittf-pingpong
Version:
Unofficial API to retrieve player rankings and statistics from ITTF (International Table Tennis Federation) affiliated members and events.
213 lines (180 loc) • 5.79 kB
TypeScript
export {};
declare global {
//// currentRankings
type Rankings = RankEntry[];
interface RemainderResponse{
data : Rankings,
errMsg : unknown[]
};
interface WttApiCurrentRankingResponse{
Version : string,
Source : string,
System : string ,
StatusCode : number,
RequestId : string,
ResponseDate : string,
ResponseTime : string,
Result : Rankings
};
interface RankEntry {
IttfId : string,
PlayerName : string,
CountryCode : string,
CountryName : string,
AssociationCountryCode : string,
AssociationCountryName : string,
CategoryCode : string,
AgeCategoryCode : string,
SubEventCode : string,
RankingYear : string,
RankingMonth : string,
RankingWeek : string,
RankingPointsCareer : string | null,
RankingPointsYTD : string,
RankingPosition : string,
CurrentRank : string,
PreviousRank : string | null,
RankingDifference : string,
PublishDate : string
};
//// playerIttfId
type FullName = {
playerFullName: string;
playerGivenName?: never;
playerFamilyName?: never;
playerIttfId?: never;
};
type GivenName = {
playerFullName?: never;
playerGivenName: string;
playerFamilyName?: never;
playerIttfId?: never;
};
type FamilyName = {
playerFullName?: never;
playerGivenName?: never;
playerFamilyName: string;
playerIttfId?: never;
};
type Records = PlayerExtendedDetails[];
type PlayerId = Pick<PlayerExtendedDetails, 'IttfId' | 'PlayerFamilyNameFirst'>
interface WttApiPlayerRecordResponse{
Version : string,
Source : string,
System : string ,
StatusCode : number,
RequestId : string,
ResponseDate : string,
ResponseTime : string,
Result : Records;
};
interface PlayerExtendedDetails {
IttfId : string;
PlayerName : string;
PlayerGivenName : string;
PlayerFamilyName : string;
PlayerFamilyNameFirst : string;
CountryCode : string;
CountryName : string;
NationalityCode : string;
NationalityName : string;
OrganizationCode : string;
OrganizationName : string;
Gender : string;
Age : string;
DOB : string;
Handedness? : string;
Grip? : string;
Style? : string;
EquipmentSponsor? : string;
BladeType? : string;
RacketColoringA? : string;
RacketColoringB? : string;
RacketCoveringA? : string;
RacketCoveringB? : string;
ActiveSince? : string;
EarningsCareer? : string;
EarningsYTD? : string;
LastMatch? : string;
NextMatch? : string;
HeadShot? : string;
Bio? : string;
HeadshotR? : string;
HeadshotL? : string;
}
//// playerProfile
type PlayerFullName = {
playerFullName: string;
playerGivenName?: never;
playerFamilyName?: never;
playerIttfId?: never;
};
type IttfId = {
playerIttfId: number;
playerFullName?: never;
};
type ProfileOptions = {
includeExtendedDetails?: boolean;
}
type Stats = PlayerProfile;
interface PlayerProfile {
player : PlayerDetails | PlayerExtendedDetails;
ranking : RankingHistory;
stats : GameStatistics;
};
interface PlayerDetails {
ittfId : string;
Org : string;
Gender : string;
Name : string;
Age : number;
Active : boolean;
Country : CountryInfo;
};
interface CountryInfo {
Desc: string;
continentId: string;
subcontinent: string;
}
interface RankingHistory {
LastPos: PositionMetric[];
BestPos: PositionMetric[];
}
interface PositionMetric {
Week: number;
Year: number;
Month: number;
Category: string;
Points: number;
Rk: number;
Gender?: string; //Not required
CategoryDesc: CategoryDescription;
}
interface CategoryDescription {
L1: string; // e.g., "Seniors"
S1: string; // e.g., "Open"
}
interface GameStatistics {
total: {
byYear: WinLossMetrics[];
total: WinLossMetrics;
};
indiv: {
byYear: WinLossMetrics[];
totals: WinLossMetrics;
};
doubles: {
byYear: WinLossMetrics[];
totals: WinLossMetrics;
};
}
interface WinLossMetrics {
wins: number;
loses: number;
total: number;
winsPerc: string; // API returns these as strings
losesPerc: string;
Year?: number | string; // Optional for the "total" blocks
tournaments?: number; // Only in indiv and doubles
}
}