submitShortAnswers method
Future<FlipSubmitShortAnswersResponse>
submitShortAnswers(
- ValidationSessionInfo validationSessionInfo
Implementation
Future<FlipSubmitShortAnswersResponse> submitShortAnswers(
ValidationSessionInfo validationSessionInfo) async {
Completer<FlipSubmitShortAnswersResponse> _completer =
new Completer<FlipSubmitShortAnswersResponse>();
if (validationSessionInfo == null) {
_completer.complete(null);
return _completer.future;
}
FlipSubmitShortAnswersRequest flipSubmitShortAnswersRequest =
new FlipSubmitShortAnswersRequest();
FlipSubmitShortAnswersResponse flipSubmitShortAnswersResponse;
try {
ParamShortAnswer answers = new ParamShortAnswer();
List<ShortAnswer> listAnswers = List<ShortAnswer>.empty(growable: true);
for (int i = 0;
i < validationSessionInfo.listSessionValidationFlips.length;
i++) {
ShortAnswer answer = new ShortAnswer(
answer:
validationSessionInfo.listSessionValidationFlips[i].answerType,
hash: validationSessionInfo.listSessionValidationFlips[i].hash);
listAnswers.add(answer);
}
answers.epoch = 0;
answers.nonce = 0;
answers.answers = listAnswers;
List<ParamShortAnswer> params =
List<ParamShortAnswer>.empty(growable: true);
params.add(answers);
flipSubmitShortAnswersRequest.method =
FlipSubmitShortAnswersRequest.METHOD_NAME;
flipSubmitShortAnswersRequest.params = params;
flipSubmitShortAnswersRequest.id = 101;
flipSubmitShortAnswersRequest.key = keyApp;
if (this.nodeType == NORMAL_VPS_NODE) {
SSHClientStatus sshClientStatus;
sshClientStatus = await VpsUtil().connectVps(apiUrl, keyApp);
if (sshClientStatus.sshClientStatus) {
sshClient = sshClientStatus.sshClient;
}
var response = await ssh.HttpClientImpl(
clientFactory: () =>
ssh.SSHTunneledBaseClient(sshClientStatus.sshClient)).request(
apiUrl,
method: 'POST',
data: jsonEncode(mapParams),
headers: requestHeaders);
if (response.status == 200) {
flipSubmitShortAnswersResponse =
flipSubmitShortAnswersResponseFromJson(response.text);
}
} else {
body = json.encode(flipSubmitShortAnswersRequest.toJson());
logger.i(new JsonEncoder.withIndent(' ')
.convert(flipSubmitShortAnswersRequest));
responseHttp = await http.post(Uri.parse(this.apiUrl),
body: body, headers: requestHeaders);
if (responseHttp.statusCode == 200) {
flipSubmitShortAnswersResponse =
flipSubmitShortAnswersResponseFromJson(responseHttp.body);
}
}
} catch (e) {
logger.e(e.toString());
}
_completer.complete(flipSubmitShortAnswersResponse);
return _completer.future;
}