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.
39 lines
1.5 KiB
GDScript
39 lines
1.5 KiB
GDScript
# Generated by tools/generate_api_types.gd from server/openapi.json.
|
|
# Do not edit; change the server and generate again.
|
|
class_name SoundtrackWithSongs
|
|
extends RefCounted
|
|
## The [code]SoundtrackWithSongs[/code] schema of the MusicServer API.
|
|
|
|
var songs: Array[SongInfoForStats]
|
|
var soundtrack_id: int
|
|
var soundtrack_last_played: String
|
|
var soundtrack_name: String
|
|
var soundtrack_played: int
|
|
var soundtrack_uuid: String
|
|
|
|
|
|
## Reads the fields from parsed JSON. Missing fields keep their defaults.
|
|
static func from_dict(data: Dictionary) -> SoundtrackWithSongs:
|
|
var result: SoundtrackWithSongs = SoundtrackWithSongs.new()
|
|
for item: Variant in ApiJson.get_array(data, "songs"):
|
|
if item is Dictionary:
|
|
result.songs.append(SongInfoForStats.from_dict(item))
|
|
result.soundtrack_id = ApiJson.get_int(data, "soundtrack_id", 0)
|
|
result.soundtrack_last_played = ApiJson.get_string(data, "soundtrack_last_played", "")
|
|
result.soundtrack_name = ApiJson.get_string(data, "soundtrack_name", "")
|
|
result.soundtrack_played = ApiJson.get_int(data, "soundtrack_played", 0)
|
|
result.soundtrack_uuid = ApiJson.get_string(data, "soundtrack_uuid", "")
|
|
return result
|
|
|
|
|
|
## Returns the fields under their JSON names, ready for [method JSON.stringify].
|
|
func to_dict() -> Dictionary:
|
|
return {
|
|
"songs": songs.map(func(item: SongInfoForStats) -> Dictionary: return item.to_dict()),
|
|
"soundtrack_id": soundtrack_id,
|
|
"soundtrack_last_played": soundtrack_last_played,
|
|
"soundtrack_name": soundtrack_name,
|
|
"soundtrack_played": soundtrack_played,
|
|
"soundtrack_uuid": soundtrack_uuid,
|
|
}
|