You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/PaginationModel.cs

59 lines
1.8 KiB

using System.Diagnostics;
using System.Xml.Linq;
namespace NzbDrone.Core.MetadataSource.Goodreads
{
/// <summary>
/// Represents pagination information as returned by the Goodreads API.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public sealed class PaginationModel : GoodreadsResource
{
public override string ElementName => "";
/// <summary>
/// The item the current page starts on.
/// </summary>
public int Start { get; private set; }
/// <summary>
/// The item the current page ends on.
/// </summary>
public int End { get; private set; }
/// <summary>
/// The total number of items in the paginated list.
/// </summary>
public int TotalItems { get; private set; }
public override void Parse(XElement element)
{
// Search results have different pagination fields for some reason...
if (element.Name == "search")
{
Start = element.ElementAsInt("results-start");
End = element.ElementAsInt("results-end");
TotalItems = element.ElementAsInt("total-results");
return;
}
var startAttribute = element.Attribute("start");
var endAttribute = element.Attribute("end");
var totalAttribute = element.Attribute("total");
if (startAttribute != null &&
endAttribute != null &&
totalAttribute != null)
{
int.TryParse(startAttribute.Value, out var start);
int.TryParse(endAttribute.Value, out var end);
int.TryParse(totalAttribute.Value, out var total);
Start = start;
End = end;
TotalItems = total;
}
}
}
}