コード例 #1
0
        /// <summary>
        /// Get a playlist owned by a Spotify user.
        /// </summary>
        /// <param name="playlistId">The Spotify ID for the playlist.</param>
        /// <param name="accessToken">Optional. A valid access token from the Spotify Accounts service.
        /// <param name="fields">Optional. Filters for the query: a comma-separated list of the fields to return. If omitted, all fields are returned. See docs for examples.</param>
        /// <param name="additionalTypes">Optional. A comma-separated list of item types that your
        /// client supports besides the default track type. Valid types are: `track` and `episode`.
        /// Note: This parameter was introduced to allow existing clients to maintain their current
        /// behaviour and might be deprecated in the future. In addition to providing this parameter,
        /// make sure that your client properly handles cases of new types in the future by checking
        /// against the type field of each object.</param>
        /// <param name="market">Optional. An <see cref="SpotifyCountryCodes"/> or the string <see cref="SpotifyCountryCodes._From_Token"/>.
        /// Provide this parameter if you want to apply Track Relinking.</param>
        /// <typeparam name="T">Optionally provide your own type to deserialise Spotify's response to.</typeparam>
        /// <returns>Task of T</returns>
        public async Task <T> GetPlaylist <T>(
            string playlistId,
            string accessToken       = null,
            string fields            = null,
            string[] additionalTypes = null,
            string market            = null)
        {
            if (string.IsNullOrEmpty(playlistId))
            {
                throw new ArgumentNullException(nameof(playlistId));
            }

            var builder = new UriBuilder($"{BaseUrl}/playlists/{SpotifyUriHelper.PlaylistId(playlistId)}");

            builder.AppendToQueryIfValueNotNullOrWhiteSpace("fields", fields);
            builder.AppendToQueryAsCsv("additional_types", additionalTypes);
            builder.AppendToQueryIfValueNotNullOrWhiteSpace("market", market);

            return(await GetModel <T>(builder.Uri, accessToken : accessToken));
        }
コード例 #2
0
        /// <summary>
        /// Get full details of the tracks of a playlist owned by a Spotify user.
        /// </summary>
        /// <param name="playlistId">The Spotify ID for the playlist.</param>
        /// <param name="accessToken">Optional. A valid access token from the Spotify Accounts service.
        /// <param name="fields">Optional. Filters for the query: a comma-separated list of the fields to return. If omitted, all fields are returned. See docs for examples.</param>
        /// <param name="limit">Optional. The maximum number of tracks to return. Default: 100. Minimum: 1. Maximum: 100.</param>
        /// <param name="offset">Optional. The index of the first track to return. Default: 0 (the first object).</param>
        /// <param name="market">Optional. An <see cref="SpotifyCountryCodes"/> or the string <see cref="SpotifyCountryCodes._From_Token"/>.
        /// Provide this parameter if you want to apply Track Relinking.</param>
        /// <typeparam name="T">Optionally provide your own type to deserialise Spotify's response to.</typeparam>
        /// <returns>Task of T</returns>
        /// <remarks>
        /// https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlists-tracks/
        /// </remarks>
        public async Task <T> GetTracks <T>(
            string playlistId,
            string accessToken = null,
            string fields      = null,
            int?limit          = null,
            int offset         = 0,
            string market      = null)
        {
            if (string.IsNullOrEmpty(playlistId))
            {
                throw new ArgumentNullException(nameof(playlistId));
            }
            string url = $"{BaseUrl}/playlists/{SpotifyUriHelper.PlaylistId(playlistId)}/tracks";

            if (!string.IsNullOrEmpty(fields) || (limit ?? 0) > 0 || offset > 0 || !string.IsNullOrEmpty(market))
            {
                url += "?";

                if (!string.IsNullOrEmpty(fields))
                {
                    url += $"fields={fields}&";
                }
                if ((limit ?? 0) > 0)
                {
                    url += $"limit={limit.Value}&";
                }
                if (offset > 0)
                {
                    url += $"offset={offset}&";
                }
                if (!string.IsNullOrEmpty(market))
                {
                    url += $"market={market}";
                }
            }

            return(await GetModel <T>(url, accessToken));
        }