sendBeaconEvent method

void sendBeaconEvent(
  1. TBLBeaconEvent tblBeaconEvent, {
  2. required Function onSuccess,
  3. required Function onFailure,
})

Implementation

void sendBeaconEvent(TBLBeaconEvent tblBeaconEvent,
    {required Function onSuccess, required Function onFailure}) async {
  final beaconDataQuery = await _encodeBeaconQueryParam(tblBeaconEvent);
  if (beaconDataQuery.isEmpty) {
    onFailure("Failed to encode Beacon query");
    return;
  }
  final beaconUri = await _buildBeaconUriWithQuery(
      beaconDataQuery, tblBeaconEvent.getEventType());
  if (beaconUri == null) {
    onFailure("Failed to build Beacon URI");
    return;
  }
  try {
    final response = await client.get(await beaconUri);
    if (response.statusCode == STATUS_CODE_SUCCESS) {
      onSuccess();
      TBLLogger.log(
          "response: ${response.statusCode} sent data: ${beaconDataQuery}");
    }
  } catch (e) {
    onFailure(e);
  }
}