postData method

Future<void> postData(
  1. String adBlockLevel,
  2. String adUnitId
)

Implementation

Future<void> postData(String adBlockLevel, String adUnitId) async {

  // Create an instance of AdBlock class
  AdBlock adBlock = AdBlock(advertiserCampID: "advertiserCampID", blockLevel: adBlockLevel, platformUid: "platformUid", publisherACSID: adUnitId);

  // Convert the adBlock object to JSON
  String jsonBody = json.encode(adBlock.toJson());

  // Make the post request
  try {
    final response = await http.post(
      Uri.parse(Network.getBaseUrl() + Network.sendAdBlockInfo),
      headers: {
        'Content-type': 'application/json',
      },
      body: jsonBody,
    );

    Log("AdBlockApi").i('Response: ${response.body}');
    if (response.statusCode == 200) {
      // Request was successful
      Log("AdBlockApi").i('Status Code: ${response.statusCode}');
    } else {
      // Request failed
      Log("AdBlockApi").i('Status Code: ${response.statusCode}');
    }
  } catch (error) {
    // Handle errors
    Log("AdBlockApi").i('Error: $error');
  }
}