Exemple #1
0
        internal static VkPhotoAlbum FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }
            VkPhotoAlbum vkAlbum = new VkPhotoAlbum();

            if (json["aid"] != null)
            {
                vkAlbum.AId = json["aid"].Value <long>();
            }
            if (json["thumb_id"] != null)
            {
                vkAlbum.ThumbId = json["thumb_id"].Value <long>();
            }
            if (json["owner_id"] != null)
            {
                vkAlbum.OwnerId = json["owner_id"].Value <long>();
            }
            if (vkAlbum.AId > 0)
            {
                vkAlbum.Description = WebUtility.HtmlDecode(json["description"].Value <string>());
            }
            else
            {
                vkAlbum.Description = "Сохраненные фотографии";
            }
            vkAlbum.Title = WebUtility.HtmlDecode(json["title"].Value <string>());

            if (json["thumb_src"] != null)
            {
                vkAlbum.ThumbSrc = new Uri(json["thumb_src"].Value <string>());
            }

            return(vkAlbum);
        }
Exemple #2
0
        public async Task <IEnumerable <VkPhotoAlbum> > Get(string uid, IList <string> aids = null, int needSystem = 0, int needCovers = 0, int needSizes = 0)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (aids != null)
            {
                dictionary.Add("aids", string.Join(",", aids));
            }
            if (!string.IsNullOrEmpty(uid))
            {
                dictionary.Add("uid", uid);
            }
            dictionary.Add("need_system", needSystem.ToString());
            dictionary.Add("need_covers", needCovers.ToString());
            dictionary.Add("photo_sizes", needSizes.ToString());

            JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/photos.getAlbums"), dictionary, "GET").Execute();
            IEnumerable <VkPhotoAlbum> result;

            if (VkErrorProcessor.ProcessError(jObject))
            {
                result = null;
            }
            else
            {
                if (jObject["response"].HasValues)
                {
                    //result = Enumerable.Select<JToken, VkPhotoAlbum>(Enumerable.Skip<JToken>(jObject["response"], 1), (JToken a) => VkPhotoAlbum.FromJson(a));
                    result = Enumerable.Select <JToken, VkPhotoAlbum>(Enumerable.Where <JToken>(jObject["response"], (JToken v) => v.HasValues), (JToken v) => VkPhotoAlbum.FromJson(v));
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }