getBadges static method

Future<List<BadgeBase>> getBadges({
  1. String? userId,
  2. String? deviceId,
  3. UriHelper uriHelper = uriHelperEventsProd,
})

Returns all the BadgeBase, with optional filters.

Implementation

static Future<List<BadgeBase>> getBadges({
  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: '/badges',
      queryParameters: parameters,
    ),
    uriHelper: uriHelper,
  );
  _checkResponse(response);
  final List<BadgeBase> result = <BadgeBase>[];
  final List<dynamic> json =
      HttpHelper().jsonDecode(response.body) as List<dynamic>;
  for (var element in json) {
    result.add(BadgeBase.fromJson(element));
  }
  return result;
}