Пример #1
0
        public async Task <IEnumerable <ArtistDto> > GetArtists(string query)
        {
            var parameters = new[]
            {
                FormatJson, $"query={HttpUtility.UrlEncode(query)}"
            };

            try
            {
                var requestUri        = $"{BaseAddress}{ArtistEntityString}?{string.Join('&', parameters)}";
                var apiResponseString = await _serviceCaller.GetApiResponseString(requestUri);

                var result = JsonConvert.DeserializeObject <ArtistQueryResult>(apiResponseString);

                var matchingArtists = result.artists.Where(x => x.score > ArtistSearchScoreThreshold);
                return(matchingArtists.Select(x => new ArtistDto(x)));
            }
            catch (JsonReaderException)
            {
                return(Enumerable.Empty <ArtistDto>());
            }
        }
Пример #2
0
        public async Task <LyricsDto> GetLyrics(string artist, string title)
        {
            try
            {
                var requestUri           = $"{BaseAddress}{artist}/{title}";
                var lyricsResponseString = await _serviceCaller.GetApiResponseString(requestUri);

                var result = JsonConvert.DeserializeObject <LyricsQueryResult>(lyricsResponseString);
                return(new LyricsDto(result));
            }
            catch (JsonReaderException)
            {
                return(null);
            }
        }