Example #1
0
        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Title = element.ElementAsString("title");
            Isbn = element.ElementAsString("isbn");
            Isbn13 = element.ElementAsString("isbn13");
            Asin = element.ElementAsString("asin");
            KindleAsin = element.ElementAsString("kindle_asin");
            MarketplaceId = element.ElementAsString("marketplace_id");
            CountryCode = element.ElementAsString("country_code");
            ImageUrl = element.ElementAsString("image_url");
            SmallImageUrl = element.ElementAsString("small_image_url");
            PublicationDate = element.ElementAsMultiDateField("publication");
            Publisher = element.ElementAsString("publisher");
            LanguageCode = element.ElementAsString("language_code");
            IsEbook = element.ElementAsBool("is_ebook");
            Description = element.ElementAsString("description");
            AverageRating = element.ElementAsDecimal("average_rating");
            Pages = element.ElementAsInt("num_pages");
            Format = element.ElementAsString("format");
            EditionInformation = element.ElementAsString("edition_information");
            RatingsCount = element.ElementAsInt("ratings_count");
            TextReviewsCount = element.ElementAsInt("text_reviews_count");
            Url = element.ElementAsString("url");
            ReviewsWidget = element.ElementAsString("reviews_widget");

            var workElement = element.Element("work");
            if (workElement != null)
            {
                Work = new Work();
                Work.Parse(element.Element("work"));
            }

            Authors = element.ParseChildren<AuthorSummary>("authors", "author");
            SimilarBooks = element.ParseChildren<BookSummary>("similar_books", "book");

            var bookLinks = element.ParseChildren<BookLink>("book_links", "book_link");
            if (bookLinks != null)
            {
                bookLinks.ForEach(x => x.FixBookLink(Id));
                BookLinks = bookLinks;
            }

            var buyLinks = element.ParseChildren<BookLink>("buy_links", "buy_link");
            if (buyLinks != null)
            {
                buyLinks.ForEach(x => x.FixBookLink(Id));
                BuyLinks = buyLinks;
            }

            var shelves = element.ParseChildren(
                "popular_shelves",
                "shelf",
                (shelfElement) =>
            {
                var shelfName = shelfElement.Attribute("name").Value;
                var shelfCountValue = shelfElement.Attribute("count").Value;

                int shelfCount = 0;
                int.TryParse(shelfCountValue, out shelfCount);
                return new KeyValuePair<string, int>(shelfName, shelfCount);
            });

            if (shelves != null)
            {
                PopularShelves = shelves.ToDictionary(x => x.Key, x => x.Value);
            }
        }
Example #2
0
        /// <summary>
        /// In order to make out API models less complicated than the mess that Goodreads responds with,
        /// we merge the concept of "series works" and "works" by copying the only
        /// useful piece of information (user position) to the work object.
        /// </summary>
        /// <param name="seriesWorksRootElement">The root element of the list of series works.</param>
        private void ParseSeriesWorks(XElement seriesWorksRootElement)
        {
            var seriesWorkElements = seriesWorksRootElement.Descendants("series_work");
            if (seriesWorkElements != null && seriesWorkElements.Count() > 0)
            {
                var works = new List<Work>();
                foreach (var seriesWorkElement in seriesWorkElements)
                {
                    var userPosition = seriesWorkElement.ElementAsString("user_position");

                    var workElement = seriesWorkElement.Element("work");
                    if (workElement != null)
                    {
                        var work = new Work();
                        work.Parse(workElement);
                        work.SetUserPosition(userPosition);
                        works.Add(work);
                    }
                }

                Works = works;
            }
        }
Example #3
0
        internal override void Parse(XElement element)
        {
            Id                 = element.ElementAsLong("id");
            Title              = element.ElementAsString("title");
            Isbn               = element.ElementAsString("isbn");
            Isbn13             = element.ElementAsString("isbn13");
            Asin               = element.ElementAsString("asin");
            KindleAsin         = element.ElementAsString("kindle_asin");
            MarketplaceId      = element.ElementAsString("marketplace_id");
            CountryCode        = element.ElementAsString("country_code");
            ImageUrl           = element.ElementAsString("image_url");
            SmallImageUrl      = element.ElementAsString("small_image_url");
            PublicationDate    = element.ElementAsMultiDateField("publication");
            Publisher          = element.ElementAsString("publisher");
            LanguageCode       = element.ElementAsString("language_code");
            IsEbook            = element.ElementAsBool("is_ebook");
            Description        = element.ElementAsString("description");
            AverageRating      = element.ElementAsDecimal("average_rating");
            Pages              = element.ElementAsInt("num_pages");
            Format             = element.ElementAsString("format");
            EditionInformation = element.ElementAsString("edition_information");
            RatingsCount       = element.ElementAsInt("ratings_count");
            TextReviewsCount   = element.ElementAsInt("text_reviews_count");
            Url                = element.ElementAsString("url");
            ReviewsWidget      = element.ElementAsString("reviews_widget");

            var workElement = element.Element("work");

            if (workElement != null)
            {
                Work = new Work();
                Work.Parse(workElement);
            }

            Authors      = element.ParseChildren <AuthorSummary>("authors", "author");
            SimilarBooks = element.ParseChildren <BookSummary>("similar_books", "book");

            var bookLinks = element.ParseChildren <BookLink>("book_links", "book_link");

            if (bookLinks != null)
            {
                bookLinks.ForEach(x => x.FixBookLink(Id));
                BookLinks = bookLinks;
            }

            var buyLinks = element.ParseChildren <BookLink>("buy_links", "buy_link");

            if (buyLinks != null)
            {
                buyLinks.ForEach(x => x.FixBookLink(Id));
                BuyLinks = buyLinks;
            }

            var shelves = element.ParseChildren(
                "popular_shelves",
                "shelf",
                (shelfElement) =>
            {
                var shelfName       = shelfElement.Attribute("name").Value;
                var shelfCountValue = shelfElement.Attribute("count").Value;

                int shelfCount = 0;
                int.TryParse(shelfCountValue, out shelfCount);
                return(new KeyValuePair <string, int>(shelfName, shelfCount));
            });

            if (shelves != null)
            {
                PopularShelves = shelves.ToDictionary(x => x.Key, x => x.Value);
            }
        }