statistics method

Request<UserStatistics> statistics(
  1. String username, {
  2. StatisticsResolution? resolution,
  3. int? quantity,
})

Get a user’s statistics

Retrieve the consolidated number of downloads, views and likes of all user’s photos, as well as the historical breakdown and average of these stats in a specific time frame (default is 30 days).

See: Unsplash docs

Implementation

Request<UserStatistics> statistics(
  String username, {
  StatisticsResolution? resolution,
  int? quantity,
}) {
  assert(quantity == null || quantity >= 0);

  final params = queryParams({
    'resolution': resolution?.let(enumName),
    'quantity': quantity,
  });

  final url = baseUrl
      .resolve('$username/statistics')
      .replace(queryParameters: params);

  return Request(
    client: client,
    httpRequest: http.Request('GET', url),
    isPublicAction: true,
    bodyDeserializer: (dynamic json) =>
        UserStatistics.fromJson(json as Map<String, dynamic>),
  );
}