createRoomSecret method
Implementation
Future<String> createRoomSecret({
required String projectId,
required String roomName,
required Uint8List data,
String? secretId,
String? name,
String? type,
String? delegatedTo,
String? forIdentity,
}) async {
final encodedProjectId = Uri.encodeComponent(projectId);
final encodedRoomName = Uri.encodeComponent(roomName);
final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/rooms/$encodedRoomName/secrets');
final body = <String, dynamic>{
'data_base64': base64Encode(_normalizeSecretBytes(data)),
if (secretId != null) 'secret_id': secretId,
if (name != null) 'name': name,
if (type != null) 'type': type,
if (delegatedTo != null) 'delegated_to': delegatedTo,
if (forIdentity != null) 'for_identity': forIdentity,
};
final response = await httpClient.post(uri, body: jsonEncode(body));
if (response.statusCode >= 400) {
throw MeshagentException(
'Failed to create room secret. '
'Status code: ${response.statusCode}, body: ${response.body}',
);
}
return (jsonDecode(response.body) as Map<String, dynamic>)['id'] as String;
}