blizzardapi2 2.1.20__tar.gz → 2.1.21__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {blizzardapi2-2.1.20/blizzardapi2.egg-info → blizzardapi2-2.1.21}/PKG-INFO +1 -1
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/api.py +9 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/battlenet/battlenet_api.py +1 -3
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/battlenet/battlenet_oauth_api.py +6 -3
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/diablo3/diablo3_community_api.py +3 -2
- blizzardapi2-2.1.21/blizzardapi2/hearthstone/hearthstone_api.py +52 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/hearthstone/hearthstone_game_data_api.py +6 -2
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_community_api.py +1 -1
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/wow/wow_profile_api.py +1 -1
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21/blizzardapi2.egg-info}/PKG-INFO +1 -1
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/package.json +1 -1
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/pyproject.toml +1 -1
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/test_base_api.py +59 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/test_hearthstone.py +57 -17
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/test_starcraft2.py +2 -3
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/test_wow.py +3 -3
- blizzardapi2-2.1.20/blizzardapi2/hearthstone/hearthstone_api.py +0 -116
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.github/dependabot.yml +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.github/workflows/README.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.github/workflows/black-check.yml +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.github/workflows/python-package.yml +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.gitignore +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.pre-commit-config.yaml +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/.release-it.json +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/CLAUDE.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/CODE_OF_CONDUCT.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/CONTRIBUTING.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/LICENSE +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/README.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/SECURITY.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/__init__.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/battlenet/__init__.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/blizzard_api.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/diablo3/__init__.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/diablo3/diablo3_api.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/diablo3/diablo3_game_data_api.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/hearthstone/__init__.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/__init__.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_api.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_game_data_api.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/types.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/wow/__init__.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/wow/wow_api.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/wow/wow_game_data_api.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/SOURCES.txt +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/dependency_links.txt +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/requires.txt +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/top_level.txt +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/docs/battlenet/README.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/docs/diablo3/README.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/docs/hearthstone/README.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/docs/pull_request_template.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/docs/starcraft2/README.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/docs/wow/README.md +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/poetry.lock +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/setup.cfg +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/__init__.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/conftest.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/test_battlenet.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/tests/test_diablo3.py +0 -0
- {blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/uv.lock +0 -0
|
@@ -33,6 +33,12 @@ class BaseApi:
|
|
|
33
33
|
|
|
34
34
|
TOKEN_REFRESH_BUFFER = timedelta(minutes=5)
|
|
35
35
|
|
|
36
|
+
# Per-request timeouts (seconds). Subclass and override either constant
|
|
37
|
+
# to customize. `requests` defaults to no timeout, which lets a hung
|
|
38
|
+
# Blizzard endpoint wedge the caller indefinitely.
|
|
39
|
+
DEFAULT_GET_TIMEOUT = 30.0
|
|
40
|
+
DEFAULT_POST_TIMEOUT = 10.0
|
|
41
|
+
|
|
36
42
|
def __init__(self, client_id: str, client_secret: str) -> None:
|
|
37
43
|
"""Initialize the API client.
|
|
38
44
|
|
|
@@ -66,6 +72,7 @@ class BaseApi:
|
|
|
66
72
|
url,
|
|
67
73
|
params={"grant_type": "client_credentials"},
|
|
68
74
|
auth=(self._client_id, self._client_secret),
|
|
75
|
+
timeout=self.DEFAULT_POST_TIMEOUT,
|
|
69
76
|
)
|
|
70
77
|
response.raise_for_status()
|
|
71
78
|
token_data = response.json()
|
|
@@ -147,6 +154,7 @@ class BaseApi:
|
|
|
147
154
|
url,
|
|
148
155
|
params=params,
|
|
149
156
|
headers={"Authorization": f"Bearer {token}"},
|
|
157
|
+
timeout=self.DEFAULT_GET_TIMEOUT,
|
|
150
158
|
)
|
|
151
159
|
|
|
152
160
|
# Handle 401 errors for client credentials (not user tokens)
|
|
@@ -157,6 +165,7 @@ class BaseApi:
|
|
|
157
165
|
url,
|
|
158
166
|
params=params,
|
|
159
167
|
headers={"Authorization": f"Bearer {self._access_token}"},
|
|
168
|
+
timeout=self.DEFAULT_GET_TIMEOUT,
|
|
160
169
|
)
|
|
161
170
|
|
|
162
171
|
response.raise_for_status()
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"""battlenet_api.py file."""
|
|
2
2
|
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
3
|
from .battlenet_oauth_api import BattlenetOAuthApi
|
|
6
4
|
|
|
7
5
|
|
|
@@ -13,6 +11,6 @@ class BattlenetApi:
|
|
|
13
11
|
client_secret (str): A string client secret supplied by Blizzard.
|
|
14
12
|
"""
|
|
15
13
|
|
|
16
|
-
def __init__(self, client_id: str, client_secret: str) ->
|
|
14
|
+
def __init__(self, client_id: str, client_secret: str) -> None:
|
|
17
15
|
"""Init BattlenetApi."""
|
|
18
16
|
self.oauth = BattlenetOAuthApi(client_id, client_secret)
|
|
@@ -40,18 +40,21 @@ class BattlenetOAuthApi(BaseApi):
|
|
|
40
40
|
"""
|
|
41
41
|
super().__init__(client_id, client_secret)
|
|
42
42
|
|
|
43
|
-
def get_user_info(self, region: Region, access_token: str) -> dict[str, Any]:
|
|
43
|
+
def get_user_info(self, region: Region | str, access_token: str) -> dict[str, Any]:
|
|
44
44
|
"""Get basic information about the user associated with the current bearer token.
|
|
45
45
|
|
|
46
46
|
Args:
|
|
47
|
-
region: The region to query
|
|
47
|
+
region: The region to query — either a ``Region`` enum member or
|
|
48
|
+
a bare string (e.g. ``"us"`` or ``Region.US``). Bare strings
|
|
49
|
+
are accepted for ergonomics and parity with the other game APIs.
|
|
48
50
|
access_token: The OAuth access token.
|
|
49
51
|
|
|
50
52
|
Returns:
|
|
51
53
|
A dictionary containing user information.
|
|
52
54
|
|
|
53
55
|
Raises:
|
|
54
|
-
|
|
56
|
+
requests.HTTPError: If the API request fails (raised via
|
|
57
|
+
``response.raise_for_status()`` in ``BaseApi._make_request``).
|
|
55
58
|
"""
|
|
56
59
|
resource = "/oauth/userinfo"
|
|
57
60
|
query_params = {
|
|
@@ -255,7 +255,7 @@ class Diablo3CommunityApi(BaseApi):
|
|
|
255
255
|
self, region: str, locale: str, account_id: str, hero_id: int
|
|
256
256
|
) -> dict[str, Any]:
|
|
257
257
|
"""
|
|
258
|
-
Return
|
|
258
|
+
Return the equipped follower items for a given hero.
|
|
259
259
|
|
|
260
260
|
Args:
|
|
261
261
|
region (str): The region to query.
|
|
@@ -264,7 +264,8 @@ class Diablo3CommunityApi(BaseApi):
|
|
|
264
264
|
hero_id (int): The ID of the hero.
|
|
265
265
|
|
|
266
266
|
Returns:
|
|
267
|
-
Dict[str, Any]: A dictionary containing the
|
|
267
|
+
Dict[str, Any]: A dictionary containing the follower items
|
|
268
|
+
equipped on the specified hero.
|
|
268
269
|
"""
|
|
269
270
|
resource = f"/d3/profile/{account_id}/hero/{hero_id}/follower-items"
|
|
270
271
|
query_params = {"locale": locale}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Hearthstone API client.
|
|
2
|
+
|
|
3
|
+
This module exposes the Hearthstone facade. Hearthstone has only one
|
|
4
|
+
sub-domain (game data), but this file mirrors the structure of the other
|
|
5
|
+
game packages (`wow.game_data`, `diablo3.game_data`, etc.) so the public
|
|
6
|
+
API surface stays consistent.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Any, Dict
|
|
10
|
+
|
|
11
|
+
from ..api import BaseApi
|
|
12
|
+
from ..types import Locale, Region
|
|
13
|
+
from .hearthstone_game_data_api import HearthstoneGameDataApi
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ApiResponse:
|
|
17
|
+
"""Wrapper for API responses with metadata."""
|
|
18
|
+
|
|
19
|
+
data: Dict[str, Any]
|
|
20
|
+
region: Region
|
|
21
|
+
locale: Locale
|
|
22
|
+
namespace: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class HearthstoneApi(BaseApi):
|
|
26
|
+
"""Hearthstone API client facade.
|
|
27
|
+
|
|
28
|
+
Exposes Hearthstone endpoints under ``.game_data`` for consistency with
|
|
29
|
+
the other game facades (``wow.game_data``, ``diablo3.game_data``, ...).
|
|
30
|
+
|
|
31
|
+
Example:
|
|
32
|
+
```python
|
|
33
|
+
api = BlizzardApi("your_id", "your_secret")
|
|
34
|
+
cards = api.hearthstone.game_data.search_cards("us", "en_US")
|
|
35
|
+
card = api.hearthstone.game_data.get_card("us", "en_US", "test-card")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Attributes:
|
|
39
|
+
_client_id: The Blizzard API client ID.
|
|
40
|
+
_client_secret: The Blizzard API client secret.
|
|
41
|
+
game_data: The Hearthstone game-data API client.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, client_id: str, client_secret: str) -> None:
|
|
45
|
+
"""Initialize the API client.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
client_id: The Blizzard API client ID.
|
|
49
|
+
client_secret: The Blizzard API client secret.
|
|
50
|
+
"""
|
|
51
|
+
super().__init__(client_id, client_secret)
|
|
52
|
+
self.game_data = HearthstoneGameDataApi(client_id, client_secret)
|
{blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/hearthstone/hearthstone_game_data_api.py
RENAMED
|
@@ -24,7 +24,11 @@ class HearthstoneGameDataApi(BaseApi):
|
|
|
24
24
|
super().__init__(client_id, client_secret)
|
|
25
25
|
|
|
26
26
|
def search_cards(
|
|
27
|
-
self,
|
|
27
|
+
self,
|
|
28
|
+
region: str,
|
|
29
|
+
locale: str,
|
|
30
|
+
card_class: str | None = None,
|
|
31
|
+
**query_params: Any,
|
|
28
32
|
) -> dict[str, Any]:
|
|
29
33
|
"""
|
|
30
34
|
Return an up-to-date list of all cards matching the search criteria.
|
|
@@ -115,7 +119,7 @@ class HearthstoneGameDataApi(BaseApi):
|
|
|
115
119
|
Dict[str, Any]: A dictionary containing the deck details.
|
|
116
120
|
"""
|
|
117
121
|
resource = "/hearthstone/deck"
|
|
118
|
-
query_params = {"locale": locale}
|
|
122
|
+
query_params = {**query_params, "locale": locale}
|
|
119
123
|
return super().get_resource(resource, region, query_params)
|
|
120
124
|
|
|
121
125
|
def get_metadata(self, region: str, locale: str) -> dict[str, Any]:
|
{blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_community_api.py
RENAMED
|
@@ -151,7 +151,7 @@ class Starcraft2CommunityApi(BaseApi):
|
|
|
151
151
|
Returns:
|
|
152
152
|
Dict[str, Any]: A dictionary containing the grandmaster leaderboard data.
|
|
153
153
|
"""
|
|
154
|
-
resource = f"/sc2/ladder/grandmaster{region_id}"
|
|
154
|
+
resource = f"/sc2/ladder/grandmaster/{region_id}"
|
|
155
155
|
query_params = {"locale": locale}
|
|
156
156
|
return super().get_resource(resource, region, query_params)
|
|
157
157
|
|
|
@@ -43,7 +43,7 @@ class WowProfileApi(BaseApi):
|
|
|
43
43
|
"locale": locale,
|
|
44
44
|
"access_token": access_token,
|
|
45
45
|
}
|
|
46
|
-
return super().
|
|
46
|
+
return super().get_resource(resource, region, query_params)
|
|
47
47
|
|
|
48
48
|
def get_protected_character_profile_summary(
|
|
49
49
|
self,
|
|
@@ -324,3 +324,62 @@ def test_get_oauth_resource_end_to_end(api: BaseApi, mock_get, mock_post) -> Non
|
|
|
324
324
|
# Token in header, NOT in params.
|
|
325
325
|
assert "access_token" not in mock_get.call_args.kwargs["params"]
|
|
326
326
|
assert mock_get.call_args.kwargs["headers"]["Authorization"] == "Bearer user_token"
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
# ---------------------------------------------------------------------------
|
|
330
|
+
# HTTP timeout (issue #39)
|
|
331
|
+
# ---------------------------------------------------------------------------
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def test_make_request_passes_get_timeout(api: BaseApi, mock_get) -> None:
|
|
335
|
+
"""Every API GET must include `timeout=` to prevent indefinite hangs."""
|
|
336
|
+
prime_token(api)
|
|
337
|
+
api._make_request("https://us.api.blizzard.com/data/wow/realm/index", "us")
|
|
338
|
+
assert mock_get.call_args.kwargs.get("timeout") == BaseApi.DEFAULT_GET_TIMEOUT
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def test_get_client_token_passes_post_timeout(api: BaseApi, mock_post) -> None:
|
|
342
|
+
"""Token POST must include `timeout=`."""
|
|
343
|
+
api._get_client_token("us")
|
|
344
|
+
assert mock_post.call_args.kwargs.get("timeout") == BaseApi.DEFAULT_POST_TIMEOUT
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def test_401_retry_get_also_passes_timeout(api: BaseApi, mock_get, mock_post) -> None:
|
|
348
|
+
"""The retry GET in the 401-refresh path must also carry a timeout."""
|
|
349
|
+
prime_token(api, token="stale")
|
|
350
|
+
|
|
351
|
+
stale = mock_get.return_value
|
|
352
|
+
stale.status_code = 401
|
|
353
|
+
|
|
354
|
+
fresh = type(stale)()
|
|
355
|
+
fresh.status_code = 200
|
|
356
|
+
fresh.json = lambda: {"ok": True}
|
|
357
|
+
|
|
358
|
+
mock_get.side_effect = [stale, fresh]
|
|
359
|
+
mock_post.return_value.json.return_value = {
|
|
360
|
+
"access_token": "fresh",
|
|
361
|
+
"expires_in": 86400,
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
api._make_request("https://us.api.blizzard.com/x", "us")
|
|
365
|
+
|
|
366
|
+
assert mock_get.call_count == 2
|
|
367
|
+
assert (
|
|
368
|
+
mock_get.call_args_list[0].kwargs.get("timeout") == BaseApi.DEFAULT_GET_TIMEOUT
|
|
369
|
+
)
|
|
370
|
+
assert (
|
|
371
|
+
mock_get.call_args_list[1].kwargs.get("timeout") == BaseApi.DEFAULT_GET_TIMEOUT
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def test_subclass_can_override_default_timeout(mock_get, fake_credentials) -> None:
|
|
376
|
+
"""Subclasses override DEFAULT_*_TIMEOUT to customize per-instance."""
|
|
377
|
+
|
|
378
|
+
class FastApi(BaseApi):
|
|
379
|
+
DEFAULT_GET_TIMEOUT = 5.0
|
|
380
|
+
|
|
381
|
+
client_id, client_secret = fake_credentials
|
|
382
|
+
api = FastApi(client_id, client_secret)
|
|
383
|
+
prime_token(api)
|
|
384
|
+
api._make_request("https://us.api.blizzard.com/x", "us")
|
|
385
|
+
assert mock_get.call_args.kwargs["timeout"] == 5.0
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"""Tests for the Hearthstone APIs.
|
|
2
2
|
|
|
3
3
|
These tests verify URL construction, query-parameter shape, and return-value
|
|
4
|
-
passthrough
|
|
5
|
-
``BlizzardApi.hearthstone``) and ``
|
|
4
|
+
passthrough through ``HearthstoneApi`` (the facade exposed on
|
|
5
|
+
``BlizzardApi.hearthstone``) and its ``game_data`` sub-client. All HTTP is
|
|
6
6
|
patched at the ``requests.Session`` boundary via the ``mock_get`` fixture.
|
|
7
7
|
"""
|
|
8
8
|
|
|
@@ -28,13 +28,27 @@ def test_blizzard_api_exposes_hearthstone_facade(fake_credentials):
|
|
|
28
28
|
assert api.hearthstone._client_secret == client_secret
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
def
|
|
32
|
-
"""``
|
|
31
|
+
def test_hearthstone_facade_exposes_game_data(fake_credentials):
|
|
32
|
+
"""``HearthstoneApi.game_data`` should be a ``HearthstoneGameDataApi``.
|
|
33
|
+
|
|
34
|
+
Issue #42: the game-data client used to be orphaned (not reachable from
|
|
35
|
+
``BlizzardApi``). It is now exposed under ``.game_data`` for consistency
|
|
36
|
+
with ``wow.game_data``, ``diablo3.game_data``, ``starcraft2.game_data``.
|
|
37
|
+
"""
|
|
33
38
|
client_id, client_secret = fake_credentials
|
|
34
39
|
api = HearthstoneApi(client_id, client_secret)
|
|
35
|
-
|
|
40
|
+
assert isinstance(api.game_data, HearthstoneGameDataApi)
|
|
41
|
+
assert api.game_data._client_id == client_id
|
|
42
|
+
assert api.game_data._client_secret == client_secret
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_search_cards_no_filters_builds_bare_cards_url(fake_credentials, mock_get):
|
|
46
|
+
"""``search_cards`` with no filters hits ``/hearthstone/cards`` with locale only."""
|
|
47
|
+
client_id, client_secret = fake_credentials
|
|
48
|
+
api = HearthstoneApi(client_id, client_secret)
|
|
49
|
+
prime_token(api.game_data)
|
|
36
50
|
|
|
37
|
-
api.
|
|
51
|
+
api.game_data.search_cards("us", "en_US")
|
|
38
52
|
|
|
39
53
|
mock_get.assert_called_once()
|
|
40
54
|
args, kwargs = mock_get.call_args
|
|
@@ -42,43 +56,43 @@ def test_get_cards_builds_us_url_with_locale(fake_credentials, mock_get):
|
|
|
42
56
|
assert kwargs["params"] == {"locale": "en_US"}
|
|
43
57
|
|
|
44
58
|
|
|
45
|
-
def
|
|
46
|
-
"""``get_card`` interpolates the
|
|
59
|
+
def test_get_card_includes_id_in_path_via_game_data(fake_credentials, mock_get):
|
|
60
|
+
"""``game_data.get_card`` interpolates the id/slug into the URL path."""
|
|
47
61
|
client_id, client_secret = fake_credentials
|
|
48
62
|
api = HearthstoneApi(client_id, client_secret)
|
|
49
|
-
prime_token(api)
|
|
63
|
+
prime_token(api.game_data)
|
|
50
64
|
|
|
51
|
-
api.get_card("eu", "en_GB", "52119-arch-villain-rafaam")
|
|
65
|
+
api.game_data.get_card("eu", "en_GB", "52119-arch-villain-rafaam")
|
|
52
66
|
|
|
53
67
|
args, kwargs = mock_get.call_args
|
|
54
68
|
assert (
|
|
55
69
|
args[0]
|
|
56
70
|
== "https://eu.api.blizzard.com/hearthstone/cards/52119-arch-villain-rafaam"
|
|
57
71
|
)
|
|
58
|
-
assert kwargs["params"] == {"locale": "en_GB"}
|
|
72
|
+
assert kwargs["params"] == {"locale": "en_GB", "game_mode": "constructed"}
|
|
59
73
|
|
|
60
74
|
|
|
61
|
-
def
|
|
75
|
+
def test_search_cards_returns_mocked_payload(fake_credentials, mock_get):
|
|
62
76
|
"""The dict returned by the client should be exactly what ``json()`` returned."""
|
|
63
77
|
payload = {"cards": [{"id": 1, "name": "Test Card"}], "cardCount": 1}
|
|
64
78
|
mock_get.return_value.json.return_value = payload
|
|
65
79
|
|
|
66
80
|
client_id, client_secret = fake_credentials
|
|
67
81
|
api = HearthstoneApi(client_id, client_secret)
|
|
68
|
-
prime_token(api)
|
|
82
|
+
prime_token(api.game_data)
|
|
69
83
|
|
|
70
|
-
result = api.
|
|
84
|
+
result = api.game_data.search_cards("us", "en_US")
|
|
71
85
|
|
|
72
86
|
assert result == payload
|
|
73
87
|
|
|
74
88
|
|
|
75
|
-
def
|
|
89
|
+
def test_search_card_backs_uses_cn_gateway(fake_credentials, mock_get):
|
|
76
90
|
"""CN region must route to the Chinese gateway, not a regional subdomain."""
|
|
77
91
|
client_id, client_secret = fake_credentials
|
|
78
92
|
api = HearthstoneApi(client_id, client_secret)
|
|
79
|
-
prime_token(api)
|
|
93
|
+
prime_token(api.game_data)
|
|
80
94
|
|
|
81
|
-
api.
|
|
95
|
+
api.game_data.search_card_backs("cn", "zh_CN")
|
|
82
96
|
|
|
83
97
|
args, kwargs = mock_get.call_args
|
|
84
98
|
assert args[0] == "https://gateway.battlenet.com.cn/hearthstone/cardbacks"
|
|
@@ -149,3 +163,29 @@ def test_get_metadata_type_path_includes_type_id(fake_credentials, mock_get):
|
|
|
149
163
|
args, kwargs = mock_get.call_args
|
|
150
164
|
assert args[0] == "https://kr.api.blizzard.com/hearthstone/metadata/sets"
|
|
151
165
|
assert kwargs["params"] == {"locale": "ko_KR"}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def test_get_deck_preserves_caller_filters(fake_credentials, mock_get):
|
|
169
|
+
"""``get_deck`` must forward caller-supplied filters (issue #41).
|
|
170
|
+
|
|
171
|
+
The previous implementation silently dropped every kwarg by overwriting
|
|
172
|
+
`query_params = {"locale": locale}` after the **kwargs collection.
|
|
173
|
+
"""
|
|
174
|
+
client_id, client_secret = fake_credentials
|
|
175
|
+
api = HearthstoneGameDataApi(client_id, client_secret)
|
|
176
|
+
prime_token(api)
|
|
177
|
+
|
|
178
|
+
api.get_deck(
|
|
179
|
+
"us",
|
|
180
|
+
"en_US",
|
|
181
|
+
ids="EX1_046,EX1_054",
|
|
182
|
+
hero="HERO_01",
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
args, kwargs = mock_get.call_args
|
|
186
|
+
assert args[0] == "https://us.api.blizzard.com/hearthstone/deck"
|
|
187
|
+
assert kwargs["params"] == {
|
|
188
|
+
"locale": "en_US",
|
|
189
|
+
"ids": "EX1_046,EX1_054",
|
|
190
|
+
"hero": "HERO_01",
|
|
191
|
+
}
|
|
@@ -107,7 +107,7 @@ def test_community_get_ladder_summary_returns_mocked_payload(
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
def test_community_get_grandmaster_leaderboard_url_shape(fake_credentials, mock_get):
|
|
110
|
-
"""
|
|
110
|
+
"""Region id sits at /sc2/ladder/grandmaster/{region_id}, not concatenated."""
|
|
111
111
|
client_id, client_secret = fake_credentials
|
|
112
112
|
api = Starcraft2Api(client_id, client_secret)
|
|
113
113
|
prime_token(api.community)
|
|
@@ -115,8 +115,7 @@ def test_community_get_grandmaster_leaderboard_url_shape(fake_credentials, mock_
|
|
|
115
115
|
api.community.get_grandmaster_leaderboard(region="us", locale="en_US", region_id=1)
|
|
116
116
|
|
|
117
117
|
args, kwargs = mock_get.call_args
|
|
118
|
-
|
|
119
|
-
assert args[0] == "https://us.api.blizzard.com/sc2/ladder/grandmaster1"
|
|
118
|
+
assert args[0] == "https://us.api.blizzard.com/sc2/ladder/grandmaster/1"
|
|
120
119
|
assert kwargs["params"] == {"locale": "en_US"}
|
|
121
120
|
|
|
122
121
|
|
|
@@ -181,9 +181,9 @@ def test_oauth_token_goes_to_header_not_query(wow_api: WowApi, mock_get) -> None
|
|
|
181
181
|
)
|
|
182
182
|
|
|
183
183
|
args, kwargs = mock_get.call_args
|
|
184
|
-
#
|
|
185
|
-
#
|
|
186
|
-
assert args[0] == "https://
|
|
184
|
+
# /profile/user/wow lives on the regional API host, not oauth.battle.net
|
|
185
|
+
# — the OAuth host only serves /oauth/* endpoints.
|
|
186
|
+
assert args[0] == "https://us.api.blizzard.com/profile/user/wow"
|
|
187
187
|
# Token in header, with Bearer prefix, using the *user* token (not the
|
|
188
188
|
# primed client-credentials token).
|
|
189
189
|
assert kwargs["headers"] == {"Authorization": f"Bearer {user_token}"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"""Hearthstone API client.
|
|
2
|
-
|
|
3
|
-
This module provides access to Hearthstone game data through the Blizzard API,
|
|
4
|
-
including cards, card backs, and metadata.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from typing import Any, Dict
|
|
8
|
-
|
|
9
|
-
from ..api import BaseApi
|
|
10
|
-
from ..types import Locale, Region
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class ApiResponse:
|
|
14
|
-
"""Wrapper for API responses with metadata."""
|
|
15
|
-
|
|
16
|
-
data: Dict[str, Any]
|
|
17
|
-
region: Region
|
|
18
|
-
locale: Locale
|
|
19
|
-
namespace: str
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class HearthstoneApi(BaseApi):
|
|
23
|
-
"""Hearthstone API client.
|
|
24
|
-
|
|
25
|
-
This class provides access to Hearthstone game data through the Blizzard API,
|
|
26
|
-
including cards, card backs, and metadata.
|
|
27
|
-
|
|
28
|
-
Example:
|
|
29
|
-
```python
|
|
30
|
-
api = HearthstoneApi(client_id="your_id", client_secret="your_secret")
|
|
31
|
-
cards = api.get_cards("us", "en_US")
|
|
32
|
-
card = api.get_card("us", "en_US", "test-card")
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Attributes:
|
|
36
|
-
_client_id: The Blizzard API client ID.
|
|
37
|
-
_client_secret: The Blizzard API client secret.
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
def __init__(self, client_id: str, client_secret: str) -> None:
|
|
41
|
-
"""Initialize the API client.
|
|
42
|
-
|
|
43
|
-
Args:
|
|
44
|
-
client_id: The Blizzard API client ID.
|
|
45
|
-
client_secret: The Blizzard API client secret.
|
|
46
|
-
"""
|
|
47
|
-
super().__init__(client_id, client_secret)
|
|
48
|
-
|
|
49
|
-
def get_cards(self, region: Region, locale: Locale) -> Dict[str, Any]:
|
|
50
|
-
"""Get all cards.
|
|
51
|
-
|
|
52
|
-
Args:
|
|
53
|
-
region: The region to query (e.g., "us", "eu").
|
|
54
|
-
locale: The locale to use for the response (e.g., "en_US").
|
|
55
|
-
|
|
56
|
-
Returns:
|
|
57
|
-
A dictionary containing all cards.
|
|
58
|
-
|
|
59
|
-
Raises:
|
|
60
|
-
ApiError: If the API request fails.
|
|
61
|
-
"""
|
|
62
|
-
resource = "/hearthstone/cards"
|
|
63
|
-
query_params = {"locale": locale}
|
|
64
|
-
return self.get_resource(resource, region, query_params)
|
|
65
|
-
|
|
66
|
-
def get_card_backs(self, region: Region, locale: Locale) -> Dict[str, Any]:
|
|
67
|
-
"""Get all card backs.
|
|
68
|
-
|
|
69
|
-
Args:
|
|
70
|
-
region: The region to query (e.g., "us", "eu").
|
|
71
|
-
locale: The locale to use for the response (e.g., "en_US").
|
|
72
|
-
|
|
73
|
-
Returns:
|
|
74
|
-
A dictionary containing all card backs.
|
|
75
|
-
|
|
76
|
-
Raises:
|
|
77
|
-
ApiError: If the API request fails.
|
|
78
|
-
"""
|
|
79
|
-
resource = "/hearthstone/cardbacks"
|
|
80
|
-
query_params = {"locale": locale}
|
|
81
|
-
return self.get_resource(resource, region, query_params)
|
|
82
|
-
|
|
83
|
-
def get_metadata(self, region: Region, locale: Locale) -> Dict[str, Any]:
|
|
84
|
-
"""Get metadata.
|
|
85
|
-
|
|
86
|
-
Args:
|
|
87
|
-
region: The region to query (e.g., "us", "eu").
|
|
88
|
-
locale: The locale to use for the response (e.g., "en_US").
|
|
89
|
-
|
|
90
|
-
Returns:
|
|
91
|
-
A dictionary containing metadata.
|
|
92
|
-
|
|
93
|
-
Raises:
|
|
94
|
-
ApiError: If the API request fails.
|
|
95
|
-
"""
|
|
96
|
-
resource = "/hearthstone/metadata"
|
|
97
|
-
query_params = {"locale": locale}
|
|
98
|
-
return self.get_resource(resource, region, query_params)
|
|
99
|
-
|
|
100
|
-
def get_card(self, region: Region, locale: Locale, card_id: str) -> Dict[str, Any]:
|
|
101
|
-
"""Get a single card.
|
|
102
|
-
|
|
103
|
-
Args:
|
|
104
|
-
region: The region to query (e.g., "us", "eu").
|
|
105
|
-
locale: The locale to use for the response (e.g., "en_US").
|
|
106
|
-
card_id: The ID of the card to retrieve.
|
|
107
|
-
|
|
108
|
-
Returns:
|
|
109
|
-
A dictionary containing the card details.
|
|
110
|
-
|
|
111
|
-
Raises:
|
|
112
|
-
ApiError: If the API request fails.
|
|
113
|
-
"""
|
|
114
|
-
resource = f"/hearthstone/cards/{card_id}"
|
|
115
|
-
query_params = {"locale": locale}
|
|
116
|
-
return self.get_resource(resource, region, query_params)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{blizzardapi2-2.1.20 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_game_data_api.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|