1"""Routes of the Spell API."""
2
3from typing import TYPE_CHECKING
4
5from wow._async._resource import AsyncResource
6from wow.models._common import Media
7from wow.models.spell import Spell, SpellSearchData
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__ = ["AsyncSpells"]
17
18
[docs]
19class AsyncSpells(AsyncResource):
20 """``client.spells``: spells, such as talents and abilities."""
21
22 __slots__ = ()
23
[docs]
24 async def get(self, spell_id: int) -> Spell:
25 """Get one spell by id."""
26 return await self._get("static", f"/data/wow/spell/{spell_id}", Spell)
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[SpellSearchData]:
41 """Search spells.
42
43 Args:
44 name: Match this text in the client's locale.
45 filters: Field filters, such as ``{"id": 11070}``.
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 "spell",
53 SpellSearchData,
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[SpellSearchData]]:
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 ``{"id": 11070}``.
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 "spell",
79 SpellSearchData,
80 filters=self._localized_name(name, filters),
81 order_by=order_by,
82 page_size=page_size,
83 )