Skip to content

Commit

Permalink
#47 shift chart endpoint simple addition (#48)
Browse files Browse the repository at this point in the history
* #47 shift chart endpoint simple addition

* Bumps version to 2.5.0
  • Loading branch information
coreyjs authored Mar 30, 2024
1 parent 87c1726 commit 95a848a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 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.4.0"
__version__ = "2.5.0"
17 changes: 16 additions & 1 deletion nhlpy/api/game_center.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, List
from nhlpy.http_client import HttpClient


Expand Down Expand Up @@ -43,3 +43,18 @@ def score_now(self, date: Optional[str] = None) -> dict:
:return: dict
"""
return self.client.get(resource=f"score/{date if date else 'now'}").json()

def shift_chart_data(self, game_id: str, excludes: List[str] = None) -> dict:
"""
Get shift chart data for the game_id. GameIds can be retrieved from the schedule endpoint.
:param excludes: List of strings of items to exclude from the response.
:param game_id: The game_id for the game you want the shift chart data for.
:return: dict
"""
if not excludes:
excludes = ["eventDetails"]

base_url: str = "https://api.nhle.com/stats/rest/en/shiftcharts"
exclude_p: str = ",".join(excludes)
expr_p: str = f"gameId={game_id} and ((duration != '00:00' and typeCode = 517) or typeCode != 517 )"
return self.client.get_by_url(full_resource=f"{base_url}?cayenneExp={expr_p}&exclude={exclude_p}").json()
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.4.0"
version = "2.5.0"
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 <[email protected]>"]
readme = "README.md"
Expand Down
10 changes: 10 additions & 0 deletions tests/test_game_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ 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"


@mock.patch("httpx.Client.get")
def test_shift_chart_data(h_m, nhl_client):
nhl_client.game_center.shift_chart_data(game_id="2020020001")
h_m.assert_called_once()
assert (
h_m.call_args[1]["url"] == "https://api.nhle.com/stats/rest/en/shiftcharts?cayenneExp=gameId=2020020001 and "
"((duration != '00:00' and typeCode = 517) or typeCode != 517 )&exclude=eventDetails"
)

0 comments on commit 95a848a

Please sign in to comment.