blizzardapi2 0.1.7__tar.gz → 1.0.0__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.
Files changed (25) hide show
  1. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/PKG-INFO +1 -1
  2. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/api.py +31 -15
  3. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/wow/wow_game_data_api.py +61 -14
  4. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/wow/wow_profile_api.py +25 -5
  5. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/pyproject.toml +1 -1
  6. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/LICENSE +0 -0
  7. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/README.md +0 -0
  8. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/__init__.py +0 -0
  9. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/battlenet/__init__.py +0 -0
  10. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/battlenet/battlenet_api.py +0 -0
  11. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/battlenet/battlenet_oauth_api.py +0 -0
  12. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/blizzard_api.py +0 -0
  13. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/diablo3/__init__.py +0 -0
  14. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/diablo3/diablo3_api.py +0 -0
  15. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/diablo3/diablo3_community_api.py +0 -0
  16. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/diablo3/diablo3_game_data_api.py +0 -0
  17. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/hearthstone/__init__.py +0 -0
  18. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/hearthstone/hearthstone_api.py +0 -0
  19. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/hearthstone/hearthstone_game_data_api.py +0 -0
  20. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/starcraft2/__init__.py +0 -0
  21. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/starcraft2/starcraft2_api.py +0 -0
  22. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/starcraft2/starcraft2_community_api.py +0 -0
  23. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/starcraft2/starcraft2_game_data_api.py +0 -0
  24. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/wow/__init__.py +0 -0
  25. {blizzardapi2-0.1.7 → blizzardapi2-1.0.0}/blizzardapi2/wow/wow_api.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blizzardapi2
3
- Version: 0.1.7
3
+ Version: 1.0.0
4
4
  Summary: A Python wrapper for Blizzard API
5
5
  License: MIT
6
6
  Author: lostcol0ny
@@ -3,7 +3,7 @@
3
3
  from typing import Dict, Any
4
4
  import requests
5
5
 
6
- from time import time
6
+ from datetime import datetime, timezone, timedelta
7
7
 
8
8
 
9
9
  class Api:
@@ -22,10 +22,10 @@ class Api:
22
22
 
23
23
  def __init__(self, client_id: str, client_secret: str) -> None:
24
24
  """Init Api."""
25
- self._client_id = client_id
26
- self._client_secret = client_secret
27
- self._access_token = None
28
- self._token_expiration = 0
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
29
 
30
30
  self._api_url = "https://{0}.api.blizzard.com{1}"
31
31
  self._api_url_cn = "https://gateway.battlenet.com.cn{0}"
@@ -36,8 +36,21 @@ class Api:
36
36
  self._session = requests.Session()
37
37
 
38
38
  def _is_token_expired(self) -> bool:
39
- """Check if the token has expired."""
40
- return time() >= self._token_expiration
39
+ """Check if the token is expiring within next 5 minutes."""
40
+ current_time = (
41
+ datetime.now(timezone.utc)
42
+ .isoformat(timespec="milliseconds")
43
+ .replace("+00:00", "Z")
44
+ )
45
+ datetime_format = "%Y-%m-%dT%H:%M:%S.%fZ"
46
+ blizz_expire_obj = datetime.strptime(
47
+ self._access_token_expiration_datetime, datetime_format
48
+ )
49
+ current_datetime_obj = datetime.strptime(current_time, datetime_format)
50
+
51
+ time_difference = abs(blizz_expire_obj - current_datetime_obj)
52
+
53
+ return time_difference <= timedelta(minutes=5)
41
54
 
42
55
  def _get_client_token(self, region: str) -> Dict[str, Any]:
43
56
  """Fetch an access token based on client id and client secret credentials.
@@ -57,11 +70,10 @@ class Api:
57
70
 
58
71
  json_response = self._response_handler(response)
59
72
  self._access_token = json_response["access_token"]
60
- self._token_expiration = time() + json_response["expires_in"] - 300
61
-
73
+
62
74
  return json_response
63
75
 
64
- def _ensure_valid_token (self, region: str) -> None:
76
+ def _ensure_valid_token(self, region: str) -> None:
65
77
  """Ensure that the token is valid."""
66
78
  if self._access_token is None or self._is_token_expired():
67
79
  self._get_client_token(region)
@@ -76,17 +88,21 @@ class Api:
76
88
  ) -> Dict[str, Any]:
77
89
  """Handle the request."""
78
90
  self._ensure_valid_token(region)
79
-
91
+
80
92
  if query_params.get("access_token") is None:
81
93
  query_params["access_token"] = self._access_token
82
-
94
+
83
95
  response = self._session.get(url, params=query_params)
84
-
85
- if response.status_code == 401:
96
+
97
+ self._access_token_expiration_datetime = response.headers.get(
98
+ "blizzard-token-expires"
99
+ )
100
+
101
+ if response.status_code == 401 or self._is_token_expired():
86
102
  self._get_client_token(region)
87
103
  query_params["access_token"] = self._access_token
88
104
  response = self._session.get(url, params=query_params)
89
-
105
+
90
106
  return self._response_handler(response)
91
107
 
92
108
  def _format_api_url(self, resource: str, region: str) -> str:
@@ -18,6 +18,20 @@ class WowGameDataApi(Api):
18
18
 
19
19
  # Achievement API
20
20
 
21
+ def get_achievements_index(self, region: str, locale: str) -> Dict[str, Any]:
22
+ """Return an index of achievements."""
23
+ resource = "/data/wow/achievement/index"
24
+ query_params = {"namespace": f"static-{region}", "locale": locale}
25
+ return super().get_resource(resource, region, query_params)
26
+
27
+ def get_achievement(
28
+ self, region: str, locale: str, achievement_id: int
29
+ ) -> Dict[str, Any]:
30
+ """Return an achievement by ID."""
31
+ resource = f"/data/wow/achievement/{achievement_id}"
32
+ query_params = {"namespace": f"static-{region}", "locale": locale}
33
+ return super().get_resource(resource, region, query_params)
34
+
21
35
  def get_achievement_categories_index(
22
36
  self, region: str, locale: str
23
37
  ) -> Dict[str, Any]:
@@ -34,20 +48,6 @@ class WowGameDataApi(Api):
34
48
  query_params = {"namespace": f"static-{region}", "locale": locale}
35
49
  return super().get_resource(resource, region, query_params)
36
50
 
37
- def get_achievements_index(self, region: str, locale: str) -> Dict[str, Any]:
38
- """Return an index of achievements."""
39
- resource = "/data/wow/achievement/index"
40
- query_params = {"namespace": f"static-{region}", "locale": locale}
41
- return super().get_resource(resource, region, query_params)
42
-
43
- def get_achievement(
44
- self, region: str, locale: str, achievement_id: int
45
- ) -> Dict[str, Any]:
46
- """Return an achievement by ID."""
47
- resource = f"/data/wow/achievement/{achievement_id}"
48
- query_params = {"namespace": f"static-{region}", "locale": locale}
49
- return super().get_resource(resource, region, query_params)
50
-
51
51
  def get_achievement_media(
52
52
  self, region: str, locale: str, achievement_id: int
53
53
  ) -> Dict[str, Any]:
@@ -387,6 +387,53 @@ class WowGameDataApi(Api):
387
387
  query_params = {"namespace": namespace, "locale": locale}
388
388
  return super().get_resource(resource, region, query_params)
389
389
 
390
+ # Item Appearance API
391
+
392
+ def get_item_appearance(
393
+ self, region: str, locale: str, appearance_id: int, is_classic: bool = False
394
+ ) -> Dict[str, Any]:
395
+ """Returns an item appearance by ID."""
396
+ resource = f"/data/wow/item-appearance/{appearance_id}"
397
+ namespace = f"static-classic-{region}" if is_classic else f"static-{region}"
398
+ query_params = {"namespace": namespace, "locale": locale}
399
+ return super().get_resource(resource, region, query_params)
400
+
401
+ def get_item_appearance_sets_index(
402
+ self, region: str, locale: str, is_classic: bool = False
403
+ ) -> Dict[str, Any]:
404
+ """Returns an index of item appearance sets."""
405
+ resource = f"/data/wow/item-appearance/set/index"
406
+ namespace = f"static-classic-{region}" if is_classic else f"static-{region}"
407
+ query_params = {"namespace": namespace, "locale": locale}
408
+ return super().get_resource(resource, region, query_params)
409
+
410
+ def get_item_appearance_set(
411
+ self, region: str, locale: str, appearance_set_id: int, is_classic: bool = False
412
+ ) -> Dict[str, Any]:
413
+ """Returns an item appearance set by ID."""
414
+ resource = f"/data/wow/item-appearance/set/{appearance_set_id}"
415
+ namespace = f"static-classic-{region}" if is_classic else f"static-{region}"
416
+ query_params = {"namespace": namespace, "locale": locale}
417
+ return super().get_resource(resource, region, query_params)
418
+
419
+ def get_item_appearance_slot_index(
420
+ self, region: str, locale: str, is_classic: bool = False
421
+ ) -> Dict[str, Any]:
422
+ """Returns an index of item appearance slots."""
423
+ resource = f"/data/wow/item-appearance/slot/index"
424
+ namespace = f"static-classic-{region}" if is_classic else f"static-{region}"
425
+ query_params = {"namespace": namespace, "locale": locale}
426
+ return super().get_resource(resource, region, query_params)
427
+
428
+ def get_item_appearance_slot(
429
+ self, region: str, locale: str, slot_type: str, is_classic: bool = False
430
+ ) -> Dict[str, Any]:
431
+ """Returns an item appearance slot slot type."""
432
+ resource = f"/data/wow/item-appearance/slot/{slot_type}"
433
+ namespace = f"static-classic-{region}" if is_classic else f"static-{region}"
434
+ query_params = {"namespace": namespace, "locale": locale}
435
+ return super().get_resource(resource, region, query_params)
436
+
390
437
  # Journal API
391
438
 
392
439
  def get_journal_expansions_index(self, region: str, locale: str) -> Dict[str, Any]:
@@ -59,6 +59,18 @@ class WowProfileApi(Api):
59
59
  }
60
60
  return super().get_resource(resource, region, query_params)
61
61
 
62
+ def get_account_heirlooms_collection_summary(
63
+ self, region: str, locale: str, access_token: str
64
+ ) -> Dict[str, Any]:
65
+ """Return a summary of the heirlooms an account has obtained."""
66
+ resource = "/profile/user/wow/collections/heirlooms"
67
+ query_params = {
68
+ "namespace": f"profile-{region}",
69
+ "locale": locale,
70
+ "access_token": access_token,
71
+ }
72
+ return super().get_resource(resource, region, query_params)
73
+
62
74
  def get_account_mounts_collection_summary(
63
75
  self, region: str, locale: str, access_token: str
64
76
  ) -> Dict[str, Any]:
@@ -95,11 +107,11 @@ class WowProfileApi(Api):
95
107
  }
96
108
  return super().get_resource(resource, region, query_params)
97
109
 
98
- def get_account_heirlooms_collection_summary(
110
+ def get_account_transmog_collection_summary(
99
111
  self, region: str, locale: str, access_token: str
100
112
  ) -> Dict[str, Any]:
101
- """Return a summary of the heirlooms an account has obtained."""
102
- resource = "/profile/user/wow/collections/heirlooms"
113
+ """Return a summary of the toys an account has obtained."""
114
+ resource = "/profile/user/wow/collections/transmogs"
103
115
  query_params = {
104
116
  "namespace": f"profile-{region}",
105
117
  "locale": locale,
@@ -145,6 +157,14 @@ class WowProfileApi(Api):
145
157
  query_params = {"namespace": f"profile-{region}", "locale": locale}
146
158
  return super().get_resource(resource, region, query_params)
147
159
 
160
+ def get_character_heirlooms_collection_summary(
161
+ self, region: str, locale: str, realm_slug: str, character_name: str
162
+ ) -> Dict[str, Any]:
163
+ """Return a summary of the toys a character has obtained."""
164
+ resource = f"/profile/wow/character/{realm_slug}/{character_name}/collections/heirlooms"
165
+ query_params = {"namespace": f"profile-{region}", "locale": locale}
166
+ return super().get_resource(resource, region, query_params)
167
+
148
168
  def get_character_mounts_collection_summary(
149
169
  self, region: str, locale: str, realm_slug: str, character_name: str
150
170
  ) -> Dict[str, Any]:
@@ -175,11 +195,11 @@ class WowProfileApi(Api):
175
195
  query_params = {"namespace": f"profile-{region}", "locale": locale}
176
196
  return super().get_resource(resource, region, query_params)
177
197
 
178
- def get_character_heirlooms_collection_summary(
198
+ def get_character_transmog_collection_summary(
179
199
  self, region: str, locale: str, realm_slug: str, character_name: str
180
200
  ) -> Dict[str, Any]:
181
201
  """Return a summary of the toys a character has obtained."""
182
- resource = f"/profile/wow/character/{realm_slug}/{character_name}/collections/heirlooms"
202
+ resource = f"/profile/wow/character/{realm_slug}/{character_name}/collections/transmogs"
183
203
  query_params = {"namespace": f"profile-{region}", "locale": locale}
184
204
  return super().get_resource(resource, region, query_params)
185
205
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "blizzardapi2"
3
- version = "0.1.7"
3
+ version = "1.0.0"
4
4
  description = "A Python wrapper for Blizzard API"
5
5
  authors = ["lostcol0ny <c098os0k@4wrd.cc>"]
6
6
  license = "MIT"
File without changes
File without changes