public async Task <Album> GetInfoAsync(string artistName, string albumName)
        {
            if (artistName == null)
            {
                return(null);
            }
            if (albumName == null)
            {
                return(null);
            }

            string         artistGetInfosURL = $"/2.0/?method=album.getInfo&artist={artistName}&album={albumName}&api_key={_lastFMCredentials.APIKey}&format=json";
            LastFMResponse lastFMResponse    = Query(artistGetInfosURL).Result;
            string         jsonString        = await lastFMResponse.Message;

            if (!lastFMResponse.IsSuccessful)
            {
                GetErrorResponse error = GetErrorResponse.FromJson(jsonString);
                throw new DataAccessException($"Could not get user info ({error.Message})");
            }

            GetAlbumInfosResponse albumResponse = GetAlbumInfosResponse.FromJson(jsonString);

            Album album = _mapper.Map <Album>(albumResponse.Album);

            return(album);
        }
Esempio n. 2
0
        public async Task <IEnumerable <Track> > GetTopTracksAsync(string searchedArtist, int limit = 10)
        {
            if (searchedArtist == null)
            {
                return(null);
            }

            string         artistGetSimilarURL = $"/2.0/?method=artist.getTopTracks&artist={searchedArtist}&limit={limit}&api_key={_lastFMCredentials.APIKey}&format=json";
            LastFMResponse lastFMResponse      = Query(artistGetSimilarURL).Result;
            string         jsonString          = await lastFMResponse.Message;

            if (!lastFMResponse.IsSuccessful)
            {
                GetErrorResponse error = GetErrorResponse.FromJson(jsonString);
                throw new DataAccessException($"Could not get user info ({error.Message})");
            }

            GetArtistTopTracksResponse artistResponse = GetArtistTopTracksResponse.FromJson(jsonString);

            IEnumerable <Track> artists = _mapper.Map <IEnumerable <Track> >(artistResponse.TopTracks.Tracks);

            return(artists);
        }
Esempio n. 3
0
        public async Task <Artist> GetInfoAsync(string searchedArtist)
        {
            if (searchedArtist == null)
            {
                return(null);
            }

            string         artistGetInfosURL = $"/2.0/?method=artist.getinfo&artist={searchedArtist}&api_key={_lastFMCredentials.APIKey}&format=json";
            LastFMResponse lastFMResponse    = Query(artistGetInfosURL).Result;
            string         jsonString        = await lastFMResponse.Message;

            if (!lastFMResponse.IsSuccessful)
            {
                GetErrorResponse error = GetErrorResponse.FromJson(jsonString);
                throw new DataAccessException($"Could not get user info ({error.Message})");
            }

            GetArtistInfosResponse artistResponse = GetArtistInfosResponse.FromJson(jsonString);

            Artist artist = _mapper.Map <Artist>(artistResponse.Artist);

            return(artist);
        }