blizzardapi2 2.1.3__tar.gz → 2.1.5__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.3/blizzardapi2.egg-info → blizzardapi2-2.1.5}/PKG-INFO +1 -1
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/_version.py +2 -2
- blizzardapi2-2.1.5/blizzardapi2/api.py +137 -0
- blizzardapi2-2.1.5/blizzardapi2/battlenet/battlenet_api.py +18 -0
- blizzardapi2-2.1.5/blizzardapi2/diablo3/diablo3_community_api.py +261 -0
- blizzardapi2-2.1.5/blizzardapi2/diablo3/diablo3_game_data_api.py +106 -0
- blizzardapi2-2.1.5/blizzardapi2/hearthstone/hearthstone_game_data_api.py +146 -0
- blizzardapi2-2.1.5/blizzardapi2/starcraft2/starcraft2_api.py +18 -0
- blizzardapi2-2.1.5/blizzardapi2/starcraft2/starcraft2_community_api.py +186 -0
- blizzardapi2-2.1.5/blizzardapi2/starcraft2/starcraft2_game_data_api.py +43 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/wow/wow_game_data_api.py +386 -558
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/wow/wow_profile_api.py +119 -184
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5/blizzardapi2.egg-info}/PKG-INFO +1 -1
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2.egg-info/SOURCES.txt +1 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/package.json +1 -1
- blizzardapi2-2.1.5/poetry.lock +377 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/pyproject.toml +3 -4
- blizzardapi2-2.1.3/blizzardapi2/api.py +0 -489
- blizzardapi2-2.1.3/blizzardapi2/battlenet/battlenet_api.py +0 -32
- blizzardapi2-2.1.3/blizzardapi2/diablo3/diablo3_community_api.py +0 -705
- blizzardapi2-2.1.3/blizzardapi2/diablo3/diablo3_game_data_api.py +0 -140
- blizzardapi2-2.1.3/blizzardapi2/hearthstone/hearthstone_game_data_api.py +0 -184
- blizzardapi2-2.1.3/blizzardapi2/starcraft2/starcraft2_api.py +0 -207
- blizzardapi2-2.1.3/blizzardapi2/starcraft2/starcraft2_community_api.py +0 -487
- blizzardapi2-2.1.3/blizzardapi2/starcraft2/starcraft2_game_data_api.py +0 -88
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/.github/dependabot.yml +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/.github/workflows/black.yml +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/.github/workflows/python-package.yml +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/.gitignore +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/CODE_OF_CONDUCT.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/CONTRIBUTING.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/LICENSE +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/README.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/SECURITY.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/__init__.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/battlenet/__init__.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/battlenet/battlenet_oauth_api.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/blizzard_api.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/diablo3/__init__.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/diablo3/diablo3_api.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/hearthstone/__init__.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/hearthstone/hearthstone_api.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/starcraft2/__init__.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/types.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/wow/__init__.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2/wow/wow_api.py +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2.egg-info/dependency_links.txt +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2.egg-info/requires.txt +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/blizzardapi2.egg-info/top_level.txt +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/docs/battlenet/README.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/docs/diablo3/README.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/docs/hearthstone/README.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/docs/pull_request_template.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/docs/starcraft2/README.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/docs/wow/README.md +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/setup.cfg +0 -0
- {blizzardapi2-2.1.3 → blizzardapi2-2.1.5}/uv.lock +0 -0
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '2.0.8.
|
|
21
|
-
__version_tuple__ = version_tuple = (2, 0, 8, '
|
|
20
|
+
__version__ = version = '2.0.8.dev13+g358f10a'
|
|
21
|
+
__version_tuple__ = version_tuple = (2, 0, 8, 'dev13', 'g358f10a')
|
|
@@ -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)
|
|
@@ -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)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from ..api import Api
|
|
2
|
+
|
|
3
|
+
"""diablo3_game_data_api.py file."""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Diablo3GameDataApi(Api):
|
|
7
|
+
"""All Diablo 3 Game Data API methods.
|
|
8
|
+
|
|
9
|
+
Attributes:
|
|
10
|
+
client_id (str): A string client ID supplied by Blizzard.
|
|
11
|
+
client_secret (str): A string client secret supplied by Blizzard.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, client_id: str, client_secret: str) -> None:
|
|
15
|
+
"""
|
|
16
|
+
Initialize the Diablo3GameDataApi class.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
client_id (str): The client ID supplied by Blizzard.
|
|
20
|
+
client_secret (str): The client secret supplied by Blizzard.
|
|
21
|
+
"""
|
|
22
|
+
super().__init__(client_id, client_secret)
|
|
23
|
+
|
|
24
|
+
def get_season_index(self, region: str) -> dict:
|
|
25
|
+
"""
|
|
26
|
+
Return an index of available seasons.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
region (str): The region to query (e.g., "us", "eu").
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Dict: A dictionary containing the index of seasons.
|
|
33
|
+
"""
|
|
34
|
+
resource = "/data/d3/season/"
|
|
35
|
+
return super().get_resource(resource, region)
|
|
36
|
+
|
|
37
|
+
def get_season(self, region: str, season_id: int) -> dict:
|
|
38
|
+
"""
|
|
39
|
+
Return a leaderboard list for the specified season.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
region (str): The region to query.
|
|
43
|
+
season_id (int): The ID of the season to retrieve.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
Dict: A dictionary containing the leaderboard list for the season.
|
|
47
|
+
"""
|
|
48
|
+
resource = f"/data/d3/season/{season_id}"
|
|
49
|
+
return super().get_resource(resource, region)
|
|
50
|
+
|
|
51
|
+
def get_season_leaderboard(self, region: str, season_id: int, leaderboard_id: int) -> dict:
|
|
52
|
+
"""
|
|
53
|
+
Return the specified leaderboard for the specified season.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
region (str): The region to query.
|
|
57
|
+
season_id (int): The ID of the season.
|
|
58
|
+
leaderboard_id (int): The ID of the leaderboard to retrieve.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
Dict: A dictionary containing the leaderboard details.
|
|
62
|
+
"""
|
|
63
|
+
resource = f"/data/d3/season/{season_id}/leaderboard/{leaderboard_id}"
|
|
64
|
+
return super().get_resource(resource, region)
|
|
65
|
+
|
|
66
|
+
def get_era_index(self, region: str) -> dict:
|
|
67
|
+
"""
|
|
68
|
+
Return an index of available eras.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
region (str): The region to query.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Dict: A dictionary containing the index of eras.
|
|
75
|
+
"""
|
|
76
|
+
resource = "/data/d3/era/"
|
|
77
|
+
return super().get_resource(resource, region)
|
|
78
|
+
|
|
79
|
+
def get_era(self, region: str, era_id: int) -> dict:
|
|
80
|
+
"""
|
|
81
|
+
Return a leaderboard list for a particular era.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
region (str): The region to query.
|
|
85
|
+
era_id (int): The ID of the era to retrieve.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Dict: A dictionary containing the leaderboard list for the era.
|
|
89
|
+
"""
|
|
90
|
+
resource = f"/data/d3/era/{era_id}"
|
|
91
|
+
return super().get_resource(resource, region)
|
|
92
|
+
|
|
93
|
+
def get_era_leaderboard(self, region: str, era_id: int, leaderboard_id: int) -> dict:
|
|
94
|
+
"""
|
|
95
|
+
Return the specified leaderboard for the specified era.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
region (str): The region to query.
|
|
99
|
+
era_id (int): The ID of the era.
|
|
100
|
+
leaderboard_id (int): The ID of the leaderboard to retrieve.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
Dict: A dictionary containing the leaderboard details.
|
|
104
|
+
"""
|
|
105
|
+
resource = f"/data/d3/era/{era_id}/leaderboard/{leaderboard_id}"
|
|
106
|
+
return super().get_resource(resource, region)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from ..api import Api
|
|
4
|
+
|
|
5
|
+
"""hearthstone_game_data_api.py file."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class HearthstoneGameDataApi(Api):
|
|
9
|
+
"""All Hearthstone Game Data 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 HearthstoneGameDataApi 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 search_cards(
|
|
27
|
+
self, region: str, locale: str, card_class: str = None, **query_params: Any
|
|
28
|
+
) -> dict[str, Any]:
|
|
29
|
+
"""
|
|
30
|
+
Return an up-to-date list of all cards matching the search criteria.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
region (str): The region to query (e.g., "us", "eu").
|
|
34
|
+
locale (str): The locale to use for the response.
|
|
35
|
+
card_class (str, optional): The card class (e.g., "mage", "warrior").
|
|
36
|
+
**query_params (Any): Additional search parameters.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Dict[str, Any]: A dictionary containing the list of matching cards.
|
|
40
|
+
"""
|
|
41
|
+
resource = "/hearthstone/cards"
|
|
42
|
+
query_params.update({"locale": locale})
|
|
43
|
+
|
|
44
|
+
# Map `card_class` to `class` if provided
|
|
45
|
+
if card_class is not None:
|
|
46
|
+
query_params["class"] = card_class
|
|
47
|
+
|
|
48
|
+
return super().get_resource(resource, region, query_params)
|
|
49
|
+
|
|
50
|
+
def get_card(
|
|
51
|
+
self, region: str, locale: str, id_or_slug: str, game_mode: str = "constructed"
|
|
52
|
+
) -> dict[str, Any]:
|
|
53
|
+
"""
|
|
54
|
+
Return the card with an ID or slug that matches the one you specify.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
region (str): The region to query.
|
|
58
|
+
locale (str): The locale to use for the response.
|
|
59
|
+
id_or_slug (str): The ID or slug of the card to retrieve.
|
|
60
|
+
game_mode (str, optional): The game mode (default is "constructed").
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
Dict[str, Any]: A dictionary containing the card details.
|
|
64
|
+
"""
|
|
65
|
+
resource = f"/hearthstone/cards/{id_or_slug}"
|
|
66
|
+
query_params = {"locale": locale, "game_mode": game_mode}
|
|
67
|
+
return super().get_resource(resource, region, query_params)
|
|
68
|
+
|
|
69
|
+
def search_card_backs(self, region: str, locale: str, **query_params: Any) -> dict[str, Any]:
|
|
70
|
+
"""
|
|
71
|
+
Return an up-to-date list of all card backs matching the search criteria.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
region (str): The region to query.
|
|
75
|
+
locale (str): The locale to use for the response.
|
|
76
|
+
**query_params (Any): Additional search parameters.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Dict[str, Any]: A dictionary containing the list of matching card backs.
|
|
80
|
+
"""
|
|
81
|
+
resource = "/hearthstone/cardbacks"
|
|
82
|
+
query_params.update({"locale": locale})
|
|
83
|
+
return super().get_resource(resource, region, query_params)
|
|
84
|
+
|
|
85
|
+
def get_card_back(self, region: str, locale: str, id_or_slug: str) -> dict[str, Any]:
|
|
86
|
+
"""
|
|
87
|
+
Return a specific card back by using card back ID or slug.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
region (str): The region to query.
|
|
91
|
+
locale (str): The locale to use for the response.
|
|
92
|
+
id_or_slug (str): The ID or slug of the card back to retrieve.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
Dict[str, Any]: A dictionary containing the card back details.
|
|
96
|
+
"""
|
|
97
|
+
resource = f"/hearthstone/cardbacks/{id_or_slug}"
|
|
98
|
+
query_params = {"locale": locale}
|
|
99
|
+
return super().get_resource(resource, region, query_params)
|
|
100
|
+
|
|
101
|
+
def get_deck(self, region: str, locale: str, **query_params: Any) -> dict[str, Any]:
|
|
102
|
+
"""
|
|
103
|
+
Find a deck by list of cards or code, including the hero.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
region (str): The region to query.
|
|
107
|
+
locale (str): The locale to use for the response.
|
|
108
|
+
**query_params (Any): Additional search parameters.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
Dict[str, Any]: A dictionary containing the deck details.
|
|
112
|
+
"""
|
|
113
|
+
resource = "/hearthstone/deck"
|
|
114
|
+
query_params = {"locale": locale}
|
|
115
|
+
return super().get_resource(resource, region, query_params)
|
|
116
|
+
|
|
117
|
+
def get_metadata(self, region: str, locale: str) -> dict[str, Any]:
|
|
118
|
+
"""
|
|
119
|
+
Return information about the categorization of cards.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
region (str): The region to query.
|
|
123
|
+
locale (str): The locale to use for the response.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
Dict[str, Any]: A dictionary containing the metadata.
|
|
127
|
+
"""
|
|
128
|
+
resource = "/hearthstone/metadata"
|
|
129
|
+
query_params = {"locale": locale}
|
|
130
|
+
return super().get_resource(resource, region, query_params)
|
|
131
|
+
|
|
132
|
+
def get_metadata_type(self, region: str, locale: str, type_id: str) -> dict[str, Any]:
|
|
133
|
+
"""
|
|
134
|
+
Return information about just one type of metadata.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
region (str): The region to query.
|
|
138
|
+
locale (str): The locale to use for the response.
|
|
139
|
+
type_id (str): The ID of the metadata type to retrieve.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
Dict[str, Any]: A dictionary containing the metadata type details.
|
|
143
|
+
"""
|
|
144
|
+
resource = f"/hearthstone/metadata/{type_id}"
|
|
145
|
+
query_params = {"locale": locale}
|
|
146
|
+
return super().get_resource(resource, region, query_params)
|