getTopAlbums method

Future<List<Album>?> getTopAlbums({
  1. required String user,
  2. Period? period,
  3. int page = 1,
  4. int limit = 50,
})

Get the top albums listened to by a user. You can stipulate a time period. Sends the overall chart by default.

NOTE: the output list is already ordered by rank.

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

Implementation

Future<List<Album>?> getTopAlbums({
  required String user,
  Period? period,
  int page = 1,
  int limit = 50,
}) async {
  final parameters = {
    'user': user,
    'period': period?.value,
    'page': page,
    'limit': limit,
  };

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

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

  final topAlbums = response['topalbums']['album'];

  return parseLastFMList<Album>(topAlbums, (i) => Album.fromJson(i));
}