From 9a09aee0b69e69c9be23942736d4a0f20dd75b66 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Tue, 25 Apr 2023 17:16:31 -0500 Subject: [PATCH] implement workaround to allow eventlineupentry --- pyteamsnap/models/eventlineupentry.py | 33 +++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/pyteamsnap/models/eventlineupentry.py b/pyteamsnap/models/eventlineupentry.py index 8e389cd..13db7e3 100644 --- a/pyteamsnap/models/eventlineupentry.py +++ b/pyteamsnap/models/eventlineupentry.py @@ -1,4 +1,6 @@ from .base import BaseTeamsnapObject +from .eventlineup import EventLineup +import apiclient.exceptions class EventLineupEntry(BaseTeamsnapObject): @@ -19,9 +21,32 @@ class EventLineupEntry(BaseTeamsnapObject): @classmethod def search(cls, client, **kwargs): + # For some reason the query listed for search at this endpoint is for EventLineup, not EventLineupEntry + # this is a workaround, specifically line 31 which calls class method instead of client + try: + event_lineup_results = client.query(EventLineup.rel, "search", **kwargs) + event_lineups = [EventLineup(client, data=result) for result in event_lineup_results] + lineup_entries = [] + for event_lineup in event_lineups: + event_lineup_entries_results = cls.query(client, "search", event_lineup_id=event_lineup.id) + lineup_entries += [cls(client, data=result) for result in event_lineup_entries_results] + except apiclient.exceptions.ServerError as e: + raise e + + return lineup_entries + + + @classmethod + def query(cls, client, query: str, **kwargs) -> list: # For some reason the query listed for search at this endpoint is for EventLineup, not EventLineupEntry # this is a workaround - r = client.get(f"{client.link(cls.rel)}/search", params=kwargs) - results = client.parse_response(r) - [cls(client, data=r) for r in results] - return [cls(client, data=r) for r in results] + + if cls.rel == "event_lineup_entries" and query == "search": + response = client.get( + f"https://api.teamsnap.com/v3/{cls.rel}/{query}", + params=kwargs) + parsed_response = [{d.name: d.value for d in item.data} for item in response.items] + return parsed_response + + else: + return client.query(cls.rel, query, **kwargs)