/// <summary>
        /// API请求
        /// </summary>
        /// <param name="provider">API提供者</param>
        /// <param name="queries">参数</param>
        /// <returns></returns>
        public Task <(bool, JObject)> RequestAsync(CloudMusicApiProvider provider, Dictionary <string, object> queries = null)
        {
            if (provider is null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (queries is null)
            {
                queries = new Dictionary <string, object>();
            }
            if (provider == CloudMusicApiProviders.CheckMusic)
            {
                return(HandleCheckMusicAsync(queries));
            }
            else if (provider == CloudMusicApiProviders.Login)
            {
                return(HandleLoginAsync(queries));
            }
            else if (provider == CloudMusicApiProviders.LoginStatus)
            {
                return(HandleLoginStatusAsync());
            }
            else if (provider == CloudMusicApiProviders.RelatedPlaylist)
            {
                return(HandleRelatedPlaylistAsync(queries));
            }
            return(RequestAsync(provider.Method, provider.Url(queries), provider.Data(queries), provider.Options));
        }
Esempio n. 2
0
        /// <summary>
        /// API请求
        /// </summary>
        /// <param name="provider">API提供者</param>
        /// <param name="queries">参数</param>
        /// <param name="throwIfFailed">如果请求失败,抛出异常</param>
        /// <returns></returns>
        public async Task <JObject> RequestAsync(CloudMusicApiProvider provider, Dictionary <string, object> queries = null, bool throwIfFailed = true)
        {
            if (provider is null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (queries is null)
            {
                queries = new Dictionary <string, object>();
            }
            JObject json;

            if (provider == CloudMusicApiProviders.CheckMusic)
            {
                json = await HandleCheckMusicAsync(queries);
            }
            else if (provider == CloudMusicApiProviders.Login)
            {
                json = await HandleLoginAsync(queries);
            }
            else if (provider == CloudMusicApiProviders.LoginStatus)
            {
                json = await HandleLoginStatusAsync();
            }
            else if (provider == CloudMusicApiProviders.RelatedPlaylist)
            {
                json = await HandleRelatedPlaylistAsync(queries);
            }
            else
            {
                json = await RequestAsync(provider.Method, provider.Url(queries), provider.Data(queries), provider.Options);
            }
            if (throwIfFailed && !IsSuccess(json))
            {
                throw new HttpRequestException($"调用 '{provider.Route}' 失败");
            }
            return(json);
        }