postReview method

Future<Response<Review>> postReview({
  1. required String xKeyclicApp,
  2. required ReviewData reviewData,
  3. String? acceptLanguage,
  4. DateTime? xDateTime,
  5. String? xKeyclicAppPlatform,
  6. String? xKeyclicAppVersion,
  7. CancelToken? cancelToken,
  8. Map<String, dynamic>? headers,
  9. Map<String, dynamic>? extra,
  10. ValidateStatus? validateStatus,
  11. ProgressCallback? onSendProgress,
  12. ProgressCallback? onReceiveProgress,
})

Create one Review resource.

Parameters:

  • xKeyclicApp
  • reviewData
  • acceptLanguage
  • xDateTime
  • xKeyclicAppPlatform
  • xKeyclicAppVersion
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a Review as data Throws DioError if API call or serialization fails Keyclic API documentation. Also see Create one Review resource. Documentation

Implementation

Future<Response<Review>> postReview({
  required String xKeyclicApp,
  required ReviewData reviewData,
  String? acceptLanguage,
  DateTime? xDateTime,
  String? xKeyclicAppPlatform,
  String? xKeyclicAppVersion,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final String path = r'/reviews';
  final options = Options(
    method: r'POST',
    headers: <String, dynamic>{
      // to string ??
      if (acceptLanguage != null) r'accept-language': acceptLanguage,
      if (xDateTime != null) r'x-date-time': xDateTime,
      r'x-keyclic-app': xKeyclicApp,
      if (xKeyclicAppPlatform != null)
        r'x-keyclic-app-platform': xKeyclicAppPlatform,
      if (xKeyclicAppVersion != null)
        r'x-keyclic-app-version': xKeyclicAppVersion,
      ...?headers,
    },
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'apiKey',
          'name': 'bearer',
          'keyName': 'Authorization',
          'where': 'header',
        },
      ],
      ...?extra,
    },
    contentType: 'application/json;charset=UTF-8',
    validateStatus: validateStatus,
  );

  dynamic bodyData;

  try {
    bodyData = reviewData.toJson();
    // bodyData = jsonEncode(reviewData);
    // bodyData = jsonDecode(jsonEncode(reviewData));
  } catch (error, stackTrace) {
    throw DioError(
      requestOptions: options.compose(
        _apiClient.dio.options,
        path,
      ),
      type: DioErrorType.other,
      error: error,
    )..stackTrace = stackTrace;
  }

  final response = await _apiClient.dio.request<Object>(
    path,
    data: bodyData,
    options: options,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  Review responseData;

  try {
    responseData =
        await _apiClient.deserializeAsync<Review>(response.data!, 'Review');
  } catch (error, stackTrace) {
    throw DioError(
      requestOptions: response.requestOptions,
      response: response,
      type: DioErrorType.other,
      error: error,
    )..stackTrace = stackTrace;
  }

  return Response<Review>(
    data: responseData,
    headers: response.headers,
    isRedirect: response.isRedirect,
    requestOptions: response.requestOptions,
    redirects: response.redirects,
    statusCode: response.statusCode,
    statusMessage: response.statusMessage,
    extra: response.extra,
  );
}