OpenContacts/lib/apis/cloud_variable_api.dart

28 lines
1.2 KiB
Dart
Raw Permalink Normal View History

2023-06-03 09:31:15 -04:00
import 'dart:convert';
2024-07-15 00:23:04 -04:00
import 'package:OpenContacts/clients/api_client.dart';
import 'package:OpenContacts/models/cloud_variable.dart';
2023-06-03 09:31:15 -04:00
class CloudVariableApi {
static Future<CloudVariable> 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<CloudVariable> readGlobalCloudVariable(ApiClient client, {required String path}) async =>
await readCloudVariable(client, ownerId: "", path: path);
static Future<void> deleteCloudVariable(ApiClient client, {required String ownerId, required String path}) async {
final response = await client.delete("/users/vars/$path");
client.checkResponse(response);
}
static Future<void> 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);
}
}