Esempio n. 1
0
        /// <summary>
        /// Creates a playlist View Model
        /// </summary>
        /// <param name="spotifyRecommendationResponse"></param>
        /// <returns>PlaylistVM</returns>
        public static PlaylistVM CreateViewModel(SpotifyRecommendationResponse spotifyRecommendationResponse)
        {
            PlaylistVM response = new PlaylistVM();

            response.Playlist = spotifyRecommendationResponse.Tracks.Select(t => t.Name).ToList();
            return(response);
        }
        /// <summary>
        /// Service responsible to Request Playlist tracks from Spotify
        /// </summary>
        /// <param name="spotifyToken"></param>
        /// <param name="temperature"></param>
        public async Task <DomainResponse> GetPlaylistAsync(string spotifyToken, double temperature)
        {
            SpotifyRecommendationResponse spotifyRecommendationResponse = null;

            try
            {
                string genre = GetGenreByTemperature(temperature);

                Dictionary <string, string> header = new Dictionary <string, string>();
                header.Add("Authorization", "Bearer " + spotifyToken);

                spotifyRecommendationResponse = await new ApiWrapper("SpotifyRecommendations").GetAsync <SpotifyRecommendationResponse>($"recommendations?seed_genres={genre}", header);
            }
            catch (Exception ex)
            {
                AddBusinessInfo("NO_INTERNET");
                Logger.Error(ex, ex.Message);
            }
            return(Response(spotifyRecommendationResponse));
        }