-
Notifications
You must be signed in to change notification settings - Fork 6
/
bo4.ts
119 lines (100 loc) · 4.87 KB
/
bo4.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
BlackoutMatch,
BlackoutOverall,
RawBlackoutMatchesObject,
RawBlackoutObject
} from './blackout';
import { COD_API_ENDPOINT, getDataFromAPI } from './utils';
import {
RawZombiesMatchesObject,
RawZombiesObject,
ZombiesMatch,
ZombiesOverall
} from './zombies';
import {
MultiplayerLifetime,
MultiplayerMatch,
MultiplayerWeekly,
RawMultiplayerMatchesObject,
RawMultiplayerObject,
} from './multiplayer';
const BO4_ENDPOINT = `${COD_API_ENDPOINT}/crm/cod/v2/title/bo4`;
export type BO4Platform = 'psn' | 'xbl' | 'battle';
export function getRawMultiplayerStats(username: string, platform: BO4Platform) {
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/profile?type=mp`;
return getDataFromAPI<RawMultiplayerObject>(uri)
}
export function getRawBlackoutStats(username: string, platform: BO4Platform) {
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/profile?type=blackout`;
return getDataFromAPI<RawBlackoutObject>(uri);
}
export function getRawZombiesStats(username: string, platform: BO4Platform) {
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/profile?type=zombies`;
return getDataFromAPI<RawZombiesObject>(uri);
}
export interface MatchesProps {
username: string;
platform: BO4Platform;
start?: Date;
end?: Date;
}
export function getRawMultiplayerMatchesStats({ username, platform, start, end }: MatchesProps) {
const startTimestamp = start ? start.getTime() : 0;
const endTimestamp = end ? end.getTime() : 0;
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/matches/mp/start/${startTimestamp}/end/${endTimestamp}/details`;
return getDataFromAPI<RawMultiplayerMatchesObject>(uri);
}
export function getRawBlackoutMatchesStats({ username, platform, start, end }: MatchesProps) {
const startTimestamp = start ? start.getTime() : 0;
const endTimestamp = end ? end.getTime() : 0;
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/matches/warzone/start/${startTimestamp}/end/${endTimestamp}/details`;
return getDataFromAPI<RawBlackoutMatchesObject>(uri);
}
export function getRawZombiesMatchesStats({ username, platform, start, end }: MatchesProps) {
const startTimestamp = start ? start.getTime() : 0;
const endTimestamp = end ? end.getTime() : 0;
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/matches/zombies/start/${startTimestamp}/end/${endTimestamp}/details`;
return getDataFromAPI<RawZombiesMatchesObject>(uri);
}
/* These Blackout Methods are not populated with data yet
export async function getSoloBlackoutStats(username: string, platform: BO4Platform) {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.mode.warzone_solo;
}
export async function getDuoBlackoutStats(username: string, platform: BO4Platform) {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.mode.warzone_duo;
}
export async function getQuadBlackoutStats(username: string, platform: BO4Platform) {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.mode.warzone_quad;
}
*/
export async function getOverallBlackoutStats(username: string, platform: BO4Platform): Promise<BlackoutOverall> {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.all;
}
export async function getOverallZombiesStats(username: string, platform: BO4Platform): Promise<ZombiesOverall> {
const rawZombiesObject = await getRawZombiesStats(username, platform);
return rawZombiesObject.data.mp.lifetime.all;
}
export async function getLifetimeMultiplayerStats(username: string, platform: BO4Platform): Promise<MultiplayerLifetime> {
const rawMultiplayerObject = await getRawMultiplayerStats(username, platform);
return rawMultiplayerObject.data.mp.lifetime;
}
export async function getWeeklyMultiplayerStats(username: string, platform: BO4Platform): Promise<MultiplayerWeekly> {
const rawMultiplayerObject = await getRawMultiplayerStats(username, platform);
return rawMultiplayerObject.data.mp.weekly;
}
export async function getMultiplayerMatchesStats(props: MatchesProps): Promise<MultiplayerMatch[]> {
const rawMatchesObject = await getRawMultiplayerMatchesStats(props);
return rawMatchesObject.data.matches;
}
export async function getBlackoutMatchesStats(props: MatchesProps): Promise<BlackoutMatch[]> {
const rawMatchesObject = await getRawBlackoutMatchesStats(props);
return rawMatchesObject.data.matches;
}
export async function getZombiesMatchesStats(props: MatchesProps): Promise<ZombiesMatch[]> {
const rawMatchesObject = await getRawZombiesMatchesStats(props);
return rawMatchesObject.data.matches;
}