Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
Support Black Ops Cold War and Full Match Data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Chrisp authored and Ethan Chrisp committed Nov 27, 2020
1 parent 6a17384 commit 4ba6da2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 13 deletions.
8 changes: 2 additions & 6 deletions callofduty/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ class Auth:
def __init__(self, email: str, password: str):
self.email: str = email
self.password: str = password

# Certain endpoints, such as the one used by GetPlayerLoadouts,
# take a bit longer to recieve data; Hence the increased read_timeout.
self.session: httpx.AsyncClient = httpx.AsyncClient(
timeout=httpx.Timeout(read_timeout=10)
)

self.session: httpx.AsyncClient = httpx.AsyncClient()

@property
def AccessToken(self) -> Optional[str]:
Expand Down
45 changes: 43 additions & 2 deletions callofduty/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .loot import Season
from .match import Match
from .player import Player
from .squad import Squad, SquadsReward, SquadsTournament
from .squad import Squad, SquadsTournament
from .stamp import AuthenticityStamp
from .utils import (
VerifyGameType,
Expand Down Expand Up @@ -623,6 +623,47 @@ async def GetMatch(self, title: Title, platform: Platform, matchId: int) -> Matc
self, {"id": matchId, "platform": platform.value, "title": title.value,},
)

async def GetFullMatch(
self,
platform: Platform,
title: Title,
mode: Mode,
matchId: int,
language: Language = Language.English,
) -> dict:
"""
Get a Call of Duty full match using its platform, username, title, mode, matchId, and language.
Parameters
----------
platform : callofduty.Platform
Platform to get the player from.
title : callofduty.Title
Call of Duty title which the match occured on.
mode: callofduty.Mode
Call of Duty mode to get the matches from.
matchId : int
Match ID.
language : callofduty.Language, optional
Language to use for localization data (default is English.)
Returns
-------
object
Match object representing the specified details.
"""

VerifyPlatform(platform)
VerifyTitle(title)
VerifyMode(mode, title)
VerifyLanguage(language)

return (
await self.http.GetFullMatch(
title.value, platform.value, mode.value, matchId, language.value
)
)["data"]

async def GetPlayerMatches(
self, platform: Platform, username: str, title: Title, mode: Mode, **kwargs
) -> List[Match]:
Expand Down Expand Up @@ -816,7 +857,7 @@ async def GetMatchTeams(
Returns
-------
list
Array containing two child arrays, one for each team. Each
Array containing child arrays, one for each team. Each
team's array contains Player objects which represent the
players on the team.
"""
Expand Down
1 change: 1 addition & 0 deletions callofduty/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Platform(Enum):


class Title(Enum):
BlackOpsColdWar = "cw"
ModernWarfare = "mw"
BlackOps4 = "bo4"
WWII = "wwii"
Expand Down
14 changes: 12 additions & 2 deletions callofduty/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class Request:
endpoint : str, optional
Endpoint to execute the request on (default is None.)
baseUrl : str, optional
Base URL to use for the request (default is https://callofduty.com/)
Base URL to use for the request (default is https://www.callofduty.com/)
headers : dict, optional
Headers to include in the request (default is None.)
json : dict, optional
JSON data to include in the body of the request (default is None.)
"""

defaultBaseUrl: str = "https://callofduty.com/"
defaultBaseUrl: str = "https://www.callofduty.com/"
myBaseUrl: str = "https://my.callofduty.com/"
squadsBaseUrl: str = "https://squads.callofduty.com/"

Expand Down Expand Up @@ -267,6 +267,16 @@ async def GetMatch(
)
)

async def GetFullMatch(
self, title: str, platform: str, mode: str, matchId: int, language: str
) -> Union[dict, list, str]:
return await self.Send(
Request(
"GET",
f"api/papi-client/crm/cod/v2/title/{title}/platform/{platform}/fullMatch/{mode}/{matchId}/{language}",
)
)

async def GetLeaderboard(
self,
title: str,
Expand Down
11 changes: 8 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ async def main():
# for mode in maps[mapName]:
# print(f" - {mode}")

# matches = await client.GetPlayerMatches(Platform.Activision, "Yeah#8649242", Title.ModernWarfare, Mode.Multiplayer, limit=3)
# for match in matches:
# print(match.id)
# match = (await client.GetPlayerMatches(Platform.Activision, "Yeah#8649242", Title.ModernWarfare, Mode.Warzone, limit=3))[0]
# teams = await match.teams()
# print(teams)

# player = await client.GetPlayer(Platform.BattleNet, "Mxtive#1930")
# match = (await player.matches(Title.ModernWarfare, Mode.Multiplayer, limit=3))[1]
Expand All @@ -126,6 +126,11 @@ async def main():
# details = await match.details()
# print(details)

# player = await client.GetPlayer(Platform.BattleNet, "Mxtive#1930")
# match = (await player.matches(Title.ModernWarfare, Mode.Multiplayer, limit=3))[1]
# match = await client.GetFullMatch(Platform.Activision, Title.ModernWarfare, Mode.Multiplayer, match.id)
# print(match)

# results = await client.SearchPlayers(Platform.Activision, "Tustin")
# for player in results:
# print(f"{player.username} ({player.platform.name})")
Expand Down

0 comments on commit 4ba6da2

Please sign in to comment.