Source code for wow._async.resources.creature

  1"""Routes of the Creature, Creature Family and Creature Type APIs."""
  2
  3from typing import TYPE_CHECKING
  4
  5from wow._async._resource import AsyncResource
  6from wow.models._common import Media
  7from wow.models.creature import (
  8    Creature,
  9    CreatureFamily,
 10    CreatureFamilyIndex,
 11    CreatureSearchData,
 12    CreatureType,
 13    CreatureTypeIndex,
 14)
 15from wow.search import MAX_PAGE_SIZE
 16
 17if TYPE_CHECKING:
 18    from collections.abc import AsyncIterator, Mapping, Sequence
 19
 20    from wow.models._common import SearchPage, SearchResult
 21    from wow.search import FilterValue
 22
 23__all__ = ["AsyncCreatureFamilies", "AsyncCreatureTypes", "AsyncCreatures"]
 24
 25
[docs] 26class AsyncCreatureFamilies(AsyncResource): 27 """``client.creature_families``: pet families such as Bat and Wolf.""" 28 29 __slots__ = () 30
[docs] 31 async def index(self) -> CreatureFamilyIndex: 32 """List every creature family.""" 33 return await self._get("static", "/data/wow/creature-family/index", CreatureFamilyIndex)
34
[docs] 35 async def get(self, family_id: int) -> CreatureFamily: 36 """Get one creature family by id.""" 37 return await self._get("static", f"/data/wow/creature-family/{family_id}", CreatureFamily)
38 39
[docs] 40class AsyncCreatureTypes(AsyncResource): 41 """``client.creature_types``: creature types such as Beast and Dragonkin.""" 42 43 __slots__ = () 44
[docs] 45 async def index(self) -> CreatureTypeIndex: 46 """List every creature type.""" 47 return await self._get("static", "/data/wow/creature-type/index", CreatureTypeIndex)
48
[docs] 49 async def get(self, type_id: int) -> CreatureType: 50 """Get one creature type by id.""" 51 return await self._get("static", f"/data/wow/creature-type/{type_id}", CreatureType)
52 53
[docs] 54class AsyncCreatures(AsyncResource): 55 """``client.creatures``: creatures, Forest Spider included.""" 56 57 __slots__ = () 58
[docs] 59 async def get(self, creature_id: int) -> Creature: 60 """Get one creature by id.""" 61 return await self._get("static", f"/data/wow/creature/{creature_id}", Creature)
62
[docs] 63 async def display_media(self, display_id: int) -> Media: 64 """Get a creature display's rendered image.""" 65 return await self._get("static", f"/data/wow/media/creature-display/{display_id}", Media)
66
[docs] 67 async def search( 68 self, 69 *, 70 name: str | None = None, 71 filters: Mapping[str, FilterValue] | None = None, 72 order_by: str | Sequence[str] | None = None, 73 page: int = 1, 74 page_size: int = 100, 75 ) -> SearchPage[CreatureSearchData]: 76 """Search creatures. 77 78 Args: 79 name: Match this text in the client's locale. 80 filters: Field filters, such as ``{"is_tameable": True}``. 81 order_by: Field name(s) to sort by, each optionally suffixed ``:desc``. 82 page: The page to fetch, starting at 1. 83 page_size: Results per page. 84 """ 85 return await self._search( 86 "static", 87 "creature", 88 CreatureSearchData, 89 filters=self._localized_name(name, filters), 90 order_by=order_by, 91 page=page, 92 page_size=page_size, 93 )
94
[docs] 95 def search_all( 96 self, 97 *, 98 name: str | None = None, 99 filters: Mapping[str, FilterValue] | None = None, 100 order_by: str | Sequence[str] | None = None, 101 page_size: int = MAX_PAGE_SIZE, 102 ) -> AsyncIterator[SearchResult[CreatureSearchData]]: 103 """Iterate over every result across pages (Battle.net stops at 1,000). 104 105 Args: 106 name: Match this text in the client's locale. 107 filters: Field filters, such as ``{"is_tameable": True}``. 108 order_by: Field name(s) to sort by, each optionally suffixed ``:desc``. 109 page_size: Results per page. 110 """ 111 return self._search_all( 112 "static", 113 "creature", 114 CreatureSearchData, 115 filters=self._localized_name(name, filters), 116 order_by=order_by, 117 page_size=page_size, 118 )