Skip to content

Commit

Permalink
Merge pull request #9 from dev-ruby/dev
Browse files Browse the repository at this point in the history
Separate model classes
  • Loading branch information
dev-ruby authored Oct 23, 2023
2 parents 188e76d + b72b70d commit d13c980
Show file tree
Hide file tree
Showing 33 changed files with 743 additions and 353 deletions.
2 changes: 2 additions & 0 deletions TrackerGG/HTTPClients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
from .httpclient import ResponseData
from .httpclient import Route
from .httpclient import get_http_client

__all__ = ["AbstractHTTPClient", "HTTPClientLibrary", "RequestMethod", "ResponseData", "Route", "get_http_client"]
4 changes: 3 additions & 1 deletion TrackerGG/HTTPClients/abstract_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
"""

from abc import *
from typing import Optional, Dict
from typing import *

from .httpclient import ResponseData, Route

__all__ = ["AbstractHTTPClient"]


class AbstractHTTPClient(metaclass=ABCMeta):
def __new__(cls, *args, **kwargs):
Expand Down
4 changes: 3 additions & 1 deletion TrackerGG/HTTPClients/aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

import asyncio
import atexit
from typing import ClassVar, Optional, Union, Dict
from typing import *

import aiohttp

from .abstract_http_client import AbstractHTTPClient
from .httpclient import MISSING, ResponseData, Route

__all__ = ["AiohttpHTTPClient"]


class AiohttpHTTPClient(AbstractHTTPClient):
USER_AGENT: ClassVar[str] = "Mozilla/5.0"
Expand Down
9 changes: 5 additions & 4 deletions TrackerGG/HTTPClients/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

import asyncio
from enum import Enum, auto
from typing import ClassVar, Optional, Dict, Any
from typing import *


__all__ = ["HTTPClientLibrary", "get_http_client", "ResponseData", "Route", "RequestMethod", "MISSING"]


class Missing:
Expand All @@ -30,9 +33,7 @@ class HTTPClientLibrary(Enum):
HTTPX = auto()


def get_http_client(
loop: asyncio.AbstractEventLoop, api_key: str, lib: Optional[HTTPClientLibrary] = None
):
def get_http_client(loop: asyncio.AbstractEventLoop, api_key: str, lib: Optional[HTTPClientLibrary] = None):
if lib is None:
try:
import aiohttp
Expand Down
4 changes: 3 additions & 1 deletion TrackerGG/HTTPClients/httpx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
"""

import asyncio
from typing import ClassVar, Optional, Union, Dict
from typing import *

import httpx

from .abstract_http_client import AbstractHTTPClient
from .httpclient import ResponseData, Route

__all__ = ["HttpxHTTPClient"]


class HttpxHTTPClient(AbstractHTTPClient):
USER_AGENT: ClassVar[str] = "Mozilla/5.0"
Expand Down
24 changes: 24 additions & 0 deletions TrackerGG/Models/Apex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from .apex_profile import ApexProfile
from .apex_query_data import ApexQueryData
from .apex_segment import ApexSegment
from .apex_stats import ApexStats

__all__ = ["ApexProfile", "ApexQueryData", "ApexSegment", "ApexStats"]
36 changes: 36 additions & 0 deletions TrackerGG/Models/Apex/apex_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from typing import *

from TrackerGG.Models.General import PlatformInfo, UserInfo
from .apex_segment import ApexSegment

__all__ = ["ApexProfile"]


class ApexProfile:
def __init__(self, data: Dict[str, Any]):
segments = []
for seg in data["segments"]:
segments.append(ApexSegment(seg))

self.platform_info: PlatformInfo = PlatformInfo(data["platformInfo"])
self.user_info: UserInfo = UserInfo(data["userInfo"])
self.segments: List[ApexSegment] = segments
self.expiry_date: str = data["expiryDate"]
32 changes: 32 additions & 0 deletions TrackerGG/Models/Apex/apex_query_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""
from typing import *

__all__ = ["ApexQueryData"]


class ApexQueryData:
def __init__(self, data: Dict[str, Optional[Union[str, int]]]):
self.platform_id: int = int(data["platformId"])
self.platform_slug: str = data["platformSlug"]
self.platform_user_identifier: str = data["platformUserIdentifier"]
self.platform_user_id: str = data["platformUserId"]
self.platform_user_handle: str = data["platformUserHandle"]
self.avatar_url: Optional[str] = data["avatarUrl"]
self.status: Optional[str] = data["status"]
self.additional_parameters: Optional[str] = data["additionalParameters"]
32 changes: 32 additions & 0 deletions TrackerGG/Models/Apex/apex_segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from typing import *

from .apex_stats import ApexStats

__all__ = ["ApexSegment"]


class ApexSegment:
def __init__(self, data: Dict[str, Union[str, dict]]):
self.type: str = data["type"]
self.attributes: dict = data["attributes"]
self.metadata: dict = data["metadata"]
self.expiry_date: str = data["expiryDate"]
self.stats: ApexStats = ApexStats(data["stats"])
42 changes: 42 additions & 0 deletions TrackerGG/Models/Apex/apex_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from typing import *

from TrackerGG.Models.General import Stat

__all__ = ["ApexStats"]


class ApexStats:
def __init__(self, data: Dict[str, dict]):
self.level: Optional[Stat] = Stat(data.get("level"))
self.kills: Optional[Stat] = Stat(data.get("kills"))
self.kills_per_match: Optional[Stat] = Stat(data.get("killsPerMatch"))
self.winning_kills: Optional[Stat] = Stat(data.get("winningKills"))
self.kills_as_kill_leader: Optional[Stat] = Stat(data.get("killsAsKillLeader"))
self.damage: Optional[Stat] = Stat(data.get("damage"))
self.matches_played: Optional[Stat] = Stat(data.get("matchesPlayed"))
self.revives: Optional[Stat] = Stat(data.get("revives"))
self.sniper_kills: Optional[Stat] = Stat(data.get("sniperKills"))
self.rank_score: Optional[Stat] = Stat(data.get("rankScore"))
self.arena_rank_score: Optional[Stat] = Stat(data.get("arenaRankScore"))
self.beast_of_the_hunt_kills: Optional[Stat] = Stat(data.get("beastOfTheHuntKills"))
self.grapple_travel_distance: Optional[Stat] = Stat(data.get("grappleTravelDistance"))
self.voices_warnings_heard: Optional[Stat] = Stat(data.get("voicesWarningsHeard"))
self.voices_warnings_heard: Optional[Stat] = Stat(data.get("voicesWarningsHeard"))
41 changes: 41 additions & 0 deletions TrackerGG/Models/CSGO/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from .csgo_map import CSGOMap
from .csgo_map_segment import CSGOMapSegment
from .csgo_map_stats import CSGOMapStats
from .csgo_profile import CSGOProfile
from .csgo_query_data import CSGOQueryData
from .csgo_segment import CSGOSegment
from .csgo_stats import CSGOStats
from .csgo_weapon import CSGOWeapon
from .csgo_weapon_segment import CSGOWeaponSegment
from .csgo_weapon_stats import CSGOWeaponStats

__all__ = [
"CSGOMap",
"CSGOMapSegment",
"CSGOMapStats",
"CSGOProfile",
"CSGOQueryData",
"CSGOSegment",
"CSGOStats",
"CSGOWeapon",
"CSGOWeaponSegment",
"CSGOWeaponStats",
]
31 changes: 31 additions & 0 deletions TrackerGG/Models/CSGO/csgo_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from typing import *

from .csgo_map_stats import CSGOMapStats

__all__ = ["CSGOMap"]


class CSGOMap:
def __init__(self, data: Dict[str, Union[str, dict]]):
self.attributes: dict = data["attributes"]
self.metadata: dict = data["metadata"]
self.expiry_date: str = data["expiryDate"]
self.stats: CSGOMapStats = CSGOMapStats(data["stats"])
32 changes: 32 additions & 0 deletions TrackerGG/Models/CSGO/csgo_map_segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from typing import *

from .csgo_map_stats import CSGOMapStats

__all__ = ["CSGOMapSegment"]


class CSGOMapSegment:
def __init__(self, data: Dict[str, Union[str, dict]]):
self.type: str = data["type"]
self.attributes: dict = data["attributes"]
self.metadata: dict = data["metadata"]
self.expiry_date: str = data["expiryDate"]
self.stats: CSGOMapStats = CSGOMapStats(data["stats"])
29 changes: 29 additions & 0 deletions TrackerGG/Models/CSGO/csgo_map_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from typing import *

from TrackerGG.Models.General import Stat

__all__ = ["CSGOMapStats"]


class CSGOMapStats:
def __init__(self, data: Dict[str, dict]):
self.rounds: Stat = Stat(data["rounds"])
self.wins: Stat = Stat(data["wins"])
Loading

0 comments on commit d13c980

Please sign in to comment.