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>()); } }
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); } }