getTopAlbums method
Get the top albums for an artist on Last.fm, ordered by popularity.
Implementation
Future<List<Album>?> getTopAlbums({
String? artist,
String? mbid,
int page = 1,
int limit = 50,
}) async {
if (artist == null && mbid == null) {
return Future.error(
ScrobblenautException(
description: 'This method requires at least artist or mbid.',
),
);
}
final parameters = {
'artist': artist,
'mbid': mbid,
'page': page,
'limit': limit,
};
final request = Request(
api: _api,
method: 'artist.getTopAlbums',
parameters: parameters,
);
final response = await request.send(mode: RequestMode.GET);
final topAlbums = response['topalbums']['album'];
return topAlbums == null
? null
: List.generate(
(topAlbums as List).length,
(i) => Album.fromJson(topAlbums[i]),
);
}