rename method

Future<void> rename(
  1. String newName
)

Rename this collection.

Implementation

Future<void> rename(String newName) async {
  // PUT the new name of this collection to the CARP web service
  final response = await service._put(
    collectionUriByID,
    body: '{"name":"$newName"}',
  );
  int httpStatusCode = response.statusCode;
  Map<String, dynamic> responseJson =
      json.decode(response.body) as Map<String, dynamic>;

  if (httpStatusCode == HttpStatus.ok) {
    int start = _path.length - _path.split('/').last.length;
    _path = _path.replaceRange(start, _path.length,
        newName); // renaming path, i.e. the last part of the path
    return;
  }
  // All other cases are treated as an error.
  throw CarpServiceException.fromMap(httpStatusCode, responseJson);
}