Merge pull request #26832 from JoshuaHall/overwatch-api

Added type definitions for overwatch-api
This commit is contained in:
Paul van Brenk
2018-06-26 13:21:26 -07:00
committed by GitHub
4 changed files with 378 additions and 0 deletions
+328
View File
@@ -0,0 +1,328 @@
// Type definitions for overwatch-api 0.4
// Project: https://github.com/alfg/overwatch-api
// Definitions by: JoshuaHall <https://github.com/JoshuaHall>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export type callbackFunc<T> = (err: Error | null, data: T) => void;
export type OverwatchPlatform = "pc" | "xbl" | "psn";
export type OverwatchServerRegion = "us" | "eu" | "kr" | "cn" | "global";
export type OverwatchHero =
| "Zarya"
| "Mercy"
| "Reinhardt"
| "Zenyatta"
| "Hanzo"
| "Orisa"
| "Genji"
| "Roadhog"
| "McCree"
| "Tracer"
| "Ana"
| "Winston"
| "D.Va"
| "Moira"
| "Junkrat"
| "Soldier: 76"
| "Brigitte"
| "Lúcio"
| "Torbjörn"
| "Reaper"
| "Pharah"
| "Widowmaker"
| "Bastion"
| "Symmetra"
| "Mei"
| "Sombra"
| "Doomfist";
export interface GameType {
won: number;
played: number;
}
export type QuickplayGameType = GameType;
export interface CompetitiveGameType extends GameType {
lost: number;
draw: number;
win_rate: number;
}
export interface GameTypes {
quickplay: QuickplayGameType;
competitive: CompetitiveGameType;
}
export interface Playtime {
quickplay: string;
competitive: string;
}
export interface CompetitiveRankInfo {
rank: number;
rank_img: string;
}
export interface OverwatchApiResponse {
username: string;
level: number;
portrait: string;
}
export interface ProfileApiResponse extends OverwatchApiResponse {
games: GameTypes;
playtime: Playtime;
competitive: CompetitiveRankInfo;
levelFrame: string;
star: string;
}
export interface TopHeroStats {
hero: OverwatchHero;
img: string;
}
export interface HeroTimePlayed extends TopHeroStats {
played: string;
}
export interface HeroGamesWon extends TopHeroStats {
games_won: string;
}
export interface HeroWinRate extends TopHeroStats {
win_rate: string;
}
export interface Stat {
title: string;
value: string;
}
export interface StatsByGameType<T> {
quickplay: T[];
competitive: T[];
}
export interface StatByGameType<T, U> {
quickplay: T;
competitive: U;
}
export interface QuickplayTopHeroData {
played: HeroTimePlayed[];
games_won: HeroGamesWon[];
}
export interface CompetitiveTopHeroData extends QuickplayTopHeroData {
win_rate: HeroWinRate[];
}
export interface StatsCategories {
top_heroes: StatByGameType<
QuickplayTopHeroData,
CompetitiveTopHeroData
>;
combat: StatsByGameType<Stat>;
match_awards: StatsByGameType<Stat>;
assists: StatsByGameType<Stat>;
average: StatsByGameType<Stat>;
miscellaneous: StatsByGameType<Stat>;
best: StatsByGameType<Stat>;
game: StatsByGameType<Stat>;
}
export interface StatsApiResponse extends OverwatchApiResponse {
stats: StatsCategories;
}
export function getProfile(
platform: OverwatchPlatform,
region: OverwatchServerRegion,
tag: string,
callback: callbackFunc<ProfileApiResponse>,
): void;
export function getStats(
platform: OverwatchPlatform,
region: OverwatchServerRegion,
tag: string,
callback: callbackFunc<StatsApiResponse>,
): void;
export namespace owl {
interface ApiResponse<T> {
data: T;
}
interface StandingInfo {
matchWin: number;
matchLoss: number;
matchDraw: number;
matchBye: number;
gameWin: number;
gameLoss: number;
gameTie: number;
gamePointsFor: number;
gamePointsAgainst: number;
placement: number;
}
interface StandingComparison {
key: string;
value: number;
}
interface StageStandingInfo extends PreseasonStandingInfo {
isPlayoffWinner: boolean;
}
interface Stages {
stage1: StageStandingInfo;
stage2: StageStandingInfo;
stage3: StageStandingInfo;
stage4: StageStandingInfo;
}
interface PreseasonStandingInfo extends StandingInfo {
comparisons: StandingComparison[];
}
interface TeamStandingInfo {
id: number;
divisionId: number;
name: string;
abbreviatedName: string;
league: StandingInfo;
stages: Stages;
preseason: PreseasonStandingInfo;
}
interface LiveMatchData {
liveMatch: {};
}
interface TournamentData {
id: number;
type: string;
}
interface MatchScores {
value: number;
}
interface TeamData {
id: number;
availableLanguages: string[];
handle: string;
name: string;
homeLocation: string;
primaryColor: string;
secondaryColor: string;
game: string;
abbreviatedName: string;
addressCountry: string;
logo: string;
icon: string;
secondaryPhoto: string;
type: string;
}
interface MatchGameScore {
team1: number;
team2: number;
}
interface MatchGameAttributeData {
instanceID: string;
map: string;
mapScore: MatchGameScore;
}
type ScoreTuple = [number, number];
interface MatchGameData {
id: number;
points: ScoreTuple;
attributes: MatchGameAttributeData;
attributesVersion: string;
state: string;
status: string;
statusReason: string;
stats: null;
handle: string;
}
interface MatchVideoData {
name: number;
description: string;
vodLink: string;
youtubeId: string;
thumbnailUrl: string;
}
interface MatchTournamentData {
id: number;
type: string;
location: string;
}
interface MatchData {
id: number;
competitors: TeamData[];
scores: MatchScores[];
conclusionValue: number;
conclusionStrategy: string;
winner: TeamData;
state: string;
status: string;
statusReason: string;
attributes: {};
games: MatchGameData[];
clientHints: any[];
dateCreated: number;
flags: any[];
handle: string;
startDate: string;
endDate: string;
showStartTime: boolean;
showEndTime: boolean;
startDateTS: number;
endDateTS: number;
youtubeId: string;
wins: ScoreTuple;
ties: ScoreTuple;
losses: ScoreTuple;
videos: MatchVideoData[];
tournament: MatchTournamentData;
}
interface WeekData {
id: number;
startDate: number;
endDate: number;
matches: MatchData[];
name: string;
}
interface StageScheduleInfo {
id: number;
slug: string;
enabled: boolean;
name: string;
tournament: TournamentData[];
matches: MatchData[];
weeks: WeekData[];
}
interface ScheduleInfo {
startDate: string;
endDate: string;
stages: StageScheduleInfo[];
}
function getLiveMatch(callback: callbackFunc<ApiResponse<LiveMatchData>>): void;
function getStandings(callback: callbackFunc<ApiResponse<TeamStandingInfo[]>>): void;
function getSchedule(callback: callbackFunc<ApiResponse<ScheduleInfo>>): void;
}
@@ -0,0 +1,25 @@
import { getProfile, OverwatchPlatform, OverwatchServerRegion, ProfileApiResponse, owl } from 'overwatch-api';
const platform: OverwatchPlatform = 'pc';
const region: OverwatchServerRegion = 'us';
const battleTag = 'sparK#12434';
getProfile(platform, region, battleTag, (err: Error | null, data: ProfileApiResponse) => {
if (err === null) {
console.log(`Username: ${data.username}`);
console.log(`Level: ${data.level}`);
console.log(`Rank: ${data.competitive.rank} SR`);
console.log(`Win Rate in Competitive: ${data.games.competitive.win_rate}`);
} else {
console.log(err);
}
});
owl.getStandings((err: Error | null, data: owl.ApiResponse<owl.TeamStandingInfo[]>) => {
if (err === null) {
const standingInfo: owl.TeamStandingInfo = data.data[0];
console.log(`${standingInfo.name} - ${standingInfo.abbreviatedName}`);
} else {
console.log(err);
}
});
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"overwatch-api-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }