updateRoomSecret method

Future<void> updateRoomSecret({
  1. required String projectId,
  2. required String roomName,
  3. required String secretId,
  4. required Uint8List data,
  5. String? name,
  6. String? type,
  7. String? delegatedTo,
  8. String? forIdentity,
})

Implementation

Future<void> updateRoomSecret({
  required String projectId,
  required String roomName,
  required String secretId,
  required Uint8List data,
  String? name,
  String? type,
  String? delegatedTo,
  String? forIdentity,
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedRoomName = Uri.encodeComponent(roomName);
  final encodedSecretId = Uri.encodeComponent(secretId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/rooms/$encodedRoomName/secrets/$encodedSecretId');
  final body = <String, dynamic>{
    'data_base64': base64Encode(_normalizeSecretBytes(data)),
    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.put(uri, body: jsonEncode(body));

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to update room secret. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }
}