Skip to content

Commit 02d8813

Browse files
committed
bugfix: Debug logging now properly will print the URL generated by the method call. Logging is also fixed to only enable debug logging in the nhl-api-py package.
- Add: notebook/ example jupyter notebook of each available endpoint call. For ref/testing purposes only
1 parent 377637a commit 02d8813

File tree

3 files changed

+59527
-5
lines changed

3 files changed

+59527
-5
lines changed

nhlpy/http_client.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ def __init__(self, message: str, status_code: int = 401):
6969
class HttpClient:
7070
def __init__(self, config) -> None:
7171
self._config = config
72+
self._logger = logging.getLogger(__name__)
7273
if self._config.debug:
73-
logging.basicConfig(level=logging.DEBUG)
74+
self._logger.setLevel(logging.DEBUG)
75+
if not self._logger.handlers:
76+
handler = logging.StreamHandler()
77+
formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
78+
handler.setFormatter(formatter)
79+
self._logger.addHandler(handler)
7480
else:
75-
logging.basicConfig(level=logging.WARNING)
81+
self._logger.setLevel(logging.WARNING)
7682

7783
def _handle_response(self, response: httpx.Response, url: str) -> None:
7884
"""Handle different HTTP status codes and raise appropriate exceptions"""
@@ -108,6 +114,8 @@ def _handle_response(self, response: httpx.Response, url: str) -> None:
108114
def get(self, endpoint: Endpoint, resource: str, query_params: dict = None) -> httpx.Response:
109115
"""
110116
Private method to make a get request to the NHL API. This wraps the lib httpx functionality.
117+
:param query_params:
118+
:param endpoint:
111119
:param resource:
112120
:return: httpx.Response
113121
:raises:
@@ -124,7 +132,10 @@ def get(self, endpoint: Endpoint, resource: str, query_params: dict = None) -> h
124132
with httpx.Client(
125133
verify=self._config.ssl_verify, timeout=self._config.timeout, follow_redirects=self._config.follow_redirects
126134
) as client:
127-
r: httpx.Response = client.get(url=f"{endpoint.value}{resource}", params=query_params)
135+
full_url = f"{endpoint.value}{resource}"
136+
if self._config.debug:
137+
self._logger.debug(f"GET: {full_url}")
138+
r: httpx.Response = client.get(url=full_url, params=query_params)
128139

129140
self._handle_response(r, resource)
130141
return r

0 commit comments

Comments
 (0)