Exemplo n.º 1
0
        public static VkGroup FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }
            VkGroup vkGroup = new VkGroup();

            vkGroup.Id   = Math.Abs(json["gid"].Value <long>());
            vkGroup.Name = json["name"].Value <string>();
            if (json["photo"] != null)
            {
                vkGroup.Photo = new Uri(json["photo"].Value <string>());
            }
            return(vkGroup);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <VkGroup> > Get(string uid, string fields, string filter, int count, int offset, bool extended = true)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(uid))
            {
                dictionary.Add("uid", uid);
            }
            if (!string.IsNullOrWhiteSpace(fields))
            {
                dictionary.Add("fields", fields);
            }
            if (!string.IsNullOrWhiteSpace(filter))
            {
                dictionary.Add("filter", filter);
            }
            if (count > 0)
            {
                dictionary.Add("count", count.ToString());
            }
            if (offset > 0)
            {
                dictionary.Add("offset", offset.ToString());
            }
            if (extended)
            {
                dictionary.Add("extended", "1");
            }
            dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token);
            JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/groups.get"), dictionary, "GET").Execute();

            VkErrorProcessor.ProcessError(jObject);
            IEnumerable <VkGroup> result;

            if (jObject["response"].HasValues)
            {
                result = Enumerable.Select <JToken, VkGroup>(Enumerable.Where <JToken>(jObject["response"], (JToken g) => g.HasValues), (JToken g) => VkGroup.FromJson(g));
            }
            else
            {
                result = null;
            }
            return(result);
        }