1"""Routes of the Item, Item Class and Item Set APIs."""
2
3from typing import TYPE_CHECKING
4
5from wow._async._resource import AsyncResource
6from wow.models._common import Media
7from wow.models.item import Item, ItemClass, ItemClassIndex, ItemSearchData, ItemSet, ItemSetIndex
8from wow.search import MAX_PAGE_SIZE
9
10if TYPE_CHECKING:
11 from collections.abc import AsyncIterator, Mapping, Sequence
12
13 from wow.models._common import SearchPage, SearchResult
14 from wow.search import FilterValue
15
16__all__ = ["AsyncItemClasses", "AsyncItemSets", "AsyncItems"]
17
18
[docs]
19class AsyncItems(AsyncResource):
20 """``client.items``: items."""
21
22 __slots__ = ()
23
[docs]
24 async def get(self, item_id: int) -> Item:
25 """Get one item by id."""
26 return await self._get("static", f"/data/wow/item/{item_id}", Item)
27
31
[docs]
32 async def search(
33 self,
34 *,
35 name: str | None = None,
36 filters: Mapping[str, FilterValue] | None = None,
37 order_by: str | Sequence[str] | None = None,
38 page: int = 1,
39 page_size: int = 100,
40 ) -> SearchPage[ItemSearchData]:
41 """Search items.
42
43 Args:
44 name: Match this text in the client's locale.
45 filters: Field filters, such as ``{"item_class.id": 2}``.
46 order_by: Field name(s) to sort by, each optionally suffixed ``:desc``.
47 page: The page to fetch, starting at 1.
48 page_size: Results per page.
49 """
50 return await self._search(
51 "static",
52 "item",
53 ItemSearchData,
54 filters=self._localized_name(name, filters),
55 order_by=order_by,
56 page=page,
57 page_size=page_size,
58 )
59
[docs]
60 def search_all(
61 self,
62 *,
63 name: str | None = None,
64 filters: Mapping[str, FilterValue] | None = None,
65 order_by: str | Sequence[str] | None = None,
66 page_size: int = MAX_PAGE_SIZE,
67 ) -> AsyncIterator[SearchResult[ItemSearchData]]:
68 """Iterate over every result across pages (Battle.net stops at 1,000).
69
70 Args:
71 name: Match this text in the client's locale.
72 filters: Field filters, such as ``{"item_class.id": 2}``.
73 order_by: Field name(s) to sort by, each optionally suffixed ``:desc``.
74 page_size: Results per page.
75 """
76 return self._search_all(
77 "static",
78 "item",
79 ItemSearchData,
80 filters=self._localized_name(name, filters),
81 order_by=order_by,
82 page_size=page_size,
83 )
84
85
[docs]
86class AsyncItemClasses(AsyncResource):
87 """``client.item_classes``: item classes such as Weapon and Consumable."""
88
89 __slots__ = ()
90
[docs]
91 async def index(self) -> ItemClassIndex:
92 """List every item class."""
93 return await self._get("static", "/data/wow/item-class/index", ItemClassIndex)
94
[docs]
95 async def get(self, class_id: int) -> ItemClass:
96 """Get one item class by id."""
97 return await self._get("static", f"/data/wow/item-class/{class_id}", ItemClass)
98
99
[docs]
100class AsyncItemSets(AsyncResource):
101 """``client.item_sets``: equipment sets."""
102
103 __slots__ = ()
104
[docs]
105 async def index(self) -> ItemSetIndex:
106 """List every item set."""
107 return await self._get("static", "/data/wow/item-set/index", ItemSetIndex)
108
[docs]
109 async def get(self, set_id: int) -> ItemSet:
110 """Get one item set by id."""
111 return await self._get("static", f"/data/wow/item-set/{set_id}", ItemSet)