loadAd method
Implementation
Future<AdResponse> loadAd() async {
String br = "";
// Fetch patient data
Patient? patient = await DocereeAd().getPatientData();
if (patient != null) {
Map<String, dynamic> attributes = {
"attributes": patient.toJson()
};
Log("AdRequest").i(const JsonEncoder().convert(attributes));
br = Utill().encryptString(const JsonEncoder().convert(attributes));
} else {
Log("AdRequest").i("No patient found");
}
HCP? hcp = await DocereeAd().getHCPData();
Header header = Header();
Map<String, dynamic> queryParameters = {
"cdt": "TestCDT",
"hcpid": hcp?.hcpId,
"zipcode": hcp?.zipCode,
"city": hcp?.city,
"email": hcp?.email,
"lastname": hcp?.lastName,
"state": hcp?.state,
"gender": hcp?.gender,
"firstname": hcp?.firstName,
"br": br,
"adunit": adUnit,
"privacyConsent": 1,
"userid": await header.getDeviceId(),
"specialization": hcp?.specialization,
"appkey": "safaegxyzzzz",
"hashedhcpid": hcp?.hashedHcpId,
// "pb": 1,
// "requestId": "DE.V108.138353613050.1690367123-DIRECT-DSREF-1"
};
Log("AdRequest").i("headers ${header.getHeaders()}");
// Log("AdRequest").i("MapData $queryParameters");
final response = await http.post(
Uri.parse(Network.getBaseUrl() + Network.adRequestUrl),
headers: header.getHeaders(),
body: json.encode(queryParameters),
);
Log("AdRequest").i("Ad Response Body ${response.body}");
if (response.statusCode == 200) {
// If the server did return a 200 CREATED response,
// then parse the JSON.
return parseAdResponse(response.body);
} else {
// If the server did not return a 200 CREATED response,
// then throw an exception.
throw Exception('Failed to create album.');
}
}