setOutOfOfficeRaw method

  1. @experimental
DynamiteRawResponse<OutOfOfficeSetOutOfOfficeResponseApplicationJson, void> setOutOfOfficeRaw({
  1. required String firstDay,
  2. required String lastDay,
  3. required String status,
  4. required String message,
  5. required String userId,
  6. bool? oCSAPIRequest,
})

Set out-of-office absence.

This method and the response it returns is experimental. The API might change without a major version bump.

Returns a Future containing a DynamiteRawResponse with the raw HttpClientResponse and serialization helpers. Throws a DynamiteApiException if the API call does not return an expected status code.

Parameters:

  • firstDay First day of the absence in format YYYY-MM-DD.
  • lastDay Last day of the absence in format YYYY-MM-DD.
  • status Short text that is set as user status during the absence.
  • message Longer multiline message that is shown to others during the absence.
  • userId
  • oCSAPIRequest Required to be true for the API request to pass. Defaults to true.

Status codes:

  • 200: Absence data
  • 400: When the first day is not before the last day
  • 401: When the user is not logged in

See:

Implementation

@experimental
DynamiteRawResponse<OutOfOfficeSetOutOfOfficeResponseApplicationJson, void> setOutOfOfficeRaw({
  required String firstDay,
  required String lastDay,
  required String status,
  required String message,
  required String userId,
  bool? oCSAPIRequest,
}) {
  final _parameters = <String, dynamic>{};
  final _headers = <String, String>{
    'Accept': 'application/json',
  };

// coverage:ignore-start
  final authentication = _rootClient.authentications.firstWhereOrNull(
    (auth) => switch (auth) {
      DynamiteHttpBearerAuthentication() || DynamiteHttpBasicAuthentication() => true,
      _ => false,
    },
  );

  if (authentication != null) {
    _headers.addAll(
      authentication.headers,
    );
  } else {
    throw Exception('Missing authentication for bearer_auth or basic_auth');
  }

// coverage:ignore-end
  final $firstDay = jsonSerializers.serialize(firstDay, specifiedType: const FullType(String));
  _parameters['firstDay'] = $firstDay;

  final $lastDay = jsonSerializers.serialize(lastDay, specifiedType: const FullType(String));
  _parameters['lastDay'] = $lastDay;

  final $status = jsonSerializers.serialize(status, specifiedType: const FullType(String));
  _parameters['status'] = $status;

  final $message = jsonSerializers.serialize(message, specifiedType: const FullType(String));
  _parameters['message'] = $message;

  final $userId = jsonSerializers.serialize(userId, specifiedType: const FullType(String));
  _parameters['userId'] = $userId;

  var $oCSAPIRequest = jsonSerializers.serialize(oCSAPIRequest, specifiedType: const FullType(bool));
  $oCSAPIRequest ??= true;
  _headers['OCS-APIRequest'] = const dynamite_utils.HeaderEncoder().convert($oCSAPIRequest);

  final _path = UriTemplate('/ocs/v2.php/apps/dav/api/v1/outOfOffice/{userId}{?firstDay*,lastDay*,status*,message*}')
      .expand(_parameters);
  return DynamiteRawResponse<OutOfOfficeSetOutOfOfficeResponseApplicationJson, void>(
    response: _rootClient.executeRequest(
      'post',
      _path,
      _headers,
      null,
      const {200},
    ),
    bodyType: const FullType(OutOfOfficeSetOutOfOfficeResponseApplicationJson),
    headersType: null,
    serializers: jsonSerializers,
  );
}