getRandomInsights static method

Future<InsightsResult> getRandomInsights(
  1. {InsightType? type,
  2. Iterable<OpenFoodFactsCountry>? countries,
  3. String? valueTag,
  4. ServerType? serverType,
  5. int? count,
  6. UriHelper uriHelper = uriHelperRobotoffProd}
)

Implementation

static Future<InsightsResult> getRandomInsights({
  InsightType? type,
  Iterable<OpenFoodFactsCountry>? countries,
  String? valueTag,
  ServerType? serverType,
  int? count,
  final UriHelper uriHelper = uriHelperRobotoffProd,
}) async {
  final Map<String, String> parameters = {
    if (type != null) 'type': type.offTag,
    if (countries?.isNotEmpty == true)
      'countries': _getCountryList(countries!),
    if (valueTag != null) 'value_tag': valueTag,
    if (count != null) 'count': count.toString(),
    if (serverType != null) 'server_type': serverType.offTag,
  };

  var insightUri = uriHelper.getUri(
    path: 'api/v1/insights/random/',
    queryParameters: parameters,
  );

  Response response = await HttpHelper().doGetRequest(
    insightUri,
    uriHelper: uriHelper,
  );
  var result = InsightsResult.fromJson(
    HttpHelper().jsonDecode(utf8.decode(response.bodyBytes)),
  );

  return result;
}