get method
Generates a list of size limit
of tracks based on
seedArtists
, seedGenres
, seedTracks
spotify IDs
min
max
and target
sets Tunable Track attributes limitations
(see https://developer.spotify.com/documentation/web-api/reference/browse/get-recommendations/)
Implementation
Future<Recommendations> get(
{Iterable<String>? seedArtists,
Iterable<String>? seedGenres,
Iterable<String>? seedTracks,
int limit = 20,
Market? market,
Map<String, num>? max,
Map<String, num>? min,
Map<String, num>? target}) async {
assert(limit >= 1 && limit <= 100, 'limit should be 1 <= limit <= 100');
final seedsNum = (seedArtists?.length ?? 0) +
(seedGenres?.length ?? 0) +
(seedTracks?.length ?? 0);
assert(
seedsNum >= 1 && seedsNum <= 5,
'Up to 5 seed values may be provided in any combination of seed_artists,'
' seed_tracks and seed_genres.');
final parameters = <String, String>{'limit': limit.toString()};
final _ = {
'seed_artists': seedArtists,
'seed_genres': seedGenres,
'seed_tracks': seedTracks
}.forEach((key, list) => _addList(parameters, key, list!));
if (market != null) parameters['market'] = market.name;
for (var map in [min, max, target]) {
_addTunableTrackMap(parameters, map);
}
final pathQuery = Uri(path: _path, queryParameters: parameters)
.toString()
.replaceAll(RegExp(r'%2C'), ',');
final result = jsonDecode(await _api._get(pathQuery));
return Recommendations.fromJson(result);
}