Cache¶
-
class
arez.
DataCache
[source]¶ A data cache, cappable of storing multiple cached entires of different languages, managing their fetching, refreshing and expiration times.
Inherits from
Endpoint
.Note
You can request your developer ID and authorization key here.
Warning
The main API class uses this class as base, so all of it’s methods are already available there. This class is listed here solely for documentation purposes. Instanting it yourself is possible, but not recommended.
- Parameters
url (str) – The cache’s base endpoint URL.
auth_key (str) – Your developer’s authentication key (authKey).
enabled (bool) – When set to
False
, this disables the data cache. This makes most objects returned from the API beCacheObject
instead of their respective data-rich counterparts. Defaults toTrue
.initialize (Union[bool, Language]) –
When set to
True
, it launches a task that will initialize the cache with the default (English) language.Can be set to a
Language
instance, in which case that language will be set as default first, before initializing.Defaults to
False
, where no initialization occurs.loop (Optional[asyncio.AbstractEventLoop]) –
The event loop you want to use for this data cache.
Default loop is used when not provided.
-
set_default_language
(language)[source]¶ Sets the default language used by the cache in places where one is not provided by the user.
The default language set is
Language.English
.- Parameters
language (Language) – The new default language you want to set.
-
await
initialize
(*, language=None)[source]¶ Initializes the data cache, by pre-fetching and storing the
CacheEntry
for the default language currently set.Note
This will both, force the champion information fetching, as well as cache the resulting object.
-
get_entry
(language=None)[source]¶ Returns a cache entry for the given language specified.
Note
This method can return
None
or stale data if the entry hasn’t been fetched yet, or haven’t been updated in a while.Consider using the
get_champion_info
method from the main API instead.- Parameters
language (Optional[Language]) –
The
Language
you want to get the entry in.Default language is used if not provided.
- Returns
The cache entry you requested.
None
is returned if the entry for the language specified hasn’t been fetched yet.- Return type
Optional[CacheEntry]
-
await
close
()¶ Closes the underlying API connection.
Attempting to make a request after the connection is closed will result in a
RuntimeError
.
-
await
request
(method_name, /, *data)¶ Makes a direct request to the HiRez API.
For all methods available (and their parameters), please see Hi-Rez API docs.
- Parameters
- Returns
A raw server’s response as a string, list or a dictionary (depending on the endpoint).
- Return type
- Raises
HTTPException – Whenever it was impossible to fetch the data in a reliable manner. Check the
HTTPException.cause
attribute for the original exception (and reason) that lead to this.Unauthorized – When the developer’s ID (devId) or the developer’s authentication key (authKey) are deemed invalid.
Unavailable – When the Hi-Rez API switches to emergency mode, and no data could be returned at this time.
LimitReached – Your daily limit of requests has been reached.
-
class
arez.
CacheEntry
[source]¶ Represents a collection of champions, cards, talents and shop items. You can get this one from the
PaladinsAPI.get_champion_info
orDataCache.get_entry
methods.Note
The
Lookup
class provides an easy way of searching for a particular object, based on its Name or ID. You can also obtain a list of all objects instead.Please see the example code below:
entry: CacheEntry # obtain a list of all champions champions = list(entry.champions) # get a particular champion by their name champion = entry.champions.get("Androxus") # fuzzy name matching champion = entry.champions.get_fuzzy("andro")