diff --git a/battlemetrics/flag.py b/battlemetrics/flag.py index 394bb0b..1371a42 100644 --- a/battlemetrics/flag.py +++ b/battlemetrics/flag.py @@ -1,76 +1,69 @@ from __future__ import annotations +from datetime import UTC, datetime from typing import TYPE_CHECKING from . import utils from .types.flag import Flag as FlagPayload -from .types.flag import ( - FlagAttributes, - FlagRelationships -) - -from datetime import datetime, UTC +from .types.flag import FlagAttributes, FlagRelationships if TYPE_CHECKING: from .http import HTTPClient __all__ = ("Flag",) + class Flag: - """Represents a Flag""" + """Represents a Flag.""" - def __init__(self, *, data :FlagPayload, http : HTTPClient) -> None: + def __init__(self, *, data: FlagPayload, http: HTTPClient) -> None: self._http = http - self._data : FlagPayload = FlagPayload(**data) - self._attributes : FlagAttributes = data.get("attributes") - self._relationships : FlagRelationships = ( - utils.format_relationships( - # type: ignore [reportAttributeAccessIssue] - data.get("relationships") - ) + self._data: FlagPayload = FlagPayload(**data) + self._attributes: FlagAttributes = data.get("attributes") + self._relationships: FlagRelationships = utils.format_relationships( + # type: ignore [reportAttributeAccessIssue] + data.get("relationships"), ) def __str__(self) -> str: - """Return when the string method is run on this Flag""" - return self._attributes.get("name") + """Return when the string method is run on this Flag.""" + return self._attributes.get("name") @property def id(self) -> str: - """Returns ID of the Flag""" + """Returns ID of the Flag.""" return self._data.get("id") - - + @property def name(self) -> str: - """Returns Name of the Flag""" + """Returns Name of the Flag.""" return self._attributes.get("name") - + @property def description(self) -> str | None: - """Returns Description of the Flag""" + """Returns Description of the Flag.""" return self._attributes.get("description") - + @property def color(self) -> str: - """Returns Color of the Flag""" + """Returns Color of the Flag.""" return self._attributes.get("color") - + @property def created_at(self) -> datetime: - """Returns creation date of the Flag""" - + """Returns creation date of the Flag.""" return datetime.strptime( self._attributes.get("createdAt"), "%Y-%m-%dT%H:%M:%S.%fZ", ).replace( tzinfo=UTC, ) - + @property def updated_at(self) -> datetime: - """Returns updated date of the Flag""" + """Returns updated date of the Flag.""" return datetime.strptime( self._attributes.get("updatedAt"), "%Y-%m-%dT%H:%M:%S.%fZ", @@ -78,45 +71,25 @@ def updated_at(self) -> datetime: tzinfo=UTC, ) - - @property def icon(self) -> str | None: - """Returns Icon of the Flag""" + """Returns Icon of the Flag.""" return self._attributes.get("icon") - - - + @property def organization_id(self) -> int: - """Returns Organization ID of the Flag""" + """Returns Organization ID of the Flag.""" return self._relationships.get("organization_id") - + @property def user_id(self) -> int: - """Returns user ID of the Flag""" + """Returns user ID of the Flag.""" return self._relationships.get("user_id") - # TODO : add def Player Flag Update # TODO : add def Player Flag Delete - - async def update(self): - ... - - async def delete(self): - ... - - - - - - - - - - + async def update(self) -> None: ... # noqa: D102 - \ No newline at end of file + async def delete(self) -> None: ... # noqa: D102 diff --git a/battlemetrics/http.py b/battlemetrics/http.py index bf57ea5..d5c0d06 100644 --- a/battlemetrics/http.py +++ b/battlemetrics/http.py @@ -11,11 +11,11 @@ from . import utils from .errors import BMException, Forbidden, HTTPException, NotFound, Unauthorized +from .flag import Flag from .note import Note from .organization import Organization from .player import Player from .server import Server -from .flag import Flag from .types.organization import OrganizationPlayerStats if TYPE_CHECKING: @@ -1245,7 +1245,7 @@ async def player_session_history( params=data, ) - async def player_flags(self, player_id: int) -> dict[str, Any]: + async def player_flags(self, player_id: int) -> list[Flag]: """Return all the flags on a players profile. Parameters @@ -1261,13 +1261,11 @@ async def player_flags(self, player_id: int) -> dict[str, Any]: "include": "playerFlag", } - r = await self.request( Route(method="GET", path=f"/players/{player_id}/relationships/flags"), params=data, ) - flagData = r.get("included", []) - return [Flag(data=flag, http=self) for flag in flagData] + return [Flag(data=flag, http=self) for flag in r.get("included")] async def add_flag(self, player_id: int, flag_id: str | None = None) -> dict[str, Any]: """Create or add a flag to the targeted players profile. diff --git a/battlemetrics/types/flag.py b/battlemetrics/types/flag.py index 6a8a16f..8a81a85 100644 --- a/battlemetrics/types/flag.py +++ b/battlemetrics/types/flag.py @@ -1,28 +1,28 @@ from typing import TypedDict - class FlagAttributes(TypedDict): + """Represents the attributes of a Flag.""" - name : str - description : str | None - - color : str - icon : str | None + name: str + description: str | None + color: str + icon: str | None + createdAt: str + updatedAt: str - createdAt : str - updatedAt : str class FlagRelationships(TypedDict): + """Represents the relationships of a Flag.""" - user_id : int - organization_id : int + user_id: int + organization_id: int -class Flag(TypedDict): - - id : str - type : str - attributes : FlagAttributes - relationships : FlagRelationships +class Flag(TypedDict): + """Represents a Flag.""" + id: str + type: str + attributes: FlagAttributes + relationships: FlagRelationships