import 'dart:convert'; import 'package:OpenContacts/clients/api_client.dart'; import 'package:OpenContacts/models/cloud_variable.dart'; class CloudVariableApi { static Future readCloudVariable(ApiClient client, {required String ownerId, required String path,}) async { final response = await client.get("/${ownerId.isEmpty ? "globalvars" : "users/$ownerId/vars"}/$path"); client.checkResponse(response); final body = jsonDecode(response.body); return CloudVariable.fromMap(body); } static Future readGlobalCloudVariable(ApiClient client, {required String path}) async => await readCloudVariable(client, ownerId: "", path: path); static Future deleteCloudVariable(ApiClient client, {required String ownerId, required String path}) async { final response = await client.delete("/users/vars/$path"); client.checkResponse(response); } static Future writeCloudVariable(ApiClient client, {required String ownerId, required String path, required String value}) async { final response = await client.put("/users/$ownerId/vars/$path", body: value); client.checkResponse(response); } }