sendActivateBatch method

Future<ActivateResopnse> sendActivateBatch(
  1. List<Hit> listOfActivate
)

Implementation

Future<ActivateResopnse> sendActivateBatch(List<Hit> listOfActivate) async {
  // Create url
  String urlString = Endpoints.DECISION_API + Endpoints.ACTIVATION;
  // Create an activate batch object
  ActivateBatch activateBatch = ActivateBatch(listOfActivate);

  // List exposure to send when succeed
  List<FSExposedInfo> listExposure = [];

  // Encode batch before send it
  try {
    Object? objectToSend = jsonEncode(activateBatch.toJson());
    var response = await service.sendHttpRequest(RequestType.Post, urlString,
        Endpoints.getFSHeader(this.apiKey), objectToSend,
        timeoutMs: TIMEOUT_REQUEST);
    switch (response.statusCode) {
      case 200:
      case 204:
        Flagship.logger(Level.INFO, ACTIVATE_SUCCESS + ": $objectToSend");
        onSendActivateBatchWithSuccess(listOfActivate);
        // Fill the list exposure
        this.onExposure(activateBatch.getExposureInfos());
        // Return the response
        return ActivateResopnse(listExposure, response.statusCode);
      default:
        Flagship.logger(Level.ERROR, HIT_FAILED);
        DataUsageTracking.sharedInstance().processTroubleShootingHttp(
            CriticalPoints.SEND_ACTIVATE_HIT_ROUTE_ERROR.name, response);
        return ActivateResopnse(listExposure, response.statusCode);
    }
  } on Exception catch (e) {
    DataUsageTracking.sharedInstance()
        .processTroubleShootingException(null, e);
    activateDelegate?.onFailedToSendBatch(listOfActivate);
    Flagship.logger(
        Level.EXCEPTIONS, EXCEPTION.replaceFirst("%s", "$e") + urlString);
    Flagship.logger(Level.ERROR, HIT_FAILED);
    return ActivateResopnse([], 500);
  }
}