blizzardapi2 2.1.1__tar.gz → 2.1.4__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.4/.github/workflows/black.yml +13 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/.github/workflows/python-package.yml +35 -7
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/PKG-INFO +14 -4
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/README.md +7 -2
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/_version.py +2 -2
- blizzardapi2-2.1.4/blizzardapi2/api.py +137 -0
- blizzardapi2-2.1.4/blizzardapi2/battlenet/battlenet_api.py +18 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/blizzard_api.py +9 -10
- blizzardapi2-2.1.4/blizzardapi2/diablo3/diablo3_community_api.py +261 -0
- blizzardapi2-2.1.4/blizzardapi2/diablo3/diablo3_game_data_api.py +106 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/hearthstone/hearthstone_api.py +9 -3
- blizzardapi2-2.1.4/blizzardapi2/hearthstone/hearthstone_game_data_api.py +146 -0
- blizzardapi2-2.1.4/blizzardapi2/starcraft2/starcraft2_api.py +18 -0
- blizzardapi2-2.1.4/blizzardapi2/starcraft2/starcraft2_community_api.py +186 -0
- blizzardapi2-2.1.4/blizzardapi2/starcraft2/starcraft2_game_data_api.py +43 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/types.py +4 -1
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/wow/wow_game_data_api.py +385 -555
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/wow/wow_profile_api.py +115 -169
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2.egg-info/PKG-INFO +14 -4
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2.egg-info/SOURCES.txt +3 -0
- blizzardapi2-2.1.4/package.json +27 -0
- blizzardapi2-2.1.4/poetry.lock +377 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/pyproject.toml +16 -7
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/uv.lock +27 -1
- blizzardapi2-2.1.1/blizzardapi2/api.py +0 -465
- blizzardapi2-2.1.1/blizzardapi2/battlenet/battlenet_api.py +0 -32
- blizzardapi2-2.1.1/blizzardapi2/diablo3/diablo3_community_api.py +0 -697
- blizzardapi2-2.1.1/blizzardapi2/diablo3/diablo3_game_data_api.py +0 -140
- blizzardapi2-2.1.1/blizzardapi2/hearthstone/hearthstone_game_data_api.py +0 -176
- blizzardapi2-2.1.1/blizzardapi2/starcraft2/starcraft2_api.py +0 -197
- blizzardapi2-2.1.1/blizzardapi2/starcraft2/starcraft2_community_api.py +0 -440
- blizzardapi2-2.1.1/blizzardapi2/starcraft2/starcraft2_game_data_api.py +0 -83
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/.github/dependabot.yml +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/.gitignore +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/CODE_OF_CONDUCT.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/CONTRIBUTING.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/LICENSE +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/SECURITY.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/__init__.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/battlenet/__init__.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/battlenet/battlenet_oauth_api.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/diablo3/__init__.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/diablo3/diablo3_api.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/hearthstone/__init__.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/starcraft2/__init__.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/wow/__init__.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2/wow/wow_api.py +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2.egg-info/dependency_links.txt +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2.egg-info/requires.txt +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/blizzardapi2.egg-info/top_level.txt +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/docs/battlenet/README.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/docs/diablo3/README.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/docs/hearthstone/README.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/docs/pull_request_template.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/docs/starcraft2/README.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/docs/wow/README.md +0 -0
- {blizzardapi2-2.1.1 → blizzardapi2-2.1.4}/setup.cfg +0 -0
|
@@ -6,11 +6,13 @@ name: Python package
|
|
|
6
6
|
on:
|
|
7
7
|
push:
|
|
8
8
|
branches: ["main"]
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
# Add permissions block
|
|
11
|
+
permissions:
|
|
12
|
+
contents: write
|
|
11
13
|
|
|
12
14
|
jobs:
|
|
13
|
-
|
|
15
|
+
checkout:
|
|
14
16
|
runs-on: ubuntu-latest
|
|
15
17
|
strategy:
|
|
16
18
|
fail-fast: false
|
|
@@ -20,7 +22,7 @@ jobs:
|
|
|
20
22
|
steps:
|
|
21
23
|
- uses: actions/checkout@v4
|
|
22
24
|
with:
|
|
23
|
-
fetch-depth: 0
|
|
25
|
+
fetch-depth: 0
|
|
24
26
|
|
|
25
27
|
- name: Set up Python ${{ matrix.python-version }}
|
|
26
28
|
uses: actions/setup-python@v5
|
|
@@ -41,7 +43,7 @@ jobs:
|
|
|
41
43
|
uv pip install -e ".[dev]"
|
|
42
44
|
|
|
43
45
|
publish:
|
|
44
|
-
needs:
|
|
46
|
+
needs: checkout
|
|
45
47
|
if: github.ref == 'refs/heads/main'
|
|
46
48
|
runs-on: ubuntu-latest
|
|
47
49
|
steps:
|
|
@@ -66,6 +68,10 @@ jobs:
|
|
|
66
68
|
- name: Install dependencies
|
|
67
69
|
run: |
|
|
68
70
|
uv pip install -e ".[dev]"
|
|
71
|
+
- name: Configure Git
|
|
72
|
+
run: |
|
|
73
|
+
git config --global user.name "lostcol0ny"
|
|
74
|
+
git config --global user.email "c098os0k@4wrd.cc"
|
|
69
75
|
|
|
70
76
|
- name: Build and publish to PyPI
|
|
71
77
|
run: |
|
|
@@ -75,9 +81,31 @@ jobs:
|
|
|
75
81
|
CURRENT_VERSION=$(grep 'version = ' pyproject.toml | cut -d'"' -f2)
|
|
76
82
|
# Split version into major.minor.patch
|
|
77
83
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
|
|
78
|
-
# Increment
|
|
79
|
-
NEW_VERSION="$MAJOR.$((
|
|
84
|
+
# Increment patch version
|
|
85
|
+
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
|
|
80
86
|
# Update version in pyproject.toml
|
|
81
87
|
sed -i "s/version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml
|
|
88
|
+
# Update version in package.json
|
|
89
|
+
sed -i "s/\"version\": \".*\"/\"version\": \"$NEW_VERSION\"/" package.json
|
|
90
|
+
# Commit the version changes
|
|
91
|
+
git add pyproject.toml package.json
|
|
92
|
+
git commit -m "chore: bump version to $NEW_VERSION"
|
|
93
|
+
git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
|
|
82
94
|
python -m build
|
|
83
95
|
twine upload dist/* --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
|
|
96
|
+
release:
|
|
97
|
+
needs: publish
|
|
98
|
+
runs-on: ubuntu-latest
|
|
99
|
+
steps:
|
|
100
|
+
- name: Checkout repository
|
|
101
|
+
uses: actions/checkout@v4
|
|
102
|
+
- name: Setup Node.js
|
|
103
|
+
uses: actions/setup-node@v4
|
|
104
|
+
with:
|
|
105
|
+
node-version: "18.x"
|
|
106
|
+
- name: Install npm dependencies
|
|
107
|
+
run: npm install
|
|
108
|
+
- name: Run release script
|
|
109
|
+
env:
|
|
110
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
111
|
+
run: npm run release
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: blizzardapi2
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
4
4
|
Summary: A Python wrapper for Blizzard API
|
|
5
5
|
Author-email: lostcol0ny <c098os0k@4wrd.cc>
|
|
6
|
-
License: MIT
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
7
12
|
Requires-Python: >=3.11
|
|
8
13
|
Description-Content-Type: text/markdown
|
|
9
14
|
License-File: LICENSE
|
|
@@ -22,9 +27,14 @@ Requires-Dist: black<25.0.0,>=24.4.2; extra == "dev"
|
|
|
22
27
|
Requires-Dist: ruff<1.0.0,>=0.3.0; extra == "dev"
|
|
23
28
|
Dynamic: license-file
|
|
24
29
|
|
|
25
|
-
#
|
|
30
|
+
# Blizzard API 2
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
[](https://badge.fury.io/py/blizzardapi2)
|
|
33
|
+
[](https://pypi.org/project/blizzardapi2/)
|
|
34
|
+
[](https://pypi.org/project/blizzardapi2/)
|
|
35
|
+
[](https://github.com/lostcol0ny/python-blizzardapi2/actions/workflows/python-package.yml)
|
|
36
|
+
|
|
37
|
+
[](https://github.com/lostcol0ny/blizzardapi2/actions/workflows/dependabot/dependabot-updates)[](https://github.com/lostcol0ny/python-blizzardapi2/actions/workflows/github-code-scanning/codeql)[](https://github.com/psf/black)
|
|
28
38
|
|
|
29
39
|
blizzardapi2 is a client library for Blizzard's APIs. It's a fork of [the original library](https://github.com/trevorphillipscoding/python-blizzardapi/).
|
|
30
40
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Blizzard API 2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/py/blizzardapi2)
|
|
4
|
+
[](https://pypi.org/project/blizzardapi2/)
|
|
5
|
+
[](https://pypi.org/project/blizzardapi2/)
|
|
6
|
+
[](https://github.com/lostcol0ny/python-blizzardapi2/actions/workflows/python-package.yml)
|
|
7
|
+
|
|
8
|
+
[](https://github.com/lostcol0ny/blizzardapi2/actions/workflows/dependabot/dependabot-updates)[](https://github.com/lostcol0ny/python-blizzardapi2/actions/workflows/github-code-scanning/codeql)[](https://github.com/psf/black)
|
|
4
9
|
|
|
5
10
|
blizzardapi2 is a client library for Blizzard's APIs. It's a fork of [the original library](https://github.com/trevorphillipscoding/python-blizzardapi/).
|
|
6
11
|
|
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '
|
|
21
|
-
__version_tuple__ = version_tuple = (
|
|
20
|
+
__version__ = version = '2.0.8.dev11+g2ee7425'
|
|
21
|
+
__version_tuple__ = version_tuple = (2, 0, 8, 'dev11', 'g2ee7425')
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""api.py file."""
|
|
2
|
+
|
|
3
|
+
from datetime import UTC, datetime, timedelta
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Api:
|
|
10
|
+
"""Base API class.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
_client_id: A string client id supplied by Blizzard.
|
|
14
|
+
_client_secret: A string client secret supplied by Blizzard.
|
|
15
|
+
_access_token: A string access token that is used to access Blizzard's API.
|
|
16
|
+
_api_url: A string url used to call the API endpoints.
|
|
17
|
+
_api_url_cn: A string url used to call the china API endpoints.
|
|
18
|
+
_oauth_url: A string url used to call the OAuth API endpoints.
|
|
19
|
+
_oauth_url_cn: A string url used to call the china OAuth API endpoints.
|
|
20
|
+
_session: An open requests.Session instance.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, client_id: str, client_secret: str) -> None:
|
|
24
|
+
"""Init Api."""
|
|
25
|
+
self._client_id: str = client_id
|
|
26
|
+
self._client_secret: str = client_secret
|
|
27
|
+
self._access_token: str = None
|
|
28
|
+
self._access_token_expiration_datetime: str = "2024-08-06T12:38:15.125Z"
|
|
29
|
+
|
|
30
|
+
self._api_url = "https://{0}.api.blizzard.com{1}"
|
|
31
|
+
self._api_url_cn = "https://gateway.battlenet.com.cn{0}"
|
|
32
|
+
|
|
33
|
+
self._oauth_url = "https://oauth.battle.net{1}"
|
|
34
|
+
self._oauth_url_cn = "https://www.gateway.battlenet.com.cn{0}"
|
|
35
|
+
|
|
36
|
+
self._session = requests.Session()
|
|
37
|
+
|
|
38
|
+
def _is_token_expired(self) -> bool:
|
|
39
|
+
"""Check if the token is expiring within next 5 minutes."""
|
|
40
|
+
current_time = datetime.now(UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
41
|
+
datetime_format = "%Y-%m-%dT%H:%M:%S.%fZ"
|
|
42
|
+
blizz_expire_obj = datetime.strptime(
|
|
43
|
+
self._access_token_expiration_datetime, datetime_format
|
|
44
|
+
)
|
|
45
|
+
current_datetime_obj = datetime.strptime(current_time, datetime_format)
|
|
46
|
+
|
|
47
|
+
time_difference = abs(blizz_expire_obj - current_datetime_obj)
|
|
48
|
+
|
|
49
|
+
return time_difference <= timedelta(minutes=5)
|
|
50
|
+
|
|
51
|
+
def _get_client_token(self, region: str) -> dict[str, Any]:
|
|
52
|
+
"""Fetch an access token based on client id and client secret credentials.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
region:
|
|
56
|
+
A string containing a region.
|
|
57
|
+
"""
|
|
58
|
+
url = self._format_oauth_url("/oauth/token", region)
|
|
59
|
+
query_params = {"grant_type": "client_credentials"}
|
|
60
|
+
|
|
61
|
+
response = self._session.post(
|
|
62
|
+
url,
|
|
63
|
+
params=query_params,
|
|
64
|
+
auth=(self._client_id, self._client_secret),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
json_response = self._response_handler(response)
|
|
68
|
+
self._access_token = json_response["access_token"]
|
|
69
|
+
|
|
70
|
+
return json_response
|
|
71
|
+
|
|
72
|
+
def _ensure_valid_token(self, region: str) -> None:
|
|
73
|
+
"""Ensure that the token is valid."""
|
|
74
|
+
if self._access_token is None or self._is_token_expired():
|
|
75
|
+
self._get_client_token(region)
|
|
76
|
+
|
|
77
|
+
def _response_handler(self, response: requests.Response) -> dict[str, Any]:
|
|
78
|
+
"""Handle the response."""
|
|
79
|
+
response.raise_for_status()
|
|
80
|
+
return response.json()
|
|
81
|
+
|
|
82
|
+
def _request_handler(
|
|
83
|
+
self, url: str, region: str, query_params: dict[str, Any] = None
|
|
84
|
+
) -> dict[str, Any]:
|
|
85
|
+
"""Handle the request."""
|
|
86
|
+
self._ensure_valid_token(region)
|
|
87
|
+
|
|
88
|
+
headers = {"Authorization": f"Bearer {self._access_token}"}
|
|
89
|
+
|
|
90
|
+
# Initialize query_params if it's None
|
|
91
|
+
if query_params is None:
|
|
92
|
+
query_params = {}
|
|
93
|
+
else:
|
|
94
|
+
# Create a copy of query_params to avoid modifying the original
|
|
95
|
+
query_params = query_params.copy()
|
|
96
|
+
|
|
97
|
+
# Remove access_token from query_params if it exists
|
|
98
|
+
query_params.pop("access_token", None)
|
|
99
|
+
|
|
100
|
+
response = self._session.get(url, params=query_params, headers=headers)
|
|
101
|
+
|
|
102
|
+
self._access_token_expiration_datetime = response.headers.get("blizzard-token-expires")
|
|
103
|
+
|
|
104
|
+
if response.status_code == 401 or self._is_token_expired():
|
|
105
|
+
self._get_client_token(region)
|
|
106
|
+
headers["Authorization"] = f"Bearer {self._access_token}"
|
|
107
|
+
response = self._session.get(url, params=query_params, headers=headers)
|
|
108
|
+
|
|
109
|
+
return self._response_handler(response)
|
|
110
|
+
|
|
111
|
+
def _format_api_url(self, resource: str, region: str) -> str:
|
|
112
|
+
"""Format the API url into a usable url."""
|
|
113
|
+
if region == "cn":
|
|
114
|
+
url = self._api_url_cn.format(resource)
|
|
115
|
+
else:
|
|
116
|
+
url = self._api_url.format(region, resource)
|
|
117
|
+
|
|
118
|
+
return url
|
|
119
|
+
|
|
120
|
+
def get_resource(self, resource: str, region: str, query_params={}) -> dict[str, Any]:
|
|
121
|
+
"""Direction handler for when fetching resources."""
|
|
122
|
+
url = self._format_api_url(resource, region)
|
|
123
|
+
return self._request_handler(url, region, query_params)
|
|
124
|
+
|
|
125
|
+
def _format_oauth_url(self, resource: str, region: str) -> str:
|
|
126
|
+
"""Format the oauth url into a usable url."""
|
|
127
|
+
if region == "cn":
|
|
128
|
+
url = self._oauth_url_cn.format(resource)
|
|
129
|
+
else:
|
|
130
|
+
url = self._oauth_url.format(region, resource)
|
|
131
|
+
|
|
132
|
+
return url
|
|
133
|
+
|
|
134
|
+
def get_oauth_resource(self, resource: str, region: str, query_params={}) -> dict[str, Any]:
|
|
135
|
+
"""Direction handler for when fetching oauth resources."""
|
|
136
|
+
url = self._format_oauth_url(resource, region)
|
|
137
|
+
return self._request_handler(url, region, query_params)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""battlenet_api.py file."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from .battlenet_oauth_api import BattlenetOauthApi
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BattlenetApi:
|
|
9
|
+
"""Battle.net API class.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
client_id (str): A string client id supplied by Blizzard.
|
|
13
|
+
client_secret (str): A string client secret supplied by Blizzard.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, client_id: str, client_secret: str) -> dict[str, Any]:
|
|
17
|
+
"""Init BattlenetApi."""
|
|
18
|
+
self.oauth = BattlenetOauthApi(client_id, client_secret)
|
|
@@ -5,7 +5,6 @@ a single client instance. Each game's API is accessible through its own
|
|
|
5
5
|
property on the main client.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
from .api import BaseApi
|
|
10
9
|
from .battlenet.battlenet_api import BattlenetApi
|
|
11
10
|
from .diablo3.diablo3_api import Diablo3Api
|
|
@@ -48,9 +47,9 @@ class BlizzardApi(BaseApi):
|
|
|
48
47
|
|
|
49
48
|
async def __aenter__(self) -> "BlizzardApi":
|
|
50
49
|
"""Async context manager entry.
|
|
51
|
-
|
|
50
|
+
|
|
52
51
|
Initializes async sessions for all game API clients.
|
|
53
|
-
|
|
52
|
+
|
|
54
53
|
Returns:
|
|
55
54
|
BlizzardApi: The initialized API client.
|
|
56
55
|
"""
|
|
@@ -61,12 +60,12 @@ class BlizzardApi(BaseApi):
|
|
|
61
60
|
await self.wow.__aenter__()
|
|
62
61
|
await self.starcraft2.__aenter__()
|
|
63
62
|
return self
|
|
64
|
-
|
|
63
|
+
|
|
65
64
|
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
|
|
66
65
|
"""Async context manager exit.
|
|
67
|
-
|
|
66
|
+
|
|
68
67
|
Closes async sessions for all game API clients.
|
|
69
|
-
|
|
68
|
+
|
|
70
69
|
Args:
|
|
71
70
|
exc_type: The type of exception that was raised, if any.
|
|
72
71
|
exc_val: The exception instance that was raised, if any.
|
|
@@ -78,20 +77,20 @@ class BlizzardApi(BaseApi):
|
|
|
78
77
|
await self.hearthstone.__aexit__(exc_type, exc_val, exc_tb)
|
|
79
78
|
await self.wow.__aexit__(exc_type, exc_val, exc_tb)
|
|
80
79
|
await self.starcraft2.__aexit__(exc_type, exc_val, exc_tb)
|
|
81
|
-
|
|
80
|
+
|
|
82
81
|
@property
|
|
83
82
|
def client_id(self) -> str:
|
|
84
83
|
"""Get the client ID.
|
|
85
|
-
|
|
84
|
+
|
|
86
85
|
Returns:
|
|
87
86
|
str: The Blizzard API client ID.
|
|
88
87
|
"""
|
|
89
88
|
return self._client_id
|
|
90
|
-
|
|
89
|
+
|
|
91
90
|
@property
|
|
92
91
|
def client_secret(self) -> str:
|
|
93
92
|
"""Get the client secret.
|
|
94
|
-
|
|
93
|
+
|
|
95
94
|
Returns:
|
|
96
95
|
str: The Blizzard API client secret.
|
|
97
96
|
"""
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from ..api import Api
|
|
4
|
+
|
|
5
|
+
"""diablo3_community_api.py file."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Diablo3CommunityApi(Api):
|
|
9
|
+
"""All Diablo 3 Community API methods.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
client_id (str): A string client ID supplied by Blizzard.
|
|
13
|
+
client_secret (str): A string client secret supplied by Blizzard.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, client_id: str, client_secret: str) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Initialize the Diablo3CommunityApi class.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
client_id (str): The client ID supplied by Blizzard.
|
|
22
|
+
client_secret (str): The client secret supplied by Blizzard.
|
|
23
|
+
"""
|
|
24
|
+
super().__init__(client_id, client_secret)
|
|
25
|
+
|
|
26
|
+
def get_act_index(self, region: str, locale: str) -> dict[str, Any]:
|
|
27
|
+
"""
|
|
28
|
+
Return an index of acts.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
region (str): The region to query (e.g., "us", "eu").
|
|
32
|
+
locale (str): The locale to use for the response.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Dict[str, Any]: A dictionary containing the index of acts.
|
|
36
|
+
"""
|
|
37
|
+
resource = "/d3/data/act"
|
|
38
|
+
query_params = {"locale": locale}
|
|
39
|
+
return super().get_resource(resource, region, query_params)
|
|
40
|
+
|
|
41
|
+
def get_act(self, region: str, locale: str, act_id: int) -> dict[str, Any]:
|
|
42
|
+
"""
|
|
43
|
+
Return a single act by ID.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
region (str): The region to query.
|
|
47
|
+
locale (str): The locale to use for the response.
|
|
48
|
+
act_id (int): The ID of the act to retrieve.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Dict[str, Any]: A dictionary containing the act details.
|
|
52
|
+
"""
|
|
53
|
+
resource = f"/d3/data/act/{act_id}"
|
|
54
|
+
query_params = {"locale": locale}
|
|
55
|
+
return super().get_resource(resource, region, query_params)
|
|
56
|
+
|
|
57
|
+
def get_artisan(self, region: str, locale: str, artisan_slug: str) -> dict[str, Any]:
|
|
58
|
+
"""
|
|
59
|
+
Return a single artisan by slug.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
region (str): The region to query.
|
|
63
|
+
locale (str): The locale to use for the response.
|
|
64
|
+
artisan_slug (str): The slug of the artisan to retrieve.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
Dict[str, Any]: A dictionary containing the artisan details.
|
|
68
|
+
"""
|
|
69
|
+
resource = f"/d3/data/artisan/{artisan_slug}"
|
|
70
|
+
query_params = {"locale": locale}
|
|
71
|
+
return super().get_resource(resource, region, query_params)
|
|
72
|
+
|
|
73
|
+
def get_recipe(
|
|
74
|
+
self, region: str, locale: str, artisan_slug: str, recipe_slug: str
|
|
75
|
+
) -> dict[str, Any]:
|
|
76
|
+
"""
|
|
77
|
+
Return a single recipe by slug for the specified artisan.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
region (str): The region to query.
|
|
81
|
+
locale (str): The locale to use for the response.
|
|
82
|
+
artisan_slug (str): The slug of the artisan.
|
|
83
|
+
recipe_slug (str): The slug of the recipe to retrieve.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
Dict[str, Any]: A dictionary containing the recipe details.
|
|
87
|
+
"""
|
|
88
|
+
resource = f"/d3/data/artisan/{artisan_slug}/recipe/{recipe_slug}"
|
|
89
|
+
query_params = {"locale": locale}
|
|
90
|
+
return super().get_resource(resource, region, query_params)
|
|
91
|
+
|
|
92
|
+
def get_follower(self, region: str, locale: str, follower_slug: str) -> dict[str, Any]:
|
|
93
|
+
"""
|
|
94
|
+
Return a single follower by slug.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
region (str): The region to query.
|
|
98
|
+
locale (str): The locale to use for the response.
|
|
99
|
+
follower_slug (str): The slug of the follower to retrieve.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Dict[str, Any]: A dictionary containing the follower details.
|
|
103
|
+
"""
|
|
104
|
+
resource = f"/d3/data/follower/{follower_slug}"
|
|
105
|
+
query_params = {"locale": locale}
|
|
106
|
+
return super().get_resource(resource, region, query_params)
|
|
107
|
+
|
|
108
|
+
def get_character_class(self, region: str, locale: str, class_slug: str) -> dict[str, Any]:
|
|
109
|
+
"""
|
|
110
|
+
Return a single character class by slug.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
region (str): The region to query.
|
|
114
|
+
locale (str): The locale to use for the response.
|
|
115
|
+
class_slug (str): The slug of the character class to retrieve.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
Dict[str, Any]: A dictionary containing the character class details.
|
|
119
|
+
"""
|
|
120
|
+
resource = f"/d3/data/hero/{class_slug}"
|
|
121
|
+
query_params = {"locale": locale}
|
|
122
|
+
return super().get_resource(resource, region, query_params)
|
|
123
|
+
|
|
124
|
+
def get_api_skill(
|
|
125
|
+
self, region: str, locale: str, class_slug: str, skill_slug: str
|
|
126
|
+
) -> dict[str, Any]:
|
|
127
|
+
"""
|
|
128
|
+
Return a single skill by slug for a specific character class.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
region (str): The region to query.
|
|
132
|
+
locale (str): The locale to use for the response.
|
|
133
|
+
class_slug (str): The slug of the character class.
|
|
134
|
+
skill_slug (str): The slug of the skill to retrieve.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
Dict[str, Any]: A dictionary containing the skill details.
|
|
138
|
+
"""
|
|
139
|
+
resource = f"/d3/data/hero/{class_slug}/skill/{skill_slug}"
|
|
140
|
+
query_params = {"locale": locale}
|
|
141
|
+
return super().get_resource(resource, region, query_params)
|
|
142
|
+
|
|
143
|
+
def get_item_type_index(self, region: str, locale: str) -> dict[str, Any]:
|
|
144
|
+
"""
|
|
145
|
+
Return an index of item types.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
region (str): The region to query.
|
|
149
|
+
locale (str): The locale to use for the response.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Dict[str, Any]: A dictionary containing the index of item types.
|
|
153
|
+
"""
|
|
154
|
+
resource = "/d3/data/item-type"
|
|
155
|
+
query_params = {"locale": locale}
|
|
156
|
+
return super().get_resource(resource, region, query_params)
|
|
157
|
+
|
|
158
|
+
def get_item_type(self, region: str, locale: str, item_type_slug: str) -> dict[str, Any]:
|
|
159
|
+
"""
|
|
160
|
+
Return a single item type by slug.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
region (str): The region to query.
|
|
164
|
+
locale (str): The locale to use for the response.
|
|
165
|
+
item_type_slug (str): The slug of the item type to retrieve.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
Dict[str, Any]: A dictionary containing the item type details.
|
|
169
|
+
"""
|
|
170
|
+
resource = f"/d3/data/item-type/{item_type_slug}"
|
|
171
|
+
query_params = {"locale": locale}
|
|
172
|
+
return super().get_resource(resource, region, query_params)
|
|
173
|
+
|
|
174
|
+
def get_item(self, region: str, locale: str, item_slug_id: str) -> dict[str, Any]:
|
|
175
|
+
"""
|
|
176
|
+
Return a single item by item slug and ID.
|
|
177
|
+
|
|
178
|
+
Args:
|
|
179
|
+
region (str): The region to query.
|
|
180
|
+
locale (str): The locale to use for the response.
|
|
181
|
+
item_slug_id (str): The slug and ID of the item to retrieve.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
Dict[str, Any]: A dictionary containing the item details.
|
|
185
|
+
"""
|
|
186
|
+
resource = f"/d3/data/item/{item_slug_id}"
|
|
187
|
+
query_params = {"locale": locale}
|
|
188
|
+
return super().get_resource(resource, region, query_params)
|
|
189
|
+
|
|
190
|
+
def get_api_account(self, region: str, locale: str, account_id: str) -> dict[str, Any]:
|
|
191
|
+
"""
|
|
192
|
+
Return the specified account profile.
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
region (str): The region to query.
|
|
196
|
+
locale (str): The locale to use for the response.
|
|
197
|
+
account_id (str): The ID of the account to retrieve.
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
Dict[str, Any]: A dictionary containing the account profile details.
|
|
201
|
+
"""
|
|
202
|
+
resource = f"/d3/profile/{account_id}/"
|
|
203
|
+
query_params = {"locale": locale}
|
|
204
|
+
return super().get_resource(resource, region, query_params)
|
|
205
|
+
|
|
206
|
+
def get_api_hero(
|
|
207
|
+
self, region: str, locale: str, account_id: str, hero_id: int
|
|
208
|
+
) -> dict[str, Any]:
|
|
209
|
+
"""
|
|
210
|
+
Return a single hero.
|
|
211
|
+
|
|
212
|
+
Args:
|
|
213
|
+
region (str): The region to query.
|
|
214
|
+
locale (str): The locale to use for the response.
|
|
215
|
+
account_id (str): The ID of the account.
|
|
216
|
+
hero_id (int): The ID of the hero to retrieve.
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
Dict[str, Any]: A dictionary containing the hero details.
|
|
220
|
+
"""
|
|
221
|
+
resource = f"/d3/profile/{account_id}/hero/{hero_id}"
|
|
222
|
+
query_params = {"locale": locale}
|
|
223
|
+
return super().get_resource(resource, region, query_params)
|
|
224
|
+
|
|
225
|
+
def get_api_detailed_hero_items(
|
|
226
|
+
self, region: str, locale: str, account_id: str, hero_id: int
|
|
227
|
+
) -> dict[str, Any]:
|
|
228
|
+
"""
|
|
229
|
+
Return a list of items for the specified hero.
|
|
230
|
+
|
|
231
|
+
Args:
|
|
232
|
+
region (str): The region to query.
|
|
233
|
+
locale (str): The locale to use for the response.
|
|
234
|
+
account_id (str): The ID of the account.
|
|
235
|
+
hero_id (int): The ID of the hero.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
Dict[str, Any]: A dictionary containing the list of items for the hero.
|
|
239
|
+
"""
|
|
240
|
+
resource = f"/d3/profile/{account_id}/hero/{hero_id}/items"
|
|
241
|
+
query_params = {"locale": locale}
|
|
242
|
+
return super().get_resource(resource, region, query_params)
|
|
243
|
+
|
|
244
|
+
def get_api_detailed_follower_items(
|
|
245
|
+
self, region: str, locale: str, account_id: str, hero_id: int
|
|
246
|
+
) -> dict[str, Any]:
|
|
247
|
+
"""
|
|
248
|
+
Return a single item by item slug and ID.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
region (str): The region to query.
|
|
252
|
+
locale (str): The locale to use for the response.
|
|
253
|
+
account_id (str): The ID of the account.
|
|
254
|
+
hero_id (int): The ID of the hero.
|
|
255
|
+
|
|
256
|
+
Returns:
|
|
257
|
+
Dict[str, Any]: A dictionary containing the item details.
|
|
258
|
+
"""
|
|
259
|
+
resource = f"/d3/profile/{account_id}/hero/{hero_id}/follower-items"
|
|
260
|
+
query_params = {"locale": locale}
|
|
261
|
+
return super().get_resource(resource, region, query_params)
|