import 'dart:developer'; import 'package:http/http.dart' as http; import '../../../model/accountData.dart'; import '../../apiError.dart'; import '../../apiParams.dart'; import '../../apiRequest.dart'; enum TalkApiMethod { get, post, put, delete, } abstract class TalkApi extends ApiRequest { String path; ApiParams? body; Map? headers = {}; Map? getParameters; http.Response? response; TalkApi(this.path, this.body, {this.headers, this.getParameters}); Future? request(Uri uri, ApiParams? body, Map? headers); T assemble(String raw); Future run() async { getParameters?.forEach((key, value) { getParameters?.update(key, (value) => value.toString()); }); Uri endpoint = Uri.https("${AccountData().buildHttpAuthString()}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/spreed/api/$path", getParameters); headers ??= {}; headers?.putIfAbsent("Accept", () => "application/json"); headers?.putIfAbsent("OCS-APIRequest", () => "true"); http.Response? data = await request(endpoint, body, headers); if(data == null) { throw ApiError("Request could not be dispatched!"); } //dynamic jsonData = jsonDecode(data.body); T assembled; try { assembled = assemble(data.body); return assembled; } catch (_) { // TODO report error log("Error assembling Talk API response on $endpoint with body: $body and headers: ${headers.toString()}"); } throw Exception("Error assembling Talk API response"); } }