putDirectory method

Future<Response> putDirectory(
  1. String path, {
  2. Map<String, String> additionalHeaderFields = const <String, String>{},
  3. required Map<String, dynamic> jsonBody,
})

Generates an authorized PUT to the S3I-Directory.

The path should starts with a / and the jsonBody should be a valid ditto entry. For more information see https://dir.s3i.vswf.dev/apidoc/#. If you need to add additional information to the header (e.g. ETag), use additionalHeaderFields.

Throws a FormatException if the path could not be parsed to a valid Uri. Throws a NetworkAuthenticationException if AuthenticationManager.getAccessToken throws an exception. If there is no internet connection available a SocketException is thrown.

Implementation

Future<Response> putDirectory(String path,
    {Map<String, String> additionalHeaderFields = const <String, String>{},
    required Map<String, dynamic> jsonBody}) async {
  String originalToken = '';
  try {
    final AccessToken token = await authManager.getAccessToken();
    originalToken = token.originalToken;
  } on Exception catch (e) {
    throw NetworkAuthenticationException(e);
  }
  final Map<String, String> headers = <String, String>{
    'Content-Type': 'application/json'
  }
    ..addAll(<String, String>{'Authorization': 'Bearer $originalToken'})
    ..addAll(additionalHeaderFields);
  return Client().put(Uri.parse(directoryUrl + path),
      headers: headers, body: utf8.encode(jsonEncode(jsonBody)));
}