Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to helpers and client #53

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
12 changes: 11 additions & 1 deletion pyracing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ async def _authenticate(self):
else:
self.log.info('Login successful')

async def _build_request(self, url, params):
async def _build_request(self, url, payload):
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
""" Builds the final GET request from url and params
"""
if not self.session.cookies.__bool__():
self.log.info("No cookies in cookie jar.")
await self._authenticate()

params = self.cleanup_payload(payload)
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved

NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
self.log.info(f'Request being sent to: {url} with params: {params}')

response = await self.session.get(
Expand Down Expand Up @@ -782,3 +784,11 @@ async def yearly_stats(self, cust_id):
return []

return [career_stats.YearlyStats(x) for x in response.json()]

NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
@staticmethod
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
def cleanup_payload(payload):
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
for key in payload.copy():
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
if payload.get(key) is None:
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
delattr(payload, key)
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved

NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved
return payload
NoHeDidnt marked this conversation as resolved.
Show resolved Hide resolved