sok.apis.key_check
Check that the key of a service works, with one light request.
The API clients do not all report a wrong key (some log it and return no result), so each service has its own probe here: a request that needs the key and nothing else, read by its status and, for OMDb and Last.fm, by its body. No Qt; the server uses it for the "Test" button of its settings.
KeyCheckdataclass
class KeyCheck(service: str, status: str, detail: str = '')What a check found; detail is the message of the service, if any.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
service | str | ||
status | str | ||
detail | str | '' |
Attributes
| Name | Type |
|---|---|
detail | str |
service | str |
status | str |
okproperty
bool
Probedataclass
class Probe( method: str, url: str, build: Callable[[str, str], Tuple[Dict, Dict, Any, Any]], needs_secret: bool = False, wrong_statuses: FrozenSet[int] = frozenset(), read_body: Optional[Callable[[Any], Optional[str]]] = None,)The request that checks the key of one service.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
method | str | ||
url | str | ||
build | Callable[[str, str], Tuple[Dict, Dict, Any, Any]] | ||
needs_secret | bool | False | |
wrong_statuses | FrozenSet[int] | frozenset() | |
read_body | Optional[Callable[[Any], Optional[str]]] | None |
Attributes
| Name | Type |
|---|---|
build | Callable[[str, str], Tuple[Dict, Dict, Any, Any]] |
method | str |
needs_secret | bool |
read_body | Optional[Callable[[Any], Optional[str]]] |
url | str |
wrong_statuses | FrozenSet[int] |
Functions
check_keyasync
async def check_key( service: str, key: str, secret: str = '', fetch: Fetch = _fetch,) -> KeyCheck:Check the key (and secret) of a service with one request.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
service | str | The id of the service, as in the API registry. | |
key | str | The key, or the client id for Spotify and IGDB. | |
secret | str | '' | The client secret of Spotify and IGDB. |
fetch | Fetch | _fetch | Makes the request; tests give a fake one. |
Attributes
| Name | Type | Value |
|---|---|---|
Fetch | Callable[..., Awaitable[Tuple[int, Any]]] | |
MISSING_KEY | 'missing_key' | |
OK | 'ok' | |
PROBES | Dict[str, Probe] | {'tmdb': Probe('GET', 'https://api.themoviedb.org/3/authentication', _bearer), 'tvdb': Probe('POST', 'https://api4.thetvdb.com/v4/login', lambda …), 'omdb': Probe('GET', 'https://www.omdbapi.com/', _param('apikey', i='tt0111161'), read_body=_omdb_body), 'lastfm': Probe('GET', 'https://ws.audioscrobbler.com/2.0/', _param('api_key', method='artist.getinfo', artist='Daft Punk', format='json'), read_body=_lastfm_body), 'spotify': Probe('POST', 'https://accounts.spotify.com/api/token', _spotify, needs_secret=True, wrong_statuses=frozenset({400})), 'google_books': Probe('GET', 'https://www.googleapis.com/books/v1/volumes', _param('key', q='dune', maxResults='1'), wrong_statuses=frozenset({400})), 'igdb': Probe('POST', 'https://id.twitch.tv/oauth2/token', _twitch, needs_secret=True, wrong_statuses=frozenset({400})), 'rawg': Probe('GET', 'https://api.rawg.io/api/games', _param('key', page_size='1')), 'fanart': Probe('GET', 'https://webservice.fanart.tv/v3/movies/603', _param('api_key'))} |
RATE_LIMITED | 'rate_limited' | |
SERVICE_ERROR | 'service_error' | |
TIMEOUT_SECONDS | 10 | |
UNREACHABLE | 'unreachable' | |
UNSUPPORTED | 'unsupported' | |
WRONG_KEY | 'wrong_key' |