callApi<T extends RequestParam, V extends ResponseParam> method

Future<ApiResponse<T, V>> callApi<T extends RequestParam, V extends ResponseParam>(
  1. T? p, {
  2. required TransmissionRpcMethod method,
  3. required RpcTag? tag,
  4. required int? timeout,
  5. V responseParamBuilder(
    1. JsonMap rawParam
    )?,
})

Implementation

Future<ApiResponse<T, V>>
    callApi<T extends RequestParam, V extends ResponseParam>(
  T? p, {
  required TransmissionRpcMethod method,
  required RpcTag? tag,
  required int? timeout,
  V Function(JsonMap rawParam)? responseParamBuilder,
}) async {
  final request = TransmissionRpcRequest(method: method, param: p, tag: tag);
  final rawData = await doRequest(request, timeout: timeout);
  final rawResult = rawData[TransmissionRpcResponseKey.result.keyName];
  final rawParam = rawData[TransmissionRpcRequestJsonKey.arguments.keyName];
  final rawTag = rawData[TransmissionRpcResponseKey.tag.keyName];
  return TransmissionRpcResponse(
    request: request,
    result: rawResult.toString(),
    param: TransmissionRpcResponse.isSucceed(rawResult) && rawParam is JsonMap
        ? responseParamBuilder?.call(rawParam)
        : null,
    tag: RpcTag.tryParse(rawTag.toString()),
  );
}