getWeeklyArtistChart method

Future<List<Artist>?> getWeeklyArtistChart({
  1. required String user,
  2. DateTime? fromDate,
  3. DateTime? toDate,
})

Get an artist chart for a user profile, for a given date range. If no date range is supplied, it will return the most recent artist chart for this user.

NOTE: the output list is already ordered by rank.

https://www.last.fm/api/show/user.getWeeklyArtistChart

Implementation

Future<List<Artist>?> getWeeklyArtistChart({
  required String user,
  DateTime? fromDate,
  DateTime? toDate,
}) async {
  final parameters = {
    'user': user,
    'from': LastFMValueNormalizer.DateTimeToUnixTime(fromDate),
    'to': LastFMValueNormalizer.DateTimeToUnixTime(toDate),
  };

  // TODO: is the rank necessary!?

  final request = Request(
    api: _api,
    method: 'user.getWeeklyArtistChart',
    parameters: parameters,
  );

  final response = await request.send(mode: RequestMode.GET);

  final weeklyArtistChart = response['weeklyartistchart']['artist'];

  return weeklyArtistChart == null
      ? null
      : List.generate(
          (weeklyArtistChart as List).length,
          (i) => Artist.fromJson(weeklyArtistChart[i]),
        );
}