Skip to content

Commit

Permalink
added cleanup_payload function to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
NoHeDidnt committed Jul 29, 2020
1 parent 46af1d7 commit b92e04f
Showing 1 changed file with 11 additions and 1 deletion.
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):
""" 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)

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()]

@staticmethod
def cleanup_payload(payload):
for key in payload.copy():
if payload.get(key) is None:
delattr(payload, key)

return payload

1 comment on commit b92e04f

@NoHeDidnt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#30 not much to it, implemented the call to cleanup the payload to build_request, so it gets called on every request

Please sign in to comment.