Skip to content

Commit

Permalink
Update Black Ops 4 data with full TS interfaces and move other cods t…
Browse files Browse the repository at this point in the history
…o legacy object
  • Loading branch information
jakejrichards committed Nov 27, 2018
1 parent 3fa701a commit 36333f8
Show file tree
Hide file tree
Showing 17 changed files with 1,486 additions and 184 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
dist
170 changes: 170 additions & 0 deletions blackout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
export interface BaseStats {
killsRevenge: number;
top10PlacementTeam: number;
kdratio: number;
killsUnderwaterEnemy: number;
downsEliminatedTeam: number;
ekia: number;
score: number;
distanceTraveledWingsuit: number;
rank: number;
deaths: number;
frackingBlastDoorsOpened: number;
killsEliminated: number;
wins: number;
itemsDropped: number;
squads2Eliminated: number;
winStreak: number;
distanceTraveledVehicleLand: number;
headshotDamage: number;
top5PlacementPlayer: number;
revives: number;
activationCountBroadcast: number;
rankxp: number;
placementxp: number;
killsWithoutDamage: number;
downsEliminated: number;
shots: number;
killsAfterRevive: number;
top10PlacementTeamNoCircleDamage: number;
timePlayedTotal: number;
killxp: number;
killsLongshotSniper: number;
top15PlacementTeam: number;
top5PlacementTeam: number;
killsEquipment: number;
winsLastAlive: number;
itemsPickedUp: number;
totalDamage: number;
plevel: number;
killsEnemyInVehicleWater: number;
squads4Eliminated: number;
downsRevived: number;
misses: number;
squadsEliminatedUnassisted: number;
basketsMade: number;
hitsHeadshot: number;
killStreak: number;
itemsHealthUsed: number;
killsEnemyInVehicleLand: number;
winxp: number;
top10PlacementTeamPerks: number;
hits: number;
itemsBackpacksUsed: number;
killsLongshot: number;
challengexp: number;
mostKillsInAGame: number;
longestFiringRangeBullseye: number;
killsVehiclePassenger: number;
activationCountCrane: number;
tanborFudgelyInteractions: number;
losses: number;
vehicleScavengerWater: number;
totalGamesPlayed: number;
killsUnderwater: number;
killsEnemyInVehicleAir: number;
winsWithoutDown: number;
totalShots: number;
wlratio: number;
destroyEquipment: number;
killsEarly: number;
characterQuestsCompleted: number;
distanceTraveledWingsuitMiles: number;
downs: number;
top5FirstInventory: number;
distanceTraveledVehicleWater: number;
curWinStreak: number;
vehicleEscapes: number;
distanceTraveledVehicleLandMiles: number;
vehicleScavengerAir: number;
killsUnarmed: number;
killsAfterDamage: number;
top25PlacementPlayer: number;
vehiclesDestroyed: number;
vehicleUsedAll: number;
killsZombie: number;
winsFirst: number;
killsAfterDamageUnarmed: number;
vehicleLockExits: number;
distanceTraveledVehicleAir: number;
killsWhileStunned: number;
kills: number;
distanceTraveledVehicleAirMiles: number;
vehiclesDestroyedOccupied: number;
top10PlacementPlayer: number;
top5Avenger: number;
vehicleDamageOccupied: number;
activationCountJukebox: number;
distanceTraveledFoot: number;
killsVehicleDriver: number;
headshots: number;
assists: number;
itemsPaintCansCollected: number;
ties: number;
vehicleDamage: number;
longestDistanceKill: number;
distanceTraveledVehicleWaterMiles: number;
vehiclesDestroyedOccupiedUsingVehicle: number;
itemsNPaintCansCollected: number;
maxFiringRangeBullseye: number;
itemsArmorUsed: number;
killsAvenged: number;
winsWithoutKills: number;
cargoSupplyOpened: number;
vehicleScavengerLand: number;
mostDamageInAGame: number;
timePlayedAlive: number;
squads3Eliminated: number;
}

export interface BlackoutOverall extends BaseStats {
topPlacementsAll: number;
accuracy: number;
damagePerMinute: number;
ekiadRatio: number;
killsEarlyPercentage: number;
winPercentage: number;
damagePerGame: number;
ekiaPerGame: number;
headshotPercentage: number;
topPlacementsPlayer: number;
topPlacementsTeam: number;
revivesPerGame: number;
avgLifeTime: number;
killsPerGame: number;
}

export interface Mode {
warzone_duo: BaseStats;
warzone_quad: BaseStats;
warzone_solo: BaseStats;
}

export interface Lifetime {
all: BlackoutOverall;
mode: Mode;
}

export interface Mp {
lifetime: Lifetime;
level: number;
maxLevel: number;
levelXpRemainder: number;
levelXpGained: number;
prestige: number;
prestigeId: number;
maxPrestige: number;
}

export interface Data {
title: string;
platform: string;
username: string;
mp: Mp;
engagement: any;
}

export interface RawBlackoutObject {
status: string;
data: Data;
}
62 changes: 62 additions & 0 deletions bo4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { COD_API_ENDPOINT, getDataFromAPI } from './utils';
import { RawBlackoutObject } from './blackout';
import { RawMultiplayerObject } from './multiplayer';
import { RawZombiesObject } from './zombies';

const BO4_ENDPOINT = `${COD_API_ENDPOINT}/crm/cod/v2/title/bo4`;

type Platform = 'psn' | 'xbl' | 'battle';

export function getRawBlackoutStats(username: string, platform: Platform) {
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/profile?type=blackout`;
return getDataFromAPI<RawBlackoutObject>(uri);
}

export function getRawMultiplayerStats(username: string, platform: Platform) {
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/profile?type=mp`;
return getDataFromAPI<RawMultiplayerObject>(uri)
}

export function getRawZombiesStats(username: string, platform: Platform) {
const uri = `${BO4_ENDPOINT}/platform/${platform}/gamer/${username}/profile?type=zombies`;
return getDataFromAPI<RawZombiesObject>(uri);
}

export async function getOverallBlackoutStats(username: string, platform: Platform) {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.all;
}

/* These Blackout Methods are not populated with data yet
export async function getSoloBlackoutStats(username: string, platform: Platform) {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.mode.warzone_solo;
}
export async function getDuoBlackoutStats(username: string, platform: Platform) {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.mode.warzone_duo;
}
export async function getQuadBlackoutStats(username: string, platform: Platform) {
const rawBlackoutObject = await getRawBlackoutStats(username, platform);
return rawBlackoutObject.data.mp.lifetime.mode.warzone_quad;
}
*/

export async function getOverallZombiesStats(username: string, platform: Platform) {
const rawZombiesObject = await getRawZombiesStats(username, platform);
return rawZombiesObject.data.mp.lifetime.all;
}

export async function getLifetimeMultiplayerStats(username: string, platform: Platform) {
const rawMultiplayerObject = await getRawMultiplayerStats(username, platform);
return rawMultiplayerObject.data.mp.lifetime;
}

export async function getWeeklyMultiplayerStats(username: string, platform: Platform) {
const rawMultiplayerObject = await getRawMultiplayerStats(username, platform);
return rawMultiplayerObject.data.mp.weekly;
}
48 changes: 48 additions & 0 deletions example/black-ops-4-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { BO4 } = require('../dist/index');

const username = 'Consisttt'; // username
const platform = 'psn'; // psn | xbl | battle

// Retrieve Raw Responses

BO4.getRawMultiplayerStats(username, platform)
.then(raw => {
console.log(`${username} (${platform}) is prestige ${raw.data.mp.prestige} level ${raw.data.mp.level} in Black Ops 4 Multiplayer`);
});

BO4.getRawBlackoutStats(username, platform)
.then(raw => {
console.log(`${username} (${platform}) is level ${raw.data.mp.level} in Black Ops 4 Blackout`);
});

BO4.getRawZombiesStats(username, platform)
.then(raw => {
console.log(`${username} (${platform}) is level ${raw.data.mp.level} in Black Ops 4 Zombies`);
});

// Specific Methods

BO4.getLifetimeMultiplayerStats(username, platform)
.then(data => {
console.log(`${username} (${platform}) has ${data.all.kills} total kill(s) in Black Ops 4 Multiplayer`);
});

BO4.getWeeklyMultiplayerStats(username, platform)
.then(data => {
console.log(`${username} (${platform}) has ${data.all.wins} win(s) this week in Black Ops 4 Multiplayer`);
});

BO4.getOverallZombiesStats(username, platform)
.then(data => {
console.log(`${username} (${platform}) has ${data.kills} total kill(s) in Black Ops 4 Zombies`);
});

BO4.getOverallBlackoutStats(username, platform)
.then(data => {
console.log(`${username} (${platform}) has ${data.wins} total win(s) in Black Ops 4 Blackout`);
});

// Not yet supported methods
// BO4.getSoloBlackoutStats
// BO4.getDuoBlackoutStats
// BO4.getQuadBlackoutStats
10 changes: 5 additions & 5 deletions example/example.js → example/legacy-cod-example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getLeaderboards, getProfile, getRecentMatches, getRecentSummary } = require('../index'); // require('cod-api');
const { LegacyCOD } = require('../dist/index'); // require('cod-api');

const title = "wwii"; // bo3, iw, wwii
const platform = "psn"; // psn, xbl, steam
Expand All @@ -8,7 +8,7 @@ const type = "core"; // core, hc, arena
const time = "monthly"; // alltime, monthly, weekly
const mode = "war"; // career, war (Team Deathmatch), dm (Free-For-All), conf (Kill Confirmed), ctf (Capture The Flag), sd (Search & Destroy), dom (Domination), ball (Gridiron), hp (Hardpoint), 1v1, raid (War)

getProfile({ title, platform, username })
LegacyCOD.getProfile({ title, platform, username })
.then(response => {
// Do something...
console.log(response);
Expand All @@ -18,7 +18,7 @@ getProfile({ title, platform, username })
console.log(err);
});

getRecentMatches({ title, platform, username, days })
LegacyCOD.getRecentMatches({ title, platform, username, days })
.then(response => {
// Do something...
console.log(response);
Expand All @@ -28,7 +28,7 @@ getRecentMatches({ title, platform, username, days })
console.log(err);
});

getRecentSummary({ title, platform, username, days })
LegacyCOD.getRecentSummary({ title, platform, username, days })
.then(response => {
// Do something...
console.log(response);
Expand All @@ -38,7 +38,7 @@ getRecentSummary({ title, platform, username, days })
console.log(err);
});

getLeaderboards({ title, platform, time, type, mode, username })
LegacyCOD.getLeaderboards({ title, platform, time, type, mode, username })
.then(response => {
// Do something...
console.log(response);
Expand Down
Loading

0 comments on commit 36333f8

Please sign in to comment.