getSimplifiedResponse method
Gets a simplified response from the URL using cellular data connection
Implementation
Future<AuthmatechResult> getSimplifiedResponse(String url) async {
final response = await openWithDataCellular(url, true);
String authmatechCode = '';
String mnoid = '';
String errorCode = '0';
String errorDesc = 'Authmatech Code successfully fetched';
if (response.containsKey('error')) {
errorCode = '-1';
errorDesc = response['error_description'] ?? 'Unknown error';
} else {
final responseBody = response['response_body'];
if (responseBody != null) {
authmatechCode = responseBody['authmatechCode'] ?? '';
mnoid = responseBody['MNOID'] ?? '';
errorCode = responseBody['errorCode'] ?? '0';
errorDesc = responseBody['errorDesc'] ?? 'Authmatech Code successfully fetched';
} else {
final debug = response['debug'];
if (debug != null && debug['url_trace'] != null) {
final urlTrace = debug['url_trace'];
final RegExp jsonPattern = RegExp(r'\{.*\}');
final match = jsonPattern.firstMatch(urlTrace);
if (match != null) {
try {
final extractedJson = json.decode(match.group(0)!);
if (extractedJson['authmatechCode'] != null) authmatechCode = extractedJson['authmatechCode'];
if (extractedJson['MNOID'] != null) mnoid = extractedJson['MNOID'];
if (extractedJson['errorCode'] != null) errorCode = extractedJson['errorCode'];
if (extractedJson['errorDesc'] != null) errorDesc = extractedJson['errorDesc'];
} catch (e) {
print('Failed to parse JSON from URL trace: $e');
}
}
}
}
}
return AuthmatechResult(
authmatechCode: authmatechCode,
MNOID: mnoid,
errorCode: errorCode,
errorDesc: errorDesc,
);
}