count method

Future<int> count([
  1. String query = ''
])

The number of data points matching the query for this deployment.

A query using REST SQL (RSQL) can be provided.

Implementation

Future<int> count([String query = '']) async {
  String url = (query.isEmpty)
      ? "$dataEndpointUri/count"
      : "$dataEndpointUri/count?query=$query";

  http.Response response = await httpr.get(url, headers: headers);
  int httpStatusCode = response.statusCode;

  if (httpStatusCode == HttpStatus.ok) {
    print('count response = ${response.body}');
    return int.tryParse(response.body) ?? 0;
  }
  // All other cases are treated as an error.
  Map<String, dynamic> responseJson =
      json.decode(response.body) as Map<String, dynamic>;
  throw CarpServiceException(
    httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
    message: responseJson["message"].toString(),
    path: responseJson["path"].toString(),
  );
}