...
This commit is contained in:
@@ -4,6 +4,7 @@ from apiclient import (
|
||||
APIClient,
|
||||
)
|
||||
import typing as T
|
||||
import copy
|
||||
|
||||
# Import "preview" of Self typing
|
||||
# https://stackoverflow.com/a/70932112
|
||||
@@ -23,25 +24,31 @@ class BaseApiObject:
|
||||
:param data: Data to instantiate instance, defaults to empty dict.
|
||||
"""
|
||||
self.client = client
|
||||
self._data = data
|
||||
for k, v in data.items():
|
||||
if k == 'type': continue
|
||||
if k == 'id': continue
|
||||
setattr(self, k, v)
|
||||
self._internal_data_dict = copy.deepcopy(data)
|
||||
self.rel = self.__class__.rel
|
||||
"""rel: Relationship between a linked resource and the current document"""
|
||||
|
||||
def __repr__(self):
|
||||
return f'TeamSnap<{self.__class__.__name__}:{self.id}> "{self.__str__()}"'
|
||||
return f'TeamSnap<{self.__class__.__name__}:{self.id}> "{self.data.get("name")}"'
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._data.__getitem__(key)
|
||||
return self._internal_data_dict.__getitem__(key)
|
||||
# return getattr(self, key)
|
||||
|
||||
def __setitem__(self, key, newvalue):
|
||||
return self._data.__setitem__(key, newvalue)
|
||||
return self._internal_data_dict.__setitem__(key, newvalue)
|
||||
# return setattr(self, key, newvalue)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._data.items())
|
||||
return iter(self._internal_data_dict.items())
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._data["id"]
|
||||
return self._internal_data_dict["id"]
|
||||
|
||||
@property
|
||||
def data(self) -> T.Dict[str, T.Union[str, list]]:
|
||||
@@ -49,7 +56,7 @@ class BaseApiObject:
|
||||
|
||||
:return: dict: dict with keys:
|
||||
"""
|
||||
return self._data
|
||||
return self._internal_data_dict
|
||||
|
||||
@classmethod
|
||||
def search(cls, client: APIClient, **kwargs):
|
||||
@@ -62,11 +69,11 @@ class BaseApiObject:
|
||||
@classmethod
|
||||
def get(cls, client: APIClient, id: T.Union[int, str]) -> Self:
|
||||
r = client.get(f"{client.link(cls.rel)}/{id}")
|
||||
return cls(client, cls.rel, client.parse_response(r)[0])
|
||||
return cls(client, client.parse_response(r)[0])
|
||||
|
||||
@classmethod
|
||||
def new(cls, client: Self) -> Self:
|
||||
return cls(client, cls.rel)
|
||||
return cls(client)
|
||||
|
||||
def post(self) -> Self:
|
||||
data = {
|
||||
@@ -75,7 +82,7 @@ class BaseApiObject:
|
||||
}
|
||||
}
|
||||
r = self.client.post_item(self.rel, data=data)
|
||||
self._data = r
|
||||
self._internal_data_dict = r
|
||||
return self
|
||||
|
||||
def put(self) -> Self:
|
||||
@@ -86,7 +93,7 @@ class BaseApiObject:
|
||||
}
|
||||
id = self.data.get("id")
|
||||
r = self.client.put_item(self.rel, id=id, data=data)
|
||||
self._data = r
|
||||
self._internal_data_dict = r
|
||||
return self
|
||||
|
||||
def delete(self):
|
||||
|
||||
@@ -11,6 +11,51 @@ class Event(BaseApiObject):
|
||||
type = "event"
|
||||
version = "3.866.0"
|
||||
|
||||
__slots__ = (
|
||||
# "type",
|
||||
"additional_location_details",
|
||||
"browser_time_zone",
|
||||
"division_location_id",
|
||||
"doesnt_count_towards_record",
|
||||
"duration_in_minutes",
|
||||
"game_type_code",
|
||||
"icon_color",
|
||||
"is_canceled",
|
||||
"is_game",
|
||||
"is_overtime",
|
||||
"is_shootout",
|
||||
"is_tbd",
|
||||
"label",
|
||||
"location_id",
|
||||
"minutes_to_arrive_early",
|
||||
"name",
|
||||
"notes",
|
||||
"notify_opponent",
|
||||
"notify_opponent_contacts_email",
|
||||
"notify_opponent_contacts_name",
|
||||
"notify_opponent_notes",
|
||||
"notify_team",
|
||||
"notify_team_as_member_id",
|
||||
"opponent_id",
|
||||
"points_for_opponent",
|
||||
"points_for_team",
|
||||
"repeating_include",
|
||||
"repeating_type_code",
|
||||
"repeating_until",
|
||||
"results",
|
||||
"results_url",
|
||||
"shootout_points_for_opponent",
|
||||
"shootout_points_for_team",
|
||||
"start_date",
|
||||
"team_id",
|
||||
"time_zone",
|
||||
"tracks_availability",
|
||||
"uniform",
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self["formatted_title"]}'
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
"""Data dictionary for object
|
||||
|
||||
@@ -23,5 +23,5 @@ class EventLineupEntry(BaseApiObject):
|
||||
# this is a workaround
|
||||
r = client.get(f"{client.link(cls.rel)}/search", params=kwargs)
|
||||
results = client.parse_response(r)
|
||||
[cls(client, rel=cls.rel, data=r) for r in results]
|
||||
return [cls(client, rel=cls.rel, data=r) for r in results]
|
||||
[cls(client, data=r) for r in results]
|
||||
return [cls(client, data=r) for r in results]
|
||||
|
||||
Reference in New Issue
Block a user