Merge
This commit is contained in:
commit
ad8dbf49cc
2 changed files with 60 additions and 0 deletions
27
lib/apis/cloud_variable_api.dart
Normal file
27
lib/apis/cloud_variable_api.dart
Normal file
|
@ -0,0 +1,27 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:contacts_plus_plus/clients/api_client.dart';
|
||||
import 'package:contacts_plus_plus/models/cloud_variable.dart';
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
33
lib/models/cloud_variable.dart
Normal file
33
lib/models/cloud_variable.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
import 'package:contacts_plus_plus/auxiliary.dart';
|
||||
|
||||
class CloudVariable {
|
||||
final String ownerId;
|
||||
final String path;
|
||||
final String value;
|
||||
final String partitionKey;
|
||||
final String rowKey;
|
||||
final DateTime timestamp;
|
||||
final String eTag;
|
||||
|
||||
const CloudVariable({
|
||||
required this.ownerId,
|
||||
required this.path,
|
||||
required this.value,
|
||||
required this.partitionKey,
|
||||
required this.rowKey,
|
||||
required this.timestamp,
|
||||
required this.eTag,
|
||||
});
|
||||
|
||||
factory CloudVariable.fromMap(Map map) {
|
||||
return CloudVariable(
|
||||
ownerId: map["ownerId"],
|
||||
path: map["path"],
|
||||
value: map["value"],
|
||||
partitionKey: map["partitionKey"],
|
||||
rowKey: map["rowKey"],
|
||||
timestamp: DateTime.tryParse(map["timestamp"]) ?? DateTimeX.epoch,
|
||||
eTag: map["eTag"],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue