getUsage method

Future<Usage> getUsage({
  1. required String endDate,
  2. required String startDate,
  3. required String usagePlanId,
  4. String? keyId,
  5. int? limit,
  6. String? position,
})

Gets the usage data of a usage plan in a specified time interval.

May throw BadRequestException. May throw UnauthorizedException. May throw NotFoundException. May throw TooManyRequestsException.

Parameter endDate : Required The ending date (e.g., 2016-12-31) of the usage data.

Parameter startDate : Required The starting date (e.g., 2016-01-01) of the usage data.

Parameter usagePlanId : Required The Id of the usage plan associated with the usage data.

Parameter keyId : The Id of the API key associated with the resultant usage data.

Parameter limit : The maximum number of returned results per page. The default value is 25 and the maximum value is 500.

Parameter position : The current pagination position in the paged result set.

Implementation

Future<Usage> getUsage({
  required String endDate,
  required String startDate,
  required String usagePlanId,
  String? keyId,
  int? limit,
  String? position,
}) async {
  ArgumentError.checkNotNull(endDate, 'endDate');
  ArgumentError.checkNotNull(startDate, 'startDate');
  ArgumentError.checkNotNull(usagePlanId, 'usagePlanId');
  final $query = <String, List<String>>{
    'endDate': [endDate],
    'startDate': [startDate],
    if (keyId != null) 'keyId': [keyId],
    if (limit != null) 'limit': [limit.toString()],
    if (position != null) 'position': [position],
  };
  final response = await _protocol.send(
    payload: null,
    method: 'GET',
    requestUri: '/usageplans/${Uri.encodeComponent(usagePlanId)}/usage',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  return Usage.fromJson(response);
}