submitLongAnswers method
Future<FlipSubmitLongAnswersResponse>
submitLongAnswers(
- ValidationSessionInfo validationSessionInfo
Implementation
Future<FlipSubmitLongAnswersResponse> submitLongAnswers(
ValidationSessionInfo validationSessionInfo) async {
Completer<FlipSubmitLongAnswersResponse> _completer =
new Completer<FlipSubmitLongAnswersResponse>();
if (validationSessionInfo == null) {
_completer.complete(null);
return _completer.future;
}
FlipSubmitLongAnswersRequest flipSubmitLongAnswersRequest =
new FlipSubmitLongAnswersRequest();
FlipSubmitLongAnswersResponse flipSubmitLongAnswersResponse;
bool wrongWordsBool;
try {
ParamLongAnswer answers = new ParamLongAnswer();
List<LongAnswer> listAnswers = List<LongAnswer>.empty(growable: true);
for (int i = 0;
i < validationSessionInfo.listSessionValidationFlips.length;
i++) {
wrongWordsBool = true;
if (validationSessionInfo.listSessionValidationFlips[i] != null &&
validationSessionInfo.listSessionValidationFlips[i].relevanceType ==
RelevantType.RELEVANT) {
wrongWordsBool = false;
}
LongAnswer answer = new LongAnswer(
answer:
validationSessionInfo.listSessionValidationFlips[i].answerType,
wrongWords: wrongWordsBool,
hash: validationSessionInfo.listSessionValidationFlips[i].hash);
listAnswers.add(answer);
}
answers.epoch = 0;
answers.nonce = 0;
answers.answers = listAnswers;
List<ParamLongAnswer> params =
List<ParamLongAnswer>.empty(growable: true);
params.add(answers);
flipSubmitLongAnswersRequest.method =
FlipSubmitLongAnswersRequest.METHOD_NAME;
flipSubmitLongAnswersRequest.params = params;
flipSubmitLongAnswersRequest.id = 101;
flipSubmitLongAnswersRequest.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) {
flipSubmitLongAnswersResponse =
flipSubmitLongAnswersResponseFromJson(response.text);
}
} else {
body = json.encode(flipSubmitLongAnswersRequest.toJson());
logger.i(new JsonEncoder.withIndent(' ')
.convert(flipSubmitLongAnswersRequest));
responseHttp = await http.post(Uri.parse(this.apiUrl),
body: body, headers: requestHeaders);
if (responseHttp.statusCode == 200) {
flipSubmitLongAnswersResponse =
flipSubmitLongAnswersResponseFromJson(responseHttp.body);
}
}
} catch (e) {
logger.e(e.toString());
}
_completer.complete(flipSubmitLongAnswersResponse);
return _completer.future;
}