Пример #1
0
        public async Task <SongsModel> GetListSongsBasedCategory(string category)
        {
            var    list      = new SongsModel();
            string url       = "/v1/playlists/{0}/tracks";
            var    playLists = await _categoryModule.GetPlayLists(category);

            var httpClient = await _authenticationModule.GetHttpClient();

            foreach (var playlist in playLists)
            {
                string urlFormatted = String.Format(url, playlist.Id);
                var    response     = await httpClient.GetAsync(urlFormatted);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    var tracks = JsonConvert.DeserializeObject <TracksModel>(json);
                    foreach (var track in tracks.Items)
                    {
                        list.Songs.Add(new SongReducedModel
                        {
                            SongId    = track.Track.Id,
                            SongTitle = track.Track.Name
                        });
                    }
                }
            }

            return(list);
        }
        public async Task <IList <PlayListItem> > GetPlayLists(string category)
        {
            var httpClient = await _authenticationModule.GetHttpClient();

            string url      = "/v1/browse/categories/" + category + "/playlists?limit=1";
            var    response = await httpClient.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var result = JsonConvert.DeserializeObject <PlayListsModel>(json);
                return(result.Playlists.Items);
            }
            else
            {
                return(null);
            }
        }