コード例 #1
0
        public override string ToString()
        {
            var retVal = new List <string>();

            retVal.Add(string.Format("page={0}", PageNumber));
            retVal.Add(string.Format("page_size={0}", PageSize));
            retVal.Add(string.Format("respGroup={0}", ResponseGroup.ToString()));
            if (Keyword != null)
            {
                retVal.Add(string.Format("q={0}", Keyword));
            }
            if (CategoryId != null)
            {
                retVal.Add(string.Format("categoryId={0}", CategoryId));
            }
            if (VendorId != null)
            {
                retVal.Add(string.Format("vendor={0}", VendorId));
            }
            if (VendorIds != null)
            {
                retVal.Add(string.Format("vendors={0}", string.Join(",", this.VendorIds)));
            }
            return(string.Join("&", retVal));
        }
コード例 #2
0
        public async Task <Subject> Get(int id, ResponseGroup responseGroup = ResponseGroup.Small)
        {
            if (!Enum.IsDefined(typeof(ResponseGroup), responseGroup))
            {
                throw new ArgumentOutOfRangeException(nameof(responseGroup));
            }

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

            using (var client = new BangumiClient())
            {
                var json = await client.GetStringAsync(url);

                return(JsonConvert.DeserializeObject <Subject>(json));
            }
        }
コード例 #3
0
        public static string GetValue(this ResponseGroup responseGroup)
        {
            switch (responseGroup)
            {
            case ResponseGroup.Small:
                return("small");

            case ResponseGroup.Medium:
                return("medium");

            case ResponseGroup.Large:
                return("large");

            default:
                return(responseGroup.ToString());
            }
        }
コード例 #4
0
        public async Task <ListResult <Subject> > Search(string keywords, SubjectType?type = null, ResponseGroup responseGroup = ResponseGroup.Small, int start = 0, int maxResults = 10)
        {
            if (keywords == null)
            {
                throw new ArgumentNullException(nameof(keywords));
            }
            if (start < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(start));
            }
            if (maxResults <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxResults));
            }

            var url   = $"/search/subject/{WebUtility.UrlEncode(keywords)}";
            var query = new Dictionary <string, string>();

            if (type.HasValue)
            {
                query["type"] = ((int)type.Value).ToString();
            }
            query["responseGroup"] = responseGroup.ToString().ToLowerInvariant();
            query["start"]         = start.ToString();
            query["max_results"]   = maxResults.ToString();
            if (query.Count > 0)
            {
                url += "?" + string.Join("&", query.Select(temp => temp.Key + "=" + WebUtility.UrlEncode(temp.Value)));
            }
            using (var client = new BangumiClient())
            {
                var json = await client.GetStringAsync(url);

                return(JsonConvert.DeserializeObject <ListResult <Subject> >(json));
            }
        }
コード例 #5
0
        public async Task <UserCollection[]> GetCollection(int uid, CollectionCategory category, ResponseGroup responseGroup = ResponseGroup.Medium)
        {
            if (!Enum.IsDefined(typeof(CollectionCategory), category))
            {
                throw new ArgumentOutOfRangeException(nameof(category));
            }
            if (!Enum.IsDefined(typeof(ResponseGroup), responseGroup))
            {
                throw new ArgumentOutOfRangeException(nameof(responseGroup));
            }

            var url = $"/user/{uid}/collection?cat={(category == CollectionCategory.Watching ? "watching" : "all_watching")}&responseGroup={responseGroup.ToString().ToLowerInvariant()}";

            using (var client = new BangumiClient())
            {
                var json = await client.GetStringAsync(url);

                return(JsonConvert.DeserializeObject <UserCollection[]>(json));
            }
        }