blizzardapi2 2.1.19__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.19 → blizzardapi2-2.1.21}/.github/workflows/black-check.yml +1 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.github/workflows/python-package.yml +30 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.pre-commit-config.yaml +1 -1
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.release-it.json +1 -1
- blizzardapi2-2.1.21/CLAUDE.md +69 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/CONTRIBUTING.md +2 -2
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/PKG-INFO +2 -2
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/api.py +9 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/battlenet/battlenet_api.py +1 -3
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/battlenet/battlenet_oauth_api.py +6 -3
- {blizzardapi2-2.1.19 → 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.19 → blizzardapi2-2.1.21}/blizzardapi2/hearthstone/hearthstone_game_data_api.py +6 -2
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_community_api.py +1 -1
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/wow/wow_profile_api.py +1 -1
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/PKG-INFO +2 -2
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/SOURCES.txt +10 -1
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/requires.txt +1 -1
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/package.json +1 -1
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/pyproject.toml +8 -4
- blizzardapi2-2.1.21/tests/__init__.py +0 -0
- blizzardapi2-2.1.21/tests/conftest.py +64 -0
- blizzardapi2-2.1.21/tests/test_base_api.py +385 -0
- blizzardapi2-2.1.21/tests/test_battlenet.py +152 -0
- blizzardapi2-2.1.21/tests/test_diablo3.py +207 -0
- blizzardapi2-2.1.21/tests/test_hearthstone.py +191 -0
- blizzardapi2-2.1.21/tests/test_starcraft2.py +167 -0
- blizzardapi2-2.1.21/tests/test_wow.py +274 -0
- blizzardapi2-2.1.19/blizzardapi2/hearthstone/hearthstone_api.py +0 -116
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.github/dependabot.yml +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.github/workflows/README.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/.gitignore +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/CODE_OF_CONDUCT.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/LICENSE +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/README.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/SECURITY.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/__init__.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/battlenet/__init__.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/blizzard_api.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/diablo3/__init__.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/diablo3/diablo3_api.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/diablo3/diablo3_game_data_api.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/hearthstone/__init__.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/__init__.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_api.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/starcraft2/starcraft2_game_data_api.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/types.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/wow/__init__.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/wow/wow_api.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2/wow/wow_game_data_api.py +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/dependency_links.txt +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/blizzardapi2.egg-info/top_level.txt +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/docs/battlenet/README.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/docs/diablo3/README.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/docs/hearthstone/README.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/docs/pull_request_template.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/docs/starcraft2/README.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/docs/wow/README.md +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/poetry.lock +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/setup.cfg +0 -0
- {blizzardapi2-2.1.19 → blizzardapi2-2.1.21}/uv.lock +0 -0
|
@@ -6,6 +6,8 @@ name: Python package
|
|
|
6
6
|
on:
|
|
7
7
|
push:
|
|
8
8
|
branches: ["main"]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: ["main"]
|
|
9
11
|
|
|
10
12
|
# Add permissions block
|
|
11
13
|
permissions:
|
|
@@ -14,7 +16,35 @@ permissions:
|
|
|
14
16
|
id-token: write
|
|
15
17
|
|
|
16
18
|
jobs:
|
|
19
|
+
test:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
strategy:
|
|
22
|
+
fail-fast: false
|
|
23
|
+
matrix:
|
|
24
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
|
|
28
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
29
|
+
uses: actions/setup-python@v5
|
|
30
|
+
with:
|
|
31
|
+
python-version: ${{ matrix.python-version }}
|
|
32
|
+
|
|
33
|
+
- name: Install uv
|
|
34
|
+
run: |
|
|
35
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
36
|
+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
|
37
|
+
|
|
38
|
+
- name: Create venv and install dev deps
|
|
39
|
+
run: |
|
|
40
|
+
uv venv
|
|
41
|
+
uv pip install -e ".[dev]"
|
|
42
|
+
|
|
43
|
+
- name: Run tests
|
|
44
|
+
run: uv run pytest tests/ -v
|
|
45
|
+
|
|
17
46
|
publish:
|
|
47
|
+
needs: test
|
|
18
48
|
if: github.ref == 'refs/heads/main'
|
|
19
49
|
runs-on: ubuntu-latest
|
|
20
50
|
steps:
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project
|
|
6
|
+
|
|
7
|
+
`blizzardapi2` is a published PyPI package (synchronous client wrapper around Blizzard's Battle.net APIs). Public API surface is `from blizzardapi2 import BlizzardApi`. Treat the package boundary as load-bearing — every name, parameter shape, and return type is part of the contract for external users.
|
|
8
|
+
|
|
9
|
+
Python 3.11+ only. Uses `requests` synchronously today; `aiohttp` and `pydantic` are declared dependencies but not yet integrated into the public surface.
|
|
10
|
+
|
|
11
|
+
## Common commands
|
|
12
|
+
|
|
13
|
+
Use `uv` for environment management (matches CI):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv venv
|
|
17
|
+
uv pip install -e ".[dev]"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Lint / format:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
ruff check . # lint (line-length 120, see caveat below)
|
|
24
|
+
ruff format . # format
|
|
25
|
+
black . # pre-commit also runs black with --line-length=88 (mismatch — see below)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Tests: **there is no `test_project/` directory in the repo despite CONTRIBUTING.md referencing it**, and no test job in CI. If you add tests, use `pytest` / `pytest-mock` / `pytest-asyncio` (already in `[dev]`) and configure a workflow.
|
|
29
|
+
|
|
30
|
+
Release: do not bump versions by hand. Pushing to `main` triggers `.github/workflows/python-package.yml`, which builds, publishes to PyPI, then runs `release-it` to tag and create a GitHub release. `release-it`'s `after:bump` hook `sed`s `pyproject.toml`'s `version = "..."`.
|
|
31
|
+
|
|
32
|
+
## Architecture
|
|
33
|
+
|
|
34
|
+
Single base class + one facade per game, each game facade composing sub-APIs:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
BlizzardApi (blizzard_api.py)
|
|
38
|
+
├── wow → WowApi → { game_data: WowGameDataApi, profile: WowProfileApi }
|
|
39
|
+
├── diablo3 → Diablo3Api → { community, game_data }
|
|
40
|
+
├── hearthstone, starcraft2, battlenet → similar pattern
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
All API classes inherit `BaseApi` (`api.py`). New endpoint methods are thin wrappers: build a `resource` path + `query_params` dict (typically `{"namespace": f"static-{region}", "locale": locale}`), then call `super().get_resource(...)` or `super().get_oauth_resource(...)`. Patterns are most clearly visible in `wow/wow_game_data_api.py`.
|
|
44
|
+
|
|
45
|
+
### Token handling — the non-obvious part
|
|
46
|
+
|
|
47
|
+
`BaseApi._make_request` has a deliberate indirection: callers pass user OAuth tokens **inside `query_params` under the key `"access_token"`**. `_make_request` `.pop()`s that key and moves the value into the `Authorization: Bearer <token>` header. This keeps tokens out of URL query strings (visible in logs/proxies). Preserve this when adding OAuth-protected endpoints — see `battlenet/battlenet_oauth_api.py:get_user_info` for the canonical shape. Don't add a separate `access_token` keyword argument to `_make_request`; the pop-from-params pattern is the contract.
|
|
48
|
+
|
|
49
|
+
Client-credentials tokens are managed automatically: `_ensure_valid_token` lazily fetches and caches them, with a 5-minute refresh buffer (`TOKEN_REFRESH_BUFFER`). On a 401 with a client-credentials token, `_make_request` refreshes and retries once. User-supplied OAuth tokens are never refreshed by the library.
|
|
50
|
+
|
|
51
|
+
### Region URL routing
|
|
52
|
+
|
|
53
|
+
`BaseApi.OAUTH_URLS` and `API_URLS` route China (`"cn"`) to `*.battlenet.com.cn` hosts, all other regions to `oauth.battle.net` and `{region}.api.blizzard.com`. Always use `_build_oauth_url` / `_build_api_url` rather than f-stringing URLs by hand.
|
|
54
|
+
|
|
55
|
+
### Independent token caches per sub-API
|
|
56
|
+
|
|
57
|
+
Each game's facade instantiates its sub-APIs with `client_id`/`client_secret`, so `WowGameDataApi`, `WowProfileApi`, `Diablo3CommunityApi`, etc. each maintain their **own** `_session` and `_access_token`. There is no shared token cache across sub-APIs. This is fine for the current API surface but worth knowing if you're debugging unexpected token-fetch behavior.
|
|
58
|
+
|
|
59
|
+
### `Region` / `Locale` enums
|
|
60
|
+
|
|
61
|
+
`types.py` defines `Region` and `Locale` as `str` enums. Most current endpoint methods are typed as `region: str, locale: str` and accept either bare strings or enum members (since enums subclass `str`). Newer code (e.g., `BattlenetOAuthApi`) uses the enums in signatures — prefer that for new code.
|
|
62
|
+
|
|
63
|
+
## Conventions and gotchas
|
|
64
|
+
|
|
65
|
+
- **`blizzardapi2/_version.py` is auto-generated** by `setuptools_scm` (`write_to` configured in `pyproject.toml`). Never edit by hand; don't import it as authoritative — `pyproject.toml`'s `version` is what `release-it` mutates.
|
|
66
|
+
- **`tool.ruff.target-version` in `pyproject.toml` is currently `"2.1.18"`** (the package version). The release-it `sed` hook replaces every `version = "..."` line and clobbers it. If you touch ruff config, restore this to `"py311"` and consider tightening the sed to `^version =` to prevent recurrence.
|
|
67
|
+
- **Black line-length mismatch:** pre-commit runs `black --line-length=88`, but `tool.ruff.line-length = 120`. Don't reformat existing files just to "fix" this — it'll churn diffs. Match surrounding style.
|
|
68
|
+
- Inherit from `Api`/`BaseApi` (not `BaseApi` plus a separate base) — see CONTRIBUTING.md "Import Fixes" section.
|
|
69
|
+
- Commit style is conventional commits (`feat:`, `fix:`, `chore:`, etc.) — release notes are auto-generated from them.
|
|
@@ -131,7 +131,7 @@ Use conventional commit messages:
|
|
|
131
131
|
pytest
|
|
132
132
|
|
|
133
133
|
# Run specific test file
|
|
134
|
-
pytest
|
|
134
|
+
pytest tests/test_wow.py
|
|
135
135
|
|
|
136
136
|
# Run with verbose output
|
|
137
137
|
pytest -v
|
|
@@ -139,7 +139,7 @@ pytest -v
|
|
|
139
139
|
|
|
140
140
|
### Writing Tests
|
|
141
141
|
|
|
142
|
-
- Place tests in the `
|
|
142
|
+
- Place tests in the `tests/` directory
|
|
143
143
|
- Use descriptive test names
|
|
144
144
|
- Include both positive and negative test cases
|
|
145
145
|
- Mock external API calls
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: blizzardapi2
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.21
|
|
4
4
|
Summary: A Python wrapper for Blizzard API
|
|
5
5
|
Author-email: lostcol0ny <c098os0k@4wrd.cc>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -17,7 +17,7 @@ Provides-Extra: dev
|
|
|
17
17
|
Requires-Dist: pytest<10.0.0,>=8.2.2; extra == "dev"
|
|
18
18
|
Requires-Dist: pytest-mock<4.0.0,>=3.14.0; extra == "dev"
|
|
19
19
|
Requires-Dist: pytest-asyncio<2.0.0,>=0.23.5; extra == "dev"
|
|
20
|
-
Requires-Dist: black<27.0.0,>=
|
|
20
|
+
Requires-Dist: black<27.0.0,>=26.3.1; extra == "dev"
|
|
21
21
|
Requires-Dist: ruff<1.0.0,>=0.3.0; extra == "dev"
|
|
22
22
|
Dynamic: license-file
|
|
23
23
|
|
|
@@ -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.19 → 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.19 → 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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: blizzardapi2
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.21
|
|
4
4
|
Summary: A Python wrapper for Blizzard API
|
|
5
5
|
Author-email: lostcol0ny <c098os0k@4wrd.cc>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -17,7 +17,7 @@ Provides-Extra: dev
|
|
|
17
17
|
Requires-Dist: pytest<10.0.0,>=8.2.2; extra == "dev"
|
|
18
18
|
Requires-Dist: pytest-mock<4.0.0,>=3.14.0; extra == "dev"
|
|
19
19
|
Requires-Dist: pytest-asyncio<2.0.0,>=0.23.5; extra == "dev"
|
|
20
|
-
Requires-Dist: black<27.0.0,>=
|
|
20
|
+
Requires-Dist: black<27.0.0,>=26.3.1; extra == "dev"
|
|
21
21
|
Requires-Dist: ruff<1.0.0,>=0.3.0; extra == "dev"
|
|
22
22
|
Dynamic: license-file
|
|
23
23
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
.gitignore
|
|
2
2
|
.pre-commit-config.yaml
|
|
3
3
|
.release-it.json
|
|
4
|
+
CLAUDE.md
|
|
4
5
|
CODE_OF_CONDUCT.md
|
|
5
6
|
CONTRIBUTING.md
|
|
6
7
|
LICENSE
|
|
@@ -48,4 +49,12 @@ docs/battlenet/README.md
|
|
|
48
49
|
docs/diablo3/README.md
|
|
49
50
|
docs/hearthstone/README.md
|
|
50
51
|
docs/starcraft2/README.md
|
|
51
|
-
docs/wow/README.md
|
|
52
|
+
docs/wow/README.md
|
|
53
|
+
tests/__init__.py
|
|
54
|
+
tests/conftest.py
|
|
55
|
+
tests/test_base_api.py
|
|
56
|
+
tests/test_battlenet.py
|
|
57
|
+
tests/test_diablo3.py
|
|
58
|
+
tests/test_hearthstone.py
|
|
59
|
+
tests/test_starcraft2.py
|
|
60
|
+
tests/test_wow.py
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "blizzardapi2"
|
|
3
|
-
version = "2.1.
|
|
3
|
+
version = "2.1.21"
|
|
4
4
|
description = "A Python wrapper for Blizzard API"
|
|
5
5
|
authors = [{ name = "lostcol0ny", email = "c098os0k@4wrd.cc" }]
|
|
6
6
|
license = "MIT"
|
|
@@ -29,12 +29,16 @@ include = ["blizzardapi2*"]
|
|
|
29
29
|
write_to = "blizzardapi2/_version.py"
|
|
30
30
|
local_scheme = "node-and-timestamp"
|
|
31
31
|
|
|
32
|
+
[tool.pytest.ini_options]
|
|
33
|
+
testpaths = ["tests"]
|
|
34
|
+
pythonpath = ["."]
|
|
35
|
+
|
|
32
36
|
[project.optional-dependencies]
|
|
33
37
|
dev = [
|
|
34
38
|
"pytest>=8.2.2,<10.0.0",
|
|
35
39
|
"pytest-mock>=3.14.0,<4.0.0",
|
|
36
40
|
"pytest-asyncio>=0.23.5,<2.0.0",
|
|
37
|
-
"black>=
|
|
41
|
+
"black>=26.3.1,<27.0.0",
|
|
38
42
|
"ruff>=0.3.0,<1.0.0",
|
|
39
43
|
]
|
|
40
44
|
|
|
@@ -70,10 +74,10 @@ exclude = [
|
|
|
70
74
|
]
|
|
71
75
|
|
|
72
76
|
# Same as Black.
|
|
73
|
-
line-length =
|
|
77
|
+
line-length = 88
|
|
74
78
|
|
|
75
79
|
# Assume Python 3.11
|
|
76
|
-
target-version = "
|
|
80
|
+
target-version = "py311"
|
|
77
81
|
|
|
78
82
|
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
|
79
83
|
select = ["E4", "E7", "E9", "F"]
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Shared pytest fixtures for blizzardapi2 tests.
|
|
2
|
+
|
|
3
|
+
The Blizzard API client is a thin wrapper around `requests`. Tests verify URL
|
|
4
|
+
construction, query-parameter shape, and token handling — never live HTTP. All
|
|
5
|
+
network is patched at the `requests.Session` boundary.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from datetime import UTC, datetime, timedelta
|
|
11
|
+
from typing import Any
|
|
12
|
+
from unittest.mock import MagicMock
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
CLIENT_ID = "test_client_id"
|
|
17
|
+
CLIENT_SECRET = "test_client_secret"
|
|
18
|
+
FAKE_TOKEN = "fake_access_token"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.fixture
|
|
22
|
+
def fake_credentials() -> tuple[str, str]:
|
|
23
|
+
"""Stable (client_id, client_secret) pair for instantiating API clients."""
|
|
24
|
+
return CLIENT_ID, CLIENT_SECRET
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.fixture
|
|
28
|
+
def mock_get(mocker) -> MagicMock:
|
|
29
|
+
"""Patch `requests.Session.get` globally with a 200 + empty-dict response.
|
|
30
|
+
|
|
31
|
+
Tests typically inspect `mock_get.call_args` to assert URL, params, and
|
|
32
|
+
headers. Override `return_value.json.return_value` per-test for shaped data.
|
|
33
|
+
"""
|
|
34
|
+
mock = mocker.patch("requests.Session.get")
|
|
35
|
+
mock.return_value.status_code = 200
|
|
36
|
+
mock.return_value.json.return_value = {}
|
|
37
|
+
return mock
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.fixture
|
|
41
|
+
def mock_post(mocker) -> MagicMock:
|
|
42
|
+
"""Patch `requests.Session.post` to return a fake OAuth token response.
|
|
43
|
+
|
|
44
|
+
BaseApi calls POST only for `/oauth/token` (client-credentials flow).
|
|
45
|
+
"""
|
|
46
|
+
mock = mocker.patch("requests.Session.post")
|
|
47
|
+
mock.return_value.status_code = 200
|
|
48
|
+
mock.return_value.json.return_value = {
|
|
49
|
+
"access_token": FAKE_TOKEN,
|
|
50
|
+
"token_type": "bearer",
|
|
51
|
+
"expires_in": 86400,
|
|
52
|
+
}
|
|
53
|
+
return mock
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def prime_token(
|
|
57
|
+
api_instance: Any, token: str = FAKE_TOKEN, expires_in: int = 86400
|
|
58
|
+
) -> None:
|
|
59
|
+
"""Pre-populate an API instance with a non-expired client-credentials token.
|
|
60
|
+
|
|
61
|
+
Lets tests skip the token POST when they only care about the GET request.
|
|
62
|
+
"""
|
|
63
|
+
api_instance._access_token = token
|
|
64
|
+
api_instance._token_expires_at = datetime.now(UTC) + timedelta(seconds=expires_in)
|