Skip to content

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

NameTypeDefaultDescription
servicestr
statusstr
detailstr''
Source

Attributes

NameType
detailstr
servicestr
statusstr

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

NameTypeDefaultDescription
methodstr
urlstr
buildCallable[[str, str], Tuple[Dict, Dict, Any, Any]]
needs_secretboolFalse
wrong_statusesFrozenSet[int]frozenset()
read_bodyOptional[Callable[[Any], Optional[str]]]None
Source

Attributes

NameType
buildCallable[[str, str], Tuple[Dict, Dict, Any, Any]]
methodstr
needs_secretbool
read_bodyOptional[Callable[[Any], Optional[str]]]
urlstr
wrong_statusesFrozenSet[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

NameTypeDefaultDescription
servicestrThe id of the service, as in the API registry.
keystrThe key, or the client id for Spotify and IGDB.
secretstr''The client secret of Spotify and IGDB.
fetchFetch_fetchMakes the request; tests give a fake one.
Source

Attributes

NameTypeValue
FetchCallable[..., Awaitable[Tuple[int, Any]]]
MISSING_KEY'missing_key'
OK'ok'
PROBESDict[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_SECONDS10
UNREACHABLE'unreachable'
UNSUPPORTED'unsupported'
WRONG_KEY'wrong_key'
Built with Kiln