Closes #38, #39 and #40; adds the client side of #41. - Every request goes to /api/v1. MusicServerClient gets a token with Settings.api_password the first time one is needed, reuses it, and on a 401 gets a new one and sends the request once more. Switching server gets a new token too. Callers never see the token. - Sync is started with POST, as MusicServer 5.0 requires. - The client has every endpoint in the server's OpenAPI spec, including statistics, soundtracks and songs by UUID, version, downloads and tokens. - tools/generate_api_types.gd generates a typed class per schema in server/openapi.json into server/generated/. Song info, statistics and versions are passed to callers as these classes. A list the server sends as null is an empty list. - FakeHttpTransport hands out tokens and answers 401 without one, so every test goes through the token flow. New tests cover the token handling, every endpoint and each generated class.
29 lines
922 B
GDScript
29 lines
922 B
GDScript
# Generated by tools/generate_api_types.gd from server/openapi.json.
|
|
# Do not edit; change the server and generate again.
|
|
class_name TokenResponse
|
|
extends RefCounted
|
|
## The [code]TokenResponse[/code] schema of the MusicServer API.
|
|
|
|
var client_type: String
|
|
var expires_at: String
|
|
## Send as Authorization: Bearer <token>
|
|
var token: String
|
|
|
|
|
|
## Reads the fields from parsed JSON. Missing fields keep their defaults.
|
|
static func from_dict(data: Dictionary) -> TokenResponse:
|
|
var result: TokenResponse = TokenResponse.new()
|
|
result.client_type = ApiJson.get_string(data, "client_type", "")
|
|
result.expires_at = ApiJson.get_string(data, "expires_at", "")
|
|
result.token = ApiJson.get_string(data, "token", "")
|
|
return result
|
|
|
|
|
|
## Returns the fields under their JSON names, ready for [method JSON.stringify].
|
|
func to_dict() -> Dictionary:
|
|
return {
|
|
"client_type": client_type,
|
|
"expires_at": expires_at,
|
|
"token": token,
|
|
}
|