generateMobileInsightV2 static method
Implementation
static Future<PericulumResponse?> generateMobileInsightV2({
required String publicKey,
String? phoneNumber,
String? bvn,
}) async {
try {
final senderAddress = await getSenderAddress(publicKey: publicKey);
final String response =
await _channel.invokeMethod('generateMobileDataAnalysis', {
"publicKey": publicKey,
'phoneNumber': phoneNumber,
"bvn": bvn,
});
Periculum data = periculumFromJson(response.toString());
List<Datum> unfilteredSMS = [];
List<Datum> filteredSMS = [];
unfilteredSMS = data.sms.data;
for (int i = 0; i < senderAddress.length; i++) {
for (var smses in unfilteredSMS) {
if (smses.address
.toLowerCase()
.contains(senderAddress[i].address.toLowerCase())) {
filteredSMS.add(smses);
}
}
}
Sms filterSMS = Sms(count: filteredSMS.length, data: filteredSMS);
Periculum filteredData = Periculum(
appName: data.appName,
bundleId: data.bundleId,
device: data.device,
metadata: data.metadata,
publicKey: publicKey,
sms: filterSMS,
statementName: data.statementName,
version: data.version);
var url = Uri.parse('$baseUrl/mobile/insights/v2');
var call = await http.post(url,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: json.encode(filteredData.toJson()));
switch (call.statusCode) {
case 200:
OverviewKey? overviewKey = overviewKeyFromJson(call.body.toString());
(call.body.toString());
return PericulumResponse(
mobileInsightsOverviewKey: overviewKey.mobileInsightsOverviewKey,
statusCode: call.statusCode,
status: true);
case 401:
return PericulumResponse(
mobileInsightsOverviewKey: null,
statusCode: call.statusCode,
status: false,
message: 'Invalid publicKey');
case 400:
return PericulumResponse(
mobileInsightsOverviewKey: null,
statusCode: call.statusCode,
status: false,
message:
'There is already an Insights with the unique id provided. Please use the PATCH endpoint to update the existing Insights.');
default:
return PericulumResponse(
mobileInsightsOverviewKey: null,
statusCode: call.statusCode,
status: false,
message: call.body.toString());
}
} on PlatformException catch (e) {
throw e.message.toString();
}
}