Example #1
0
        /// <summary>
        /// Allows you to get an <see cref="Artist"/>/<see cref="Album"/>/<see cref="Track"/> by a known identifier. 
        /// </summary>
        /// <param name="id">The ID to search for. Must start with "music."</param>
        /// <param name="options"></param>
        /// <returns>A <see cref="ContentResponse"/> object populated with results from the Xbox Music service.</returns>
        public async Task<ContentResponse> Get(string id, LookupOptions options = null)
        {
            if (string.IsNullOrWhiteSpace(id))
                throw new ArgumentNullException("id", "You must specify an ID");

            return await Get(new List<string> {id}, options);
        }
Example #2
0
        /// <summary>
        /// Allows you to get multiple <see cref="Artist">Artists</see>/<see cref="Album">Albums</see>/<see cref="Track">Tracks</see> by known identifiers. 
        /// </summary>
        /// <param name="ids">A List of IDs to search for. Must start with "music."</param>
        /// <param name="options">Optional. A <see cref="LookupOptions"/> instance with details on what additional information should be returned.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <returns>A <see cref="ContentResponse"/> object populated with results from the Xbox Music service.</returns>
        public async Task<ContentResponse> Get(List<string> ids, LookupOptions options = null)
        {
            if (ids == null)
                throw new ArgumentNullException("ids", "You must pass in a list of IDs to lookup.");

            if (ids.Count == 0)
                throw new ArgumentOutOfRangeException("ids", "The list of IDs to lookup cannot be empty.");

            await CheckToken();

            var request = GetPopulatedRequest("1/content/{ids}/lookup");
            request.AddUrlSegment("ids", ids.Aggregate("", (c, n) => c.Length == 0 ? c += n : c += "+" + n));

            if (options != null)
            {
                var extras = new List<string>();
                if (options.GetArtistAlbums)
                {
                    extras.Add("albums");
                }
                if (options.GetArtistTopTracks)
                {
                    extras.Add("topTracks");
                }
                if (options.GetAlbumTracks)
                {
                    extras.Add("tracks");
                }
                if (options.GetAlbumArtistDetails || options.GetTrackArtistDetails)
                {
                    extras.Add("artistDetails");
                }
                if (options.GetTrackAlbumDetails)
                {
                    extras.Add("albumDetails");
                }
                request.AddQueryString("extras", extras.Aggregate("", (c, n) => c.Length == 0 ? c += n : c += "+" + n));
            }

            request.AddQueryString("accessToken", "Bearer " + TokenResponse.AccessToken);
            
            return await ExecuteAsync<ContentResponse>(request);
        }
Example #3
0
        /// <summary>
        /// Allows you to get multiple <see cref="Artist">Artists</see>/<see cref="Album">Albums</see>/<see cref="Track">Tracks</see> by known identifiers. 
        /// </summary>
        /// <param name="ids">A List of IDs to search for. Must start with "music."</param>
        /// <param name="options">Optional. A <see cref="LookupOptions"/> instance with details on what additional information should be returned.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <returns>A <see cref="ContentResponse"/> object populated with results from the Xbox Music service.</returns>
        public async Task<ContentResponse> Get(List<string> ids, LookupOptions options = null)
        {
            if (ids == null)
                throw new ArgumentNullException("ids", "You must pass in a list of IDs to lookup.");

            if (ids.Count == 0)
                throw new ArgumentOutOfRangeException("ids", "The list of IDs to lookup cannot be empty.");

            await CheckToken();

            var request = GetPopulatedRequest(string.Format(BaseUrl + "/1/content/{0}/lookup", ids.Aggregate("", (c, n) => c.Length == 0 ? c += n : c += "+" + n)));

            if (options != null)
            {
                var extras = new List<string>();
                if (options.GetArtistAlbums)
                {
                    extras.Add("albums");
                }
                if (options.GetArtistTopTracks)
                {
                    extras.Add("topTracks");
                }
                if (options.GetAlbumTracks)
                {
                    extras.Add("tracks");
                }
                if (options.GetAlbumArtistDetails || options.GetTrackArtistDetails)
                {
                    extras.Add("artistDetails");
                }
                if (options.GetTrackAlbumDetails)
                {
                    extras.Add("albumDetails");
                }
                request.Parameters.Add("extras", extras.Aggregate("", (c, n) => c.Length == 0 ? c += n : c += "+" + n));
            }

            request.Parameters.Add("accessToken", "Bearer " + TokenResponse.AccessToken);

            var response = await request.Execute();

            return JsonConvert.DeserializeObject<ContentResponse>(response.ToString());
        }