sendBatch method

Future<void> sendBatch(
  1. List<Hit> listOfHitToSend
)

Implementation

Future<void> sendBatch(List<Hit> listOfHitToSend) async {
  // Create url
  String urlString = Endpoints.EVENT;
  Flagship.logger(Level.DEBUG, 'Sending hits using batch : ' + urlString);

  try {
    var response = await service.sendHttpRequest(
        RequestType.Post,
        urlString,
        Endpoints.getFSHeader(this.apiKey),
        jsonEncode(Batch(listOfHitToSend).bodyTrack),
        timeoutMs: TIMEOUT_REQUEST);
    switch (response.statusCode) {
      case 200:
      case 204:
      case 201:
        Flagship.logger(Level.INFO, HIT_SUCCESS);
        onSendBatchWithSuccess(listOfHitToSend);
        break;
      default:
        Flagship.logger(Level.ERROR, HIT_FAILED);
        hitDelegate?.onFailedToSendBatch(listOfHitToSend);
        DataUsageTracking.sharedInstance().processTroubleShootingHttp(
            CriticalPoints.SEND_BATCH_HIT_ROUTE_RESPONSE_ERROR.name,
            response);
    }
  } catch (error) {
    DataUsageTracking.sharedInstance()
        .processTroubleShootingException(null, error);
    hitDelegate?.onFailedToSendBatch(listOfHitToSend);
    Flagship.logger(
        Level.EXCEPTIONS, EXCEPTION.replaceFirst("%s", "$error") + urlString);
    Flagship.logger(Level.ERROR, HIT_FAILED);
  }
}