Skip to content

Commit

Permalink
Gamecenter endpoints added. For boxscore, landing, play-by-play and … (
Browse files Browse the repository at this point in the history
…#19)

* Gamecenter endpoints added.  For boxscore, landing, play-by-play and score/now
  • Loading branch information
coreyjs authored Nov 22, 2023
1 parent e79424f commit 3b47b38
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 179 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ or using pipx

2) `poetry install --with dev`

3) `poetry shell` to run commands such as `pytest`
3) `poetry shell`

```python

$ poetry shell

# You can then run the following
$ pytest
$ ruff .
$ black .

```
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="score/now").json()
104 changes: 0 additions & 104 deletions nhlpy/api/games.py

This file was deleted.

38 changes: 0 additions & 38 deletions nhlpy/api/players.py

This file was deleted.

7 changes: 2 additions & 5 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 @@ -8,14 +8,11 @@ class NHLClient:
You can instantiate this class and then access the various endpoints of the API,
such as:
client = NHLClient()
client.teams.all()
"""

def __init__(self) -> None:
# self.core = core.Core()
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
29 changes: 29 additions & 0 deletions tests/test_game_center.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 3b47b38

Please sign in to comment.