rename models and Reader
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.6 KiB |
@@ -4,20 +4,18 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ReadSharp
|
namespace ReadSharp
|
||||||
{
|
{
|
||||||
public interface IPocketReader
|
public interface IReader
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads article content from the given PocketItem.
|
/// Reads article content from the given URI.
|
||||||
/// This method does not use the official Article View API, which is private.
|
|
||||||
/// The PocketReader is based on a custom PCL port of NReadability and SgmlReader.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uri">An URI to extract the content from.</param>
|
/// <param name="uri">An URI to extract the content from.</param>
|
||||||
/// <param name="bodyOnly">if set to <c>true</c> [only body is returned].</param>
|
/// <param name="bodyOnly">if set to <c>true</c> [only body is returned].</param>
|
||||||
/// <param name="noHeadline">if set to <c>true</c> [no headline (h1) is included].</param>
|
/// <param name="noHeadline">if set to <c>true</c> [no headline (h1) is included].</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A Pocket article with extracted content and title.
|
/// An article with extracted content and meta information.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="Exception"></exception>
|
/// <exception cref="Exception"></exception>
|
||||||
Task<PocketArticle> Read(Uri uri, bool bodyOnly = true, bool noHeadline = false);
|
Task<Article> Read(Uri uri, bool bodyOnly = true, bool noHeadline = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace ReadSharp.Models
|
|||||||
/// Readable article
|
/// Readable article
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ImplementPropertyChanged]
|
[ImplementPropertyChanged]
|
||||||
public class PocketArticle
|
public class Article
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the content.
|
/// Gets or sets the content.
|
||||||
@@ -24,7 +24,7 @@ namespace ReadSharp.Models
|
|||||||
/// <value>
|
/// <value>
|
||||||
/// The images.
|
/// The images.
|
||||||
/// </value>
|
/// </value>
|
||||||
public List<PocketArticleImage> Images { get; set; }
|
public List<ArticleImage> Images { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the title.
|
/// Gets or sets the title.
|
||||||
@@ -7,7 +7,7 @@ namespace ReadSharp.Models
|
|||||||
/// Article image
|
/// Article image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ImplementPropertyChanged]
|
[ImplementPropertyChanged]
|
||||||
public class PocketArticleImage
|
public class ArticleImage
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the URI.
|
/// Gets or sets the URI.
|
||||||
@@ -39,10 +39,10 @@
|
|||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="IPocketReader.cs" />
|
<Compile Include="IReader.cs" />
|
||||||
<Compile Include="Models\PocketArticle.cs" />
|
<Compile Include="Models\Article.cs" />
|
||||||
<Compile Include="Models\PocketArticleImage.cs" />
|
<Compile Include="Models\ArticleImage.cs" />
|
||||||
<Compile Include="PocketReader.cs" />
|
<Compile Include="Reader.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace ReadSharp
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// PocketReader
|
/// PocketReader
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PocketReader : IPocketReader
|
public class Reader : IReader
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used UserAgent for HTTP request
|
/// Used UserAgent for HTTP request
|
||||||
@@ -27,12 +27,12 @@ namespace ReadSharp
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PocketReader" /> class.
|
/// Initializes a new instance of the <see cref="Reader" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userAgent">Custom UserAgent string.</param>
|
/// <param name="userAgent">Custom UserAgent string.</param>
|
||||||
/// <param name="handler">The HttpMessage handler.</param>
|
/// <param name="handler">The HttpMessage handler.</param>
|
||||||
/// <param name="timeout">Request timeout (in seconds).</param>
|
/// <param name="timeout">Request timeout (in seconds).</param>
|
||||||
public PocketReader(string userAgent = null, HttpMessageHandler handler = null, int? timeout = null)
|
public Reader(string userAgent = null, HttpMessageHandler handler = null, int? timeout = null)
|
||||||
{
|
{
|
||||||
// override user agent
|
// override user agent
|
||||||
if (!string.IsNullOrEmpty(userAgent))
|
if (!string.IsNullOrEmpty(userAgent))
|
||||||
@@ -65,18 +65,16 @@ namespace ReadSharp
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads article content from the given PocketItem.
|
/// Reads article content from the given URI.
|
||||||
/// This method does not use the official Article View API, which is private.
|
|
||||||
/// The PocketReader is based on a custom PCL port of NReadability and SgmlReader.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uri">An URI to extract the content from.</param>
|
/// <param name="uri">An URI to extract the content from.</param>
|
||||||
/// <param name="bodyOnly">if set to <c>true</c> [only body is returned].</param>
|
/// <param name="bodyOnly">if set to <c>true</c> [only body is returned].</param>
|
||||||
/// <param name="noHeadline">if set to <c>true</c> [no headline (h1) is included].</param>
|
/// <param name="noHeadline">if set to <c>true</c> [no headline (h1) is included].</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A Pocket article with extracted content and title.
|
/// An article with extracted content and meta information.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="Exception"></exception>
|
/// <exception cref="Exception"></exception>
|
||||||
public async Task<PocketArticle> Read(Uri uri, bool bodyOnly = true, bool noHeadline = false)
|
public async Task<Article> Read(Uri uri, bool bodyOnly = true, bool noHeadline = false)
|
||||||
{
|
{
|
||||||
// initialize transcoder
|
// initialize transcoder
|
||||||
NReadabilityTranscoder transcoder = new NReadabilityTranscoder(
|
NReadabilityTranscoder transcoder = new NReadabilityTranscoder(
|
||||||
@@ -111,12 +109,12 @@ namespace ReadSharp
|
|||||||
TranscodingResult transcodingResult = transcoder.Transcode(transcodingInput);
|
TranscodingResult transcodingResult = transcoder.Transcode(transcodingInput);
|
||||||
|
|
||||||
// get images from article
|
// get images from article
|
||||||
List<PocketArticleImage> images = transcodingResult.Images.Select<XElement, PocketArticleImage>(image =>
|
List<ArticleImage> images = transcodingResult.Images.Select<XElement, ArticleImage>(image =>
|
||||||
{
|
{
|
||||||
Uri imageUri;
|
Uri imageUri;
|
||||||
Uri.TryCreate(image.GetAttributeValue("src", null), UriKind.Absolute, out imageUri);
|
Uri.TryCreate(image.GetAttributeValue("src", null), UriKind.Absolute, out imageUri);
|
||||||
|
|
||||||
return new PocketArticleImage()
|
return new ArticleImage()
|
||||||
{
|
{
|
||||||
Uri = imageUri,
|
Uri = imageUri,
|
||||||
Title = image.GetAttributeValue("title", null),
|
Title = image.GetAttributeValue("title", null),
|
||||||
@@ -125,7 +123,7 @@ namespace ReadSharp
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
// create article
|
// create article
|
||||||
return new PocketArticle()
|
return new Article()
|
||||||
{
|
{
|
||||||
Content = transcodingResult.ExtractedContent,
|
Content = transcodingResult.ExtractedContent,
|
||||||
Images = images,
|
Images = images,
|
||||||
Reference in New Issue
Block a user