getEventsCount static method

Future<Map<String, int>> getEventsCount({
  1. String? userId,
  2. String? deviceId,
  3. UriHelper uriHelper = uriHelperEventsProd,
})

Returns all the events counts, with optional filters.

Implementation

static Future<Map<String, int>> getEventsCount({
  final String? userId,
  final String? deviceId,
  final UriHelper uriHelper = uriHelperEventsProd,
}) async {
  final Map<String, String> parameters = <String, String>{};
  if (userId != null) {
    parameters['user_id'] = userId;
  }
  if (deviceId != null) {
    parameters['device_id'] = deviceId;
  }
  final Response response = await HttpHelper().doGetRequest(
    uriHelper.getUri(
      path: '/events/count',
      queryParameters: parameters,
    ),
    uriHelper: uriHelper,
  );
  _checkResponse(response);
  final Map<String, int> result = <String, int>{};
  final Map<String, dynamic> json =
      HttpHelper().jsonDecode(response.body) as Map<String, dynamic>;
  for (final String key in json.keys) {
    result[key] = json[key] as int;
  }
  return result;
}