Skip to content

Commit

Permalink
Gamecenter endpoints added. For boxscore, landing, play-by-play and s…
Browse files Browse the repository at this point in the history
…core/now
  • Loading branch information
coreyjs committed Nov 22, 2023
1 parent e79424f commit 61946c5
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 138 deletions.
2 changes: 1 addition & 1 deletion nhlpy/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Should this be driven by the main pyproject.toml file? yes, is it super convoluted? yes, can it wait? sure

__version__ = "2.0.1"
__version__ = "2.0.2"
29 changes: 0 additions & 29 deletions nhlpy/api/core.py

This file was deleted.

36 changes: 36 additions & 0 deletions nhlpy/api/game_center.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from nhlpy.api import BaseNHLAPIClient


class GameCenter(BaseNHLAPIClient):
def boxscore(self, game_id: str) -> dict:
"""
Get the boxscore for the game_id. GameIds can be retrieved from the schedule endpoint.
:param game_id: The game_id for the game you want the boxscore for.
:return: dict
"""
return self._get(resource=f"gamecenter/{game_id}/boxscore").json()

def play_by_play(self, game_id: str) -> dict:
"""
Get the play by play for the game_id. GameIds can be retrieved from the schedule endpoint.
:param game_id: The game_id for the game you want the play by play for.
:return: dict
"""
return self._get(resource=f"gamecenter/{game_id}/play-by-play").json()

def landing(self, game_id: str) -> dict:
"""
Get verbose information about the matchup for the given game.
GameIds can be retrieved from the schedule endpoint.
:param game_id: The game_id for the game you want the landing page for.
:return: dict
"""
return self._get(resource=f"gamecenter/{game_id}/landing").json()

def score_now(self) -> dict:
"""
Get the current score of all games in progress. I think, not totally sure.
:return: dict
"""
return self._get(resource=f"score/now").json()
104 changes: 0 additions & 104 deletions nhlpy/api/games.py

This file was deleted.

5 changes: 2 additions & 3 deletions nhlpy/nhl_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nhlpy.api import teams, standings, schedule
from nhlpy.api import teams, standings, schedule, game_center


class NHLClient:
Expand All @@ -16,6 +16,5 @@ def __init__(self) -> None:
self.teams = teams.Teams()
self.standings = standings.Standings()
self.schedule = schedule.Schedule()
# self.players = players.Players()
# self.games = games.Games()
self.game_center = game_center.GameCenter()
# self.helpers = helpers.Helpers()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "nhl-api-py"
version = "2.0.1"
version = "2.0.2"
description = "NHL API. For standings, team stats, outcomes, player information. Contains each individual API endpoint as well as convience methods for easy data loading in Pandas or any ML applications."
authors = ["Corey Schaf <cschaf@gmail.com>"]
readme = "README.md"
Expand Down
28 changes: 28 additions & 0 deletions tests/test_game_center.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest import mock


@mock.patch("httpx.get")
def test_boxscore(h_m, nhl_client):
nhl_client.game_center.boxscore(game_id="2020020001")
h_m.assert_called_once()
assert h_m.call_args[1]["url"] == "https://api-web.nhle.com/v1/gamecenter/2020020001/boxscore"


@mock.patch("httpx.get")
def test_play_by_play(h_m, nhl_client):
nhl_client.game_center.play_by_play(game_id="2020020001")
h_m.assert_called_once()
assert h_m.call_args[1]["url"] == "https://api-web.nhle.com/v1/gamecenter/2020020001/play-by-play"


@mock.patch("httpx.get")
def test_landing_page(h_m, nhl_client):
nhl_client.game_center.landing(game_id="2020020001")
h_m.assert_called_once()
assert h_m.call_args[1]["url"] == "https://api-web.nhle.com/v1/gamecenter/2020020001/landing"

@mock.patch("httpx.get")
def test_score_now(h_m, nhl_client):
nhl_client.game_center.score_now()
h_m.assert_called_once()
assert h_m.call_args[1]["url"] == "https://api-web.nhle.com/v1/score/now"

0 comments on commit 61946c5

Please sign in to comment.