statistics method

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

Get a photo’s statistics

Retrieve total number of downloads, views and likes of a single photo, as well as the historical breakdown of these stats in a specific time frame (default is 30 days).

See: Unsplash docs

Implementation

Request<PhotoStatistics> statistics(
  String id, {
  StatisticsResolution? resolution,
  int? quantity,
}) {
  assert(quantity == null || quantity >= 1 && quantity <= 30);

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

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

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