getProductStats static method
Returns all the ProductStats, with an optional filter.
The result can be filtered with that key
, or with key
= value
.
Implementation
static Future<List<ProductStats>> getProductStats({
final String? key,
final String? value,
final QueryType? queryType,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO
if (owner != null) {
parameters['owner'] = owner;
}
*/
if (key == null && value != null) {
throw Exception(
'Does a value have a meaning without its key? I don\'t think so.');
}
if (key != null) {
parameters['k'] = key;
}
if (value != null) {
parameters['v'] = value;
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
path: 'products/stats',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
);
_checkResponse(response);
final List<ProductStats> result = <ProductStats>[];
if (response.body == 'null') {
// not found
return result;
}
final List<dynamic> json = jsonDecode(response.body) as List<dynamic>;
for (var element in json) {
result.add(ProductStats.fromJson(element));
}
return result;
}