public async Task <IActionResult> SearchTrackAsync(string artist, string track) { var tokenEntity = await _accessTokenRepository.GetAccessToken(); tokenEntity = _accessTokenRepository.ValidateToken(tokenEntity); if (string.IsNullOrEmpty(tokenEntity.Token)) { return(Unauthorized()); } var query = $"q=track:\"{track}\"%20artist:\"{artist}\"&type=track"; query = System.Web.HttpUtility.UrlEncode(query); // Set bearer auth var client = _authService.GetClientWithBearerAuth(tokenEntity); var response = await client.GetAsync($"{_trackUriBase}?{query}"); if (!response.IsSuccessStatusCode) { return(BadRequest()); } var content = await response.Content.ReadAsStringAsync(); var trackOverview = JsonConvert.DeserializeObject <TrackOverview>(content); //_logger.Log(trackOverview.tracks.items[0].uri); return(Ok(trackOverview)); }
public async Task <ActionResult> GetPlaylistsAsync() { var tokenEntity = await _accessTokenRepository.GetAccessToken(); tokenEntity = _accessTokenRepository.ValidateToken(tokenEntity); if (string.IsNullOrEmpty(tokenEntity.Token)) { return(Unauthorized()); } // Set bearer auth var client = _authService.GetClientWithBearerAuth(tokenEntity); var response = await client.GetAsync($"{_playlistUriBase}{_playlistUri}"); var playlistsString = await response.Content.ReadAsStringAsync(); return(Ok(JsonConvert.DeserializeObject <PlaylistOverview>(playlistsString))); }