/// <summary>
        /// 获取用户收藏列表
        /// </summary>
        /// <param name="client"></param>
        /// <param name="uid">UID</param>
        /// <param name="cat">收藏类型</param>
        /// <param name="ids">收藏条目 ID</param>
        /// <param name="responseGroup"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <CollectionSubject[]> GetUserCollectionAsync(
            this IBangumiClient client,
            long uid,
            CollectionType cat,
            int[] ids = null,
            ResponseGroup responseGroup         = ResponseGroup.Medium,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (responseGroup == ResponseGroup.Large)
            {
                throw new NotSupportedException();
            }

            var url = $"/user/{uid}/collection?cat={cat.GetValue()}";

            if (ids != null)
            {
                url += $"&ids={string.Join(",", ids)}";
            }
            url += $"&responseGroup={responseGroup.GetValue()}";
            return(client.GetAsync <CollectionSubject[]>(url, cancellationToken));
        }
Пример #2
0
        /// <summary>
        /// 条目搜索
        /// </summary>
        /// <param name="client"></param>
        /// <param name="keywords">关键词</param>
        /// <param name="start">开始条数</param>
        /// <param name="maxResults">每页条数</param>
        /// <param name="type">类型</param>
        /// <param name="responseGroup">返回数据大小</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task <SearchResult> SearchAsync(this IBangumiClient client, string keywords, int start, int maxResults, SubjectType?type = null, ResponseGroup responseGroup = ResponseGroup.Small, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/search/subject/{WebUtility.UrlEncode(keywords)}?";

            if (type.HasValue)
            {
                url += $"type={(int)type}";
            }
            url += $"&responseGroup={responseGroup.GetValue()}&start={start}&max_results={maxResults}";

            var result = await client.GetAsync <SearchResult>(url, cancellationToken);

            if (result.ErrorCode == (int)HttpStatusCode.NotFound)
            {
                result = new SearchResult
                {
                    List = Array.Empty <Subject>()
                };
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// 更新收视进度
        /// </summary>
        /// <param name="client"></param>
        /// <param name="epId">章节 ID</param>
        /// <param name="status">收视类型</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <BangumiResult> UpdateEpStatusAsync(this IBangumiClient client, int epId, EpStatus status, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/ep/{epId}/status/{status.GetValue()}";

            return(client.GetAsync <BangumiResult>(url, cancellationToken));
        }
        /// <summary>
        /// 获取用户基础信息
        /// </summary>
        /// <param name="client"></param>
        /// <param name="uid">UID</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <User> GetUserAsync(this IBangumiClient client, long uid, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/user/{uid}";

            return(client.GetAsync <User>(url, cancellationToken));
        }
        /// <summary>
        /// 获取用户某个条目收视进度
        /// </summary>
        /// <param name="client"></param>
        /// <param name="uid">UID</param>
        /// <param name="subjectId">条目 ID</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <SubjectProgress> GetSubjectProgressAsync(this IBangumiClient client, long uid, int subjectId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/user/{uid}/progress?subject_id={subjectId}";

            return(client.GetAsync <SubjectProgress>(url, cancellationToken));
        }
        /// <summary>
        /// 获取用户指定类型的收藏概览,固定返回最近更新的收藏,不支持翻页
        /// </summary>
        /// <param name="client"></param>
        /// <param name="uid"></param>
        /// <param name="subjectType"></param>
        /// <param name="maxResults"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <CollectionOverview[]> GetUserCollectionsOverviewAsync(this IBangumiClient client, long uid, SubjectType subjectType, int maxResults, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/user/{uid}/collections/{subjectType.GetValue()}?max_results={maxResults}";

            return(client.GetAsync <CollectionOverview[]>(url, cancellationToken));
        }
        /// <summary>
        /// 获取指定条目收藏信息
        /// </summary>
        /// <param name="client"></param>
        /// <param name="subjectId">条目 ID</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <SubjectCollectionStatus> GetCollectionStatusAsync(this IBangumiClient client, int subjectId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/collection/{subjectId}";

            return(client.GetAsync <SubjectCollectionStatus>(url, cancellationToken));
        }
        /// <summary>
        /// 获取章节数据
        /// </summary>
        /// <param name="client"></param>
        /// <param name="id">条目 ID</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <Subject> GetSubjectEpInfoAsync(this IBangumiClient client, int id, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/subject/{id}/ep";

            return(client.GetAsync <Subject>(url, cancellationToken));
        }
        /// <summary>
        /// 获取条目信息
        /// </summary>
        /// <param name="client"></param>
        /// <param name="id">条目 ID</param>
        /// <param name="responseGroup">返回数据大小</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <Subject> GetSubjectAsync(this IBangumiClient client, int id, ResponseGroup responseGroup = ResponseGroup.Small, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var url = $"/subject/{id}?responseGroup={responseGroup.GetValue()}";

            return(client.GetAsync <Subject>(url, cancellationToken));
        }
        /// <summary>
        /// 获取每日放送
        /// </summary>
        /// <param name="client"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <Calendar[]> GetCalendarAsync(this IBangumiClient client, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            const string url = "/calendar";

            return(client.GetAsync <Calendar[]>(url, cancellationToken));
        }
        /// <summary>
        /// 获取用户基础信息
        /// </summary>
        /// <param name="client"></param>
        /// <param name="username">用户名</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <User> GetUserAsync(this IBangumiClient client, string username, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }

            var url = $"/user/{WebUtility.UrlEncode(username)}";

            return(client.GetAsync <User>(url, cancellationToken));
        }
        /// <summary>
        /// 获取用户某个条目收视进度
        /// </summary>
        /// <param name="client"></param>
        /// <param name="username">用户名</param>
        /// <param name="subjectId">条目 ID</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <SubjectProgress> GetSubjectProgressAsync(this IBangumiClient client, string username, int subjectId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }

            var url = $"/user/{WebUtility.UrlEncode(username)}/progress?subject_id={subjectId}";

            return(client.GetAsync <SubjectProgress>(url, cancellationToken));
        }