From 4b021a082e9d44bba4d681e5c300a4a8bc801205 Mon Sep 17 00:00:00 2001 From: SharpBit <31069084+SharpBit@users.noreply.github.com> Date: Sun, 6 Oct 2024 22:18:02 -0400 Subject: [PATCH] remove `Client.get_constants` --- CHANGELOG.md | 7 ++++--- README.rst | 3 ++- brawlstats/core.py | 35 +---------------------------------- brawlstats/models.py | 7 +------ brawlstats/utils.py | 1 - docs/api.rst | 3 --- docs/index.rst | 4 ++-- tests/test_async.py | 9 --------- tests/test_blocking.py | 9 --------- 9 files changed, 10 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c98b186..bb7a8b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,11 @@ All notable changes to this project will be documented in this file. ### Fixed - Client actually uses session passed into parameters now instead of creating a new one anyways - `UnexpectedError` now properly shows the returned text in the message -- The `use_cache` parameter now works for `get_constants`, `get_brawlers`, and the async client. +- The `use_cache` parameter now works for `get_brawlers` and the async client ### Removed -- No longer uses `asyncio.Lock` when prevent_ratelimit=True and is_async=True as that just imitates sync behavior -- Dropped support for Python 3.5, 3.6, 3.7, and 3.8. +- Removed the prevent_ratelimit option for the Client +- Dropped support for Python 3.5, 3.6, 3.7, and 3.8 +- Removed `Client.get_constants` as the site that was hosting it is no longer running ## [4.1.1] - 10/31/21 ### Fixed diff --git a/README.rst b/README.rst index 98ed88f..6b20ccc 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,8 @@ Features - Get a player profile and battlelog. - Get a club and its members. - Get the top 200 rankings for players, clubs, or a specific brawler. -- Get information about maps, brawlers, and more! +- Get information about all the brawlers in the game. +- Get information about the current event rotation! Installation ~~~~~~~~~~~~ diff --git a/brawlstats/core.py b/brawlstats/core.py index 418907e..3f756cc 100644 --- a/brawlstats/core.py +++ b/brawlstats/core.py @@ -9,7 +9,7 @@ from cachetools import TTLCache from .errors import Forbidden, NotFoundError, RateLimitError, ServerError, UnexpectedError -from .models import BattleLog, Brawlers, Club, Constants, EventRotation, Members, Player, Ranking +from .models import BattleLog, Brawlers, Club, EventRotation, Members, Player, Ranking from .utils import API, bstag, typecasted log = logging.getLogger(__name__) @@ -185,14 +185,6 @@ def _request(self, url, use_cache=True): async def _aget_model(self, url, model, use_cache=True, key=None): """Method to turn the response data into a Model class for the async client.""" data = await self._arequest(url, use_cache=use_cache) - - if model == Constants: - if key: - if data.get(key): - return model(self, data.get(key)) - else: - raise KeyError(f'No such Constants key "{key}"') - return model(self, data) def _get_model(self, url, model, use_cache=True, key=None): @@ -202,14 +194,6 @@ def _get_model(self, url, model, use_cache=True, key=None): return self._aget_model(url, model=model, use_cache=use_cache, key=key) data = self._request(url, use_cache) - - if model == Constants: - if key: - if data.get(key): - return model(self, data.get(key)) - else: - raise KeyError(f'No such Constants key "{key}"') - return model(self, data) @typecasted @@ -354,23 +338,6 @@ def get_rankings( return self._get_model(url, model=Ranking, use_cache=use_cache) - def get_constants(self, key: str=None, use_cache=True) -> Constants: - """Gets Brawl Stars constants extracted from the app. - - Parameters - ---------- - key : str, optional - Any key to get specific data, by default None - use_cache : bool, optional - Whether to use the internal 3 minutes cache, by default True - - Returns - ------- - Constants - Data containing some Brawl Stars constants. - """ - return self._get_model(self.api.CONSTANTS, model=Constants, key=key, use_cache=use_cache) - def get_brawlers(self, use_cache=True) -> Brawlers: """Gets available brawlers and information about them. diff --git a/brawlstats/models.py b/brawlstats/models.py index 74c97b6..b04d021 100644 --- a/brawlstats/models.py +++ b/brawlstats/models.py @@ -2,7 +2,7 @@ from .utils import bstag -__all__ = ['Player', 'Club', 'Members', 'Ranking', 'BattleLog', 'Constants', 'Brawlers', 'EventRotation'] +__all__ = ['Player', 'Club', 'Members', 'Ranking', 'BattleLog', 'Brawlers', 'EventRotation'] class BaseBox: @@ -135,11 +135,6 @@ def __repr__(self): return ''.format(len(self)) -class Constants(BaseBox): - """Data containing some Brawl Stars constants.""" - pass - - class Brawlers(BaseBoxList): """A list of available brawlers and information about them.""" diff --git a/brawlstats/utils.py b/brawlstats/utils.py index 184b488..e042941 100644 --- a/brawlstats/utils.py +++ b/brawlstats/utils.py @@ -14,7 +14,6 @@ def __init__(self, base_url, version=1): self.PROFILE = self.BASE + '/players' self.CLUB = self.BASE + '/clubs' self.RANKINGS = self.BASE + '/rankings' - self.CONSTANTS = 'https://fourjr.herokuapp.com/bs/constants' self.BRAWLERS = self.BASE + '/brawlers' self.EVENT_ROTATION = self.BASE + '/events/rotation' diff --git a/docs/api.rst b/docs/api.rst index a61cd4a..c9ecaf9 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -25,9 +25,6 @@ Data Models .. autoclass:: brawlstats.models.Members :members: -.. autoclass:: brawlstats.models.Constants - :members: - .. autoclass:: brawlstats.models.Brawlers :members: diff --git a/docs/index.rst b/docs/index.rst index 66a61df..16ddaa5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -28,8 +28,8 @@ Features - Get a player profile and battlelog. - Get a club and its members. - Get the top 200 rankings for players, clubs, or a specific brawler. -- Get information about maps and more! -- Get information about current available brawlers. +- Get information about all the brawlers in the game. +- Get information about the current event rotation! Installation ~~~~~~~~~~~~ diff --git a/tests/test_async.py b/tests/test_async.py index 744d315..ece42ea 100644 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -105,15 +105,6 @@ async def test_get_rankings(self): with self.assertRaises(ValueError): await self.client.get_rankings(ranking='brawlers', brawler='SharpBit') - async def test_get_constants(self): - constants = await self.client.get_constants() - self.assertIsInstance(constants, brawlstats.Constants) - - maps = await self.client.get_constants('maps') - self.assertIsInstance(maps, brawlstats.Constants) - - await self.assertAsyncRaises(KeyError, self.client.get_constants('invalid')) - async def test_get_brawlers(self): brawlers = await self.client.get_brawlers() self.assertIsInstance(brawlers, brawlstats.Brawlers) diff --git a/tests/test_blocking.py b/tests/test_blocking.py index 757b3c4..cc3d0c8 100644 --- a/tests/test_blocking.py +++ b/tests/test_blocking.py @@ -87,15 +87,6 @@ def test_get_rankings(self): self.assertIsInstance(us_brawler_ranking, brawlstats.Ranking) self.assertTrue(len(us_brawler_ranking) == 1) - def test_get_constants(self): - constants = self.client.get_constants() - self.assertIsInstance(constants, brawlstats.Constants) - - maps = self.client.get_constants('maps') - self.assertIsInstance(maps, brawlstats.Constants) - - self.assertRaises(KeyError, self.client.get_constants, 'invalid') - def test_get_brawlers(self): brawlers = self.client.get_brawlers() self.assertIsInstance(brawlers, brawlstats.Brawlers)