Skip to content

Commit

Permalink
added BuddyLevels, SprayLevels and Gears endpoints
Browse files Browse the repository at this point in the history
added
`relation_type` property in `Contract.Content`.
`background_color` property in `CompetitiveTier.Tier`,
  • Loading branch information
MinshuG committed Jul 28, 2021
1 parent ee4e311 commit 90c4088
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def synctest():
contract = api.search_contracts_by_uuid(contracts[0].uuid)
events = api.get_events()
event = api.search_events_by_uuid(events[0].uuid)
gears = api.get_gears()
gear = api.search_gears_by_uuid(gears[0].uuid)
buddy_levels = api.get_buddy_levels()
buddy_level = api.search_buddy_levels_by_uuid(buddy_levels[0].uuid)
spray_levels = api.get_spray_levels()
spray_level = api.search_spray_levels_by_uuid(spray_levels[0].uuid)

async def Asynctest():
api = AsyncValorantApi(language=language)
Expand Down Expand Up @@ -100,6 +106,12 @@ async def Asynctest():
contract = await api.search_contracts_by_uuid(contracts[0].uuid)
events = await api.get_events()
event = await api.search_events_by_uuid(events[0].uuid)
gears = await api.get_gears()
gear = await api.search_gears_by_uuid(gears[0].uuid)
buddy_levels = await api.get_buddy_levels()
buddy_level = await api.search_buddy_levels_by_uuid(buddy_levels[0].uuid)
spray_levels = await api.get_spray_levels()
spray_level = await api.search_spray_levels_by_uuid(spray_levels[0].uuid)

async def generate(generator, agent: Agent):
image = await generator.generate(agent)
Expand Down
51 changes: 51 additions & 0 deletions valorant_api/api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from valorant_api.gear import Gear
from valorant_api.events import Event
from valorant_api.contracts import Contract
from .competitive import Competitive
from .competitivetiers import CompetitiveTier
from .sprays import Spray
from .sprays import Level as SprayLevel
from .agents import Agent
from .base_list import BaseList
from .buddies import Buddy
from .buddies import Level as BuddyLevel
from .bundles import Bundle
from .contenttiers import ContentTier
from .currencies import Currency
Expand Down Expand Up @@ -209,6 +212,30 @@ def search_events_by_uuid(self, uuid: str) -> Event:
data = self.client.get(f"{Endpoints.Events}/{uuid}")
return Contract(data)

def get_gears(self) -> BaseList[Gear]:
data = self.client.get(Endpoints.Gears)
return BaseList([Gear(x) for x in data])

def search_gears_by_uuid(self, uuid: str) -> Gear:
data = self.client.get(f"{Endpoints.Gears}/{uuid}")
return Gear(data)

def get_buddy_levels(self) -> BaseList[BuddyLevel]:
data = self.client.get(Endpoints.BuddyLevels)
return BaseList([BuddyLevel(x) for x in data])

def search_buddy_levels_by_uuid(self, uuid: str) -> BuddyLevel:
data = self.client.get(f"{Endpoints.BuddyLevels}/{uuid}")
return BuddyLevel(data)

def get_spray_levels(self) -> BaseList[SprayLevel]:
data = self.client.get(Endpoints.SprayLevels)
return BaseList([SprayLevel(x) for x in data])

def search_spray_levels_by_uuid(self, uuid: str) -> SprayLevel:
data = self.client.get(f"{Endpoints.SprayLevels}/{uuid}")
return SprayLevel(data)


class AsyncValorantApi:
"""
Expand Down Expand Up @@ -397,3 +424,27 @@ async def get_events(self) -> BaseList[Event]:
async def search_events_by_uuid(self, uuid: str) -> Event:
data = await self.client.get(f"{Endpoints.Events}/{uuid}")
return Contract(data)

async def get_gears(self) -> BaseList[Gear]:
data = await self.client.get(Endpoints.Gears)
return BaseList([Gear(x) for x in data])

async def search_gears_by_uuid(self, uuid: str) -> Gear:
data = await self.client.get(f"{Endpoints.Gears}/{uuid}")
return Gear(data)

async def get_buddy_levels(self) -> BaseList[BuddyLevel]:
data = await self.client.get(Endpoints.BuddyLevels)
return BaseList([BuddyLevel(x) for x in data])

async def search_buddy_levels_by_uuid(self, uuid: str) -> BuddyLevel:
data = await self.client.get(f"{Endpoints.BuddyLevels}/{uuid}")
return BuddyLevel(data)

async def get_spray_levels(self) -> BaseList[SprayLevel]:
data = await self.client.get(Endpoints.SprayLevels)
return BaseList([SprayLevel(x) for x in data])

async def search_spray_levels_by_uuid(self, uuid: str) -> SprayLevel:
data = await self.client.get(f"{Endpoints.SprayLevels}/{uuid}")
return SprayLevel(data)
2 changes: 1 addition & 1 deletion valorant_api/base_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
T = TypeVar('T')


class BaseList(list):
class BaseList(list, Generic[T]):
_list: List[T]

def __init__(self, data: List[T]):
Expand Down
2 changes: 2 additions & 0 deletions valorant_api/competitivetiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Tier:
tier_name: str
division: str
division_name: str
background_color: str
color: str
small_icon: Optional[str]
large_icon: Optional[str]
Expand All @@ -19,6 +20,7 @@ def __init__(self, data: dict) -> None:
self.tier_name = data.get("tierName")
self.division = data.get("division")
self.division_name = data.get("divisionName")
self.background_color = data.get("backgroundColor")
self.color = data.get("color")
self.small_icon = data.get("smallIcon")
self.large_icon = data.get("largeIcon")
Expand Down
1 change: 1 addition & 0 deletions valorant_api/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self):
@dataclass
class Content(Mapper):
relation_uuid: str
relation_type: str
chapters: List[Chapter]
premium_reward_schedule_uuid: str
premium_vp_cost: int
Expand Down
3 changes: 3 additions & 0 deletions valorant_api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Endpoints:
BASE = "https://valorant-api.com/v1/"
Agents = BASE + "agents"
Buddies = BASE + "buddies"
BuddyLevels = Buddies + "/levels"
Bundles = BASE + "bundles"
ContentTiers = BASE + "contenttiers"
Currencies = BASE + "currencies"
Expand All @@ -13,6 +14,7 @@ class Endpoints:
PlayerTitles = BASE + "playertitles"
Seasons = BASE + "seasons"
Sprays = BASE + "sprays"
SprayLevels = Sprays + "/levels"
Themes = BASE + "themes"
Weapons = BASE + "weapons"
Version = BASE + "version"
Expand All @@ -23,3 +25,4 @@ class Endpoints:
WeaponSkinLevels = Weapons + "/skinlevels"
Contracts = BASE + "contracts"
Events = BASE + "events"
Gears = BASE + "gear"
41 changes: 41 additions & 0 deletions valorant_api/gear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from dataclasses import dataclass
from typing import Optional
from .utils import Mapper


@dataclass
class GridPosition(Mapper):
row: Optional[int] = None
column: Optional[int] = None

def __init__(self):
super().__init__()

@dataclass
class ShopData(Mapper):
cost: Optional[int] = None
category: Optional[str] = None
category_text: Optional[str] = None
grid_position: Optional[GridPosition] = None
can_be_trashed: Optional[bool] = None
image: Optional[str] = None
new_image: Optional[str] = None
new_image2: Optional[str] = None
asset_path: Optional[str] = None

def __init__(self):
super().__init__()

@dataclass
class Gear(Mapper):
uuid: str
raw_data: dict
display_name: Optional[str] = None
description: Optional[str] = None
display_icon: Optional[str] = None
asset_path: Optional[str] = None
shop_data: Optional[ShopData] = None

def __init__(self, data: dict):
self.raw_data = data
self.map(childclasses={"shopData": ShopData, "gridPosition": GridPosition})
3 changes: 2 additions & 1 deletion valorant_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def map(self, childclasses=None, childdata=None):
for key, value in raw_data.items():
key_snake = snakeit(key)
if hasattr(self, key_snake):
raise AttributeExistsError(f"{self} already has '{key_snake}' attribute.")
if getattr(self, key_snake) is not None:
raise AttributeExistsError(f"{self} already has '{key_snake}' attribute.")
if isinstance(value, dict):
child = childclasses[key]()
child.map(childdata=value, childclasses=childclasses)
Expand Down

0 comments on commit 90c4088

Please sign in to comment.