/// <summary> /// Gets a collection of all available genres that can be used for fetching recommendations. /// </summary> /// <returns>A collection of genres as strings.</returns> public async Task <IEnumerable <string> > GetAvailableGenreSeeds() { var client = _httpClientFactory.CreateClient(); _accessToken = await GetAccessToken(client); var response = await client.GetAsync($"https://api.spotify.com/v1/recommendations/available-genre-seeds?access_token={_accessToken.Token}"); if (response.StatusCode == HttpStatusCode.OK) { dynamic content = await response.Content.ReadAsAsync <AvailableGenreSeedsResponse>(); return(content.Genres); } return(new string[0]); }
/// <summary> /// Gets recommendations from Spotify based upon provided search criteria. /// </summary> /// <param name="seeds">Search criteria used for getting recommendations.</param> /// <returns>An <see cref="RecommendationsResponse"/> containing a collection /// of <see cref="Track"/>s recommended by Spotify.</returns> public async Task <RecommendationsResponse> GetRecommendations(IEnumerable <RecommendationSeed> seeds) { var client = _httpClientFactory.CreateClient(); _accessToken = await GetAccessToken(client); var response = await client.GetAsync($"https://api.spotify.com/v1/recommendations?access_token={_accessToken.Token}{seeds.GetSeedQuery()}"); if (response.StatusCode == HttpStatusCode.OK) { dynamic content = await response.Content.ReadAsAsync <RecommendationsResponse>(); return(content); } return(new RecommendationsResponse() { Tracks = Enumerable.Empty <Track>() }); }
/// <summary> /// Sets the authorization code that is used for issueing an /// access token with Spotify. /// </summary> /// <param name="code">The authorization code provided by Spotify after /// the user has granted access.</param> public void SetAuthorizationCode(string code) { _authorizationCode = code; _accessToken = null; }