Пример #1
0
        internal override void Parse(XElement element)
        {
            Id           = element.ElementAsLong("id");
            UserPosition = element.ElementAsLong("user_position");
            var workElement = element.Element("series");

            Series = new Series();
            Series.Parse(workElement);
            //SeriesList = element.ParseChildren<Series>("series_works", "series");
        }
Пример #2
0
        /// <summary>
        /// Get all the series an author has written.
        /// </summary>
        /// <param name="authorId">The author to fetch the list of series for.</param>
        /// <returns>A list of series written by the author.</returns>
        public async Task<IReadOnlyList<Series>> GetListByAuthorId(int authorId)
        {
            var parameters = new List<Parameter>
            {
                new Parameter { Name = "id", Value = authorId, Type = ParameterType.QueryString }
            };

            try
            {
                var response = await Connection.ExecuteRaw("series/list", parameters);
                if (response != null && (int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
                {
                    var content = response.Content;
                    if (!string.IsNullOrWhiteSpace(content))
                    {
                        var document = XDocument.Parse(content);
                        var series = document.XPathSelectElements("GoodreadsResponse/series_works/series_work/series");
                        if (series != null && series.Count() > 0)
                        {
                            var seriesModels = new List<Series>();
                            foreach (var seriesElement in series)
                            {
                                var seriesModel = new Series();
                                seriesModel.Parse(seriesElement);
                                seriesModels.Add(seriesModel);
                            }

                            // Goodreads returns way too many duplicates, group by them by id first.
                            var grouped = seriesModels.GroupBy(x => x.Id);
                            var uniqueSeries = grouped.Select(x => x.First()).ToList();

                            return uniqueSeries;
                        }
                    }
                }
            }
            catch
            {
                // Just ignore the error and return null...
            }

            return null;
        }
Пример #3
0
        internal override void Parse(XElement element)
        {
            Id           = element.ElementAsLong("id");
            UserPosition = element.ElementAsString("user_position");
            var seriesElement = element.Element("series");

            if (seriesElement != null)
            {
                var series = new Series();
                series.Parse(seriesElement);
                Series = series;
            }

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

            if (workElement != null)
            {
                var work = new Work();
                work.Parse(workElement);
                Work = work;
            }
        }
Пример #4
0
        /// <summary>
        /// Get all the series that the given work is in.
        /// </summary>
        /// <param name="workId">The work id to fetch the list of series for.</param>
        /// <returns>A list of series that this work appears in.</returns>
        public async Task<IReadOnlyList<Series>> GetListByWorkId(int workId)
        {
            var parameters = new List<Parameter>
            {
                new Parameter { Name = "id", Value = workId, Type = ParameterType.UrlSegment }
            };

            try
            {
                var response = await Connection.ExecuteRaw("series/work/{id}", parameters);
                if (response != null && (int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
                {
                    var content = response.Content;
                    if (!string.IsNullOrWhiteSpace(content))
                    {
                        var document = XDocument.Parse(content);
                        var series = document.XPathSelectElements("GoodreadsResponse/series_works/series_work/series");
                        if (series != null && series.Count() > 0)
                        {
                            var seriesModels = new List<Series>();
                            foreach (var seriesElement in series)
                            {
                                var seriesModel = new Series();
                                seriesModel.Parse(seriesElement);
                                seriesModels.Add(seriesModel);
                            }

                            return seriesModels;
                        }
                    }
                }
            }
            catch
            {
                // Just ignore the error and return null...
            }

            return null;
        }