Beispiel #1
0
        public async static Task <GrUser> GetUserInfoAsync()
        {
            UriBuilder builder = new UriBuilder("https://www.goodreads.com/user/show/" + AuthorizationService.Instance.UserID.ToString() + ".xml");
            var        query   = HttpUtility.ParseQueryString(builder.Query);

            query["key"]  = "K7gUv8myuMHUFxeNnDjfDQ";
            builder.Query = query.ToString();
            string url = builder.ToString();

            HttpClient client = new HttpClient();

            var response = await client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var      doc  = XDocument.Parse(content);
                XElement user = doc.Element("GoodreadsResponse").Element("user");

                var name    = user.Element("name").Value;
                var image   = user.Element("image_url").Value;
                var joined  = user.Element("joined").Value;
                var friends = Int32.Parse(user.Element("friends_count").Value);
                var shelves = user.Descendants("user_shelf").Count();

                var gruser = new GrUser
                {
                    Name            = name,
                    Image           = image,
                    Joined          = joined,
                    NumberOfFriends = friends,
                    NumberOfShelves = shelves
                };
                return(gruser);
            }
            return(new GrUser());
        }
        public override async void OnNavigatingTo(NavigationParameters parameters)
        {
            base.OnNavigatingTo(parameters);

            User = await WebClient.Client.GetUserInfoAsync();
        }