Skip to content

Commit

Permalink
Merge pull request #1 from dev-ruby/dev
Browse files Browse the repository at this point in the history
Change Major API Sets
  • Loading branch information
dev-ruby authored Mar 29, 2023
2 parents a01410d + cfcde13 commit 8e0b3db
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 284 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 DevRuby
Copyright (c) 2023 DevRuby

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 3 additions & 6 deletions TrackerGG/info.py → TrackerGG/Models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2021 DevRuby
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
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
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.
"""

__version__ = "1.0"
__author__ = "DevRuby"
__license__ = "MIT License"
__copyright__ = "(c) 2021 DevRuby"
from .csgo import CSGOProfile
34 changes: 34 additions & 0 deletions TrackerGG/Models/csgo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- 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 Dict, Any, List

from .platform import PlatformInfo
from .segment import Segment
from .user import UserInfo


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

self.platform_info: PlatformInfo = PlatformInfo(data["platformInfo"])
self.user_info: UserInfo = UserInfo(data["userInfo"])
self.segments: List[Segment] = segments
self.expiry_date: str = data["expiryDate"]
46 changes: 46 additions & 0 deletions TrackerGG/Models/platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- 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 enum import Enum
from typing import Dict, Union, Any


class Platform(Enum):
steam = "steam"
origin = "origin"
xbl = "xbl"
psn = "psn"
uplay = "uplay"


class PlatformInfo:
def __init__(self, data: Dict[str, Union[str, int, None]]):
platforms = {
"steam": Platform.steam,
"origin": Platform.origin,
"xbl": Platform.xbl,
"psn": Platform.psn,
"uplay": Platform.uplay,
}

self.platform_slug: Platform = platforms[data["platformSlug"]]
self.platform_user_id: Union[str, int] = data["platformUserId"]
self.platform_user_handle: str = data["platformUserHandle"]
self.platform_user_identifier: Union[str, int] = data["platformUserIdentifier"]
self.avatar_url: str = data["avatarUrl"]
self.additional_parameters: Any = data["additionalParameters"]
49 changes: 49 additions & 0 deletions TrackerGG/Models/segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- 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 List, Dict, Union, Any


class Stat:
def __init__(self, data: Dict[str, Union[int, float, str, None, dict]]):
self.rank: int = data["rank"]
self.percentile: float = data["percentile"]
self.display_name: str = data["displayName"]
self.display_category: str = data["displayCategory"]
self.category: Union[None, str] = data["category"]
self.description: str = data["description"]
self.metadata: Union[None, dict[str, Any]] = data["metadata"]
self.value: int = data["value"]
self.display_value: str = data["displayValue"]
self.display_type: str = data["displayType"]

def __str__(self):
return f"Name : {self.display_name}\nValue : {self.display_value}\nPercentile : {self.percentile}"


class Segment:
def __init__(self, data: Dict[str, Union[str, int, dict]]):
stats = []
for stat in data["stats"].keys():
stats.append(Stat(data["stats"][stat]))

self.type: str = data["type"]
self.attributes: dict = data["attributes"]
self.metadata: dict = data["metadata"]
self.expiry_date: str = data["expiryDate"]
self.stats: List[Stat] = stats
49 changes: 49 additions & 0 deletions TrackerGG/Models/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- 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 Dict, Union, Optional, Any, List


class SocialAccount:
def __init__(self, data: Dict[str, Union[str, int, None]]):
self.platform_slug: str = data["platformSlug"]
self.platform_user_id: Union[str, int] = data["platformUserId"]
self.platform_user_handle: str = data["platformUserHandle"]
self.platform_user_identifier: Union[str, int] = data["platformUserIdentifier"]
self.avatar_url: str = data["avatarUrl"]
self.additional_parameters: Any = data["additionalParameters"]


class UserInfo:
def __init__(self, data: Dict[str, Union[str, int, bool, list, None]]):
social_accounts = []
if data["socialAccounts"]:
for social_account in data["socialAccounts"]:
social_accounts.append(SocialAccount(social_account))

self.user_id: Optional[int] = data["userId"]
self.is_premium: bool = data["isPremium"]
self.is_verified: bool = data["isVerified"]
self.is_influencer: bool = data["isInfluencer"]
self.is_partner: bool = data["isPartner"]
self.country_code: Union[str, None] = data["countryCode"]
self.custom_avatar_url: Optional[str] = data["customAvatarUrl"]
self.custom_hero_url: Optional[str] = data["customHeroUrl"]
self.social_accounts: List[SocialAccount] = social_accounts
self.page_views: int = data["pageviews"]
self.custom_avatar_url: Any = data["isSuspicious"]
18 changes: 4 additions & 14 deletions TrackerGG/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2021 DevRuby
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
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
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 .exceptions import ApiError
from .exceptions import UserError
from .models import Client
from .models import CsgoStatData
from .models import CsgoProfileData
from .models import CsgoStats
from .models import PlatformInfo
from .models import Platform
from .info import __version__
from .info import __author__
from .info import __license__
from .info import __copyright__
from .Models import CSGOProfile
from .client import CSGOClient
49 changes: 49 additions & 0 deletions TrackerGG/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- 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.
"""

import asyncio
import json

from .Models import CSGOProfile
from .httpclient import HTTPClient
from .httpclient import RequestMethod
from .httpclient import ResponseData
from .httpclient import Route


class CSGOClient:
api_key: str
loop: asyncio.AbstractEventLoop
http_client: HTTPClient

def __init__(self, api_key: str) -> None:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
self.loop = asyncio.get_event_loop()
self.api_key = api_key
self.http_client = HTTPClient(self.loop, self.api_key)

async def get_profile(self, identifier: str):
response: ResponseData = await self.http_client.request(
Route(RequestMethod.GET, f"/csgo/standard/profile/steam/{identifier}")
)

assert response.status == 200, "HTTP Response Status Code is not 200"

json_data: dict = json.loads(response.response_data)

return CSGOProfile(json_data["data"])
24 changes: 0 additions & 24 deletions TrackerGG/exceptions.py

This file was deleted.

Loading

0 comments on commit 8e0b3db

Please sign in to comment.