Utility
utility
¶
Utility
¶
Bases: SyncBaseExtension[Utility]
Extension for utility related endpoints.
Source code in pokelance/ext/_base.py
get_language
¶
Gets a language from the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The resource id. |
required |
Returns:
| Type | Description |
|---|---|
Language | None
|
The cached model or None. |
Examples:
Source code in pokelance/ext/sync/utility.py
def get_language(self, id: int) -> models.Language | None:
"""Gets a language from the cache.
Parameters
----------
id : int
The resource id.
Returns
-------
models.Language | None
The cached model or None.
Examples
--------
```python
language = client.utility.get_language("en")
if language:
print(language)
```"""
route = Endpoint.get_language(id)
self._validate_resource(self._cache_group.language, id, route)
return self._cache_group.language.get(route, None)
fetch_language
¶
Fetches a language from the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
The resource id. |
required |
Returns:
| Type | Description |
|---|---|
Language
|
The fetched model. |
Examples:
Source code in pokelance/ext/sync/utility.py
def fetch_language(self, id: int) -> models.Language:
"""Fetches a language from the API.
Parameters
----------
id : int
The resource id.
Returns
-------
models.Language
The fetched model.
Examples
--------
```python
language = client.utility.fetch_language("en")
print(language)
```"""
route = Endpoint.get_language(id)
self._validate_resource(self._cache_group.language, id, route)
data = self._client.request(route)
return self._cache_group.language.setdefault(route, self._cache_group.language.from_payload(data))
get_api_metadata
¶
get_api_metadata() -> APIMetadata | None
Gets a api metadata from the cache.
Returns:
| Type | Description |
|---|---|
APIMetadata | None
|
The cached model or None. |
Examples:
Source code in pokelance/ext/sync/utility.py
def get_api_metadata(self) -> models.APIMetadata | None:
"""Gets a api metadata from the cache.
Returns
-------
models.APIMetadata | None
The cached model or None.
Examples
--------
```python
metadata = client.utility.get_api_metadata()
if metadata:
print(metadata)
```"""
route = Endpoint.get_api_metadata()
return self._cache_group.api_metadata.get(route, None)
fetch_api_metadata
¶
fetch_api_metadata() -> APIMetadata
Fetches a api metadata from the API.
Returns:
| Type | Description |
|---|---|
APIMetadata
|
The fetched model. |
Examples:
Source code in pokelance/ext/sync/utility.py
def fetch_api_metadata(self) -> models.APIMetadata:
"""Fetches a api metadata from the API.
Returns
-------
models.APIMetadata
The fetched model.
Examples
--------
```python
metadata = client.utility.fetch_api_metadata()
print(metadata)
```"""
route = Endpoint.get_api_metadata()
data = self._client.request(route)
return self._cache_group.api_metadata.setdefault(route, self._cache_group.api_metadata.from_payload(data))
setup
¶
setup(lance: PokeLanceSyncClient) -> None