callApi<T extends RequestParam, V extends ResponseParam> method
Future<ApiResponse<T, V> >
callApi<T extends RequestParam, V extends ResponseParam>(
- T? p, {
- required TransmissionRpcMethod method,
- required RpcTag? tag,
- required int? timeout,
- V responseParamBuilder(
- 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()),
);
}