Compare commits

..

6 Commits

3 changed files with 38 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ from apiclient import (
JsonResponseHandler,
JsonRequestFormatter,
)
from pyteamsnap.models.base import BaseTeamsnapObject
# import pyteamsnap.models.base
import datetime
from pyteamsnap.formatters import CollectionJsonResponseHandler, CollectionJsonRequestFormatter
@@ -36,11 +36,10 @@ class TeamSnap(APIClient):
pass
def link(self, link_name):
d = {link["rel"]: link["href"] for link in self._root_collection["links"]}
return d.get(link_name)
return self._root_collection.links.get(rel=link_name).href
def bulk_load(
self, team_id, types: T.List[BaseTeamsnapObject], **kwargs
self, team_id, types: T.List[T.Any], **kwargs # TODO fix typing
) -> T.List[TTeamSnap]:
"""

View File

@@ -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)

View File

@@ -10,7 +10,11 @@ with open('README.rst') as readme_file:
with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements = ['api-client', 'typing-extensions']
requirements = [
'api-client',
'typing-extensions',
'collection-json @ git+https://github.com/anthonyscorrea/collection-json.python.git'
]
test_requirements = [ ]
@@ -39,6 +43,6 @@ setup(
test_suite='unittests',
tests_require=test_requirements,
url='https://github.com/anthonyscorrea/pyteamsnap',
version='0.2.0',
version='0.2.1',
zip_safe=False,
)