implement ParserAPI func
This commit is contained in:
@@ -196,6 +196,34 @@ namespace PocketSharp
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the article content from an URI
|
||||
/// WARNING:
|
||||
/// You have to pass the parseUri in the PocketClient ctor for this method to work.
|
||||
/// This is a private API and can only be used by authenticated users.
|
||||
/// </summary>
|
||||
/// <param name="tag">The article URI.</param>
|
||||
/// <param name="includeImages">Include images into content or use placeholder.</param>
|
||||
/// <param name="includeVideos">Include videos into content or use placeholder.</param>
|
||||
/// <param name="forceRefresh">Force refresh of the content (don't use cache).</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
public async Task<PocketArticle> GetArticle(Uri uri, bool includeImages = true, bool includeVideos = true, bool forceRefresh = false, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
Dictionary<string, string> parameters = new Dictionary<string, string>()
|
||||
{
|
||||
{ "url", uri.OriginalString },
|
||||
{ "images", includeImages ? "1" : "0" },
|
||||
{ "videos", includeVideos ? "1" : "0" },
|
||||
{ "refresh", forceRefresh ? "1" : "0" },
|
||||
{ "output", "json" }
|
||||
};
|
||||
|
||||
return await Request<PocketArticle>("", cancellationToken, parameters, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -196,6 +196,21 @@ namespace PocketSharp
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<IEnumerable<PocketItem>> Search(string searchString, string tag = null, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the article content from an URI
|
||||
/// WARNING:
|
||||
/// You have to pass the parseUri in the PocketClient ctor for this method to work.
|
||||
/// This is a private API and can only be used by authenticated users.
|
||||
/// </summary>
|
||||
/// <param name="tag">The article URI.</param>
|
||||
/// <param name="includeImages">Include images into content or use placeholder.</param>
|
||||
/// <param name="includeVideos">Include videos into content or use placeholder.</param>
|
||||
/// <param name="forceRefresh">Force refresh of the content (don't use cache).</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<PocketArticle> GetArticle(Uri uri, bool includeImages = true, bool includeVideos = true, bool forceRefresh = false, CancellationToken cancellationToken = default(CancellationToken));
|
||||
#endregion
|
||||
|
||||
#region modify methods
|
||||
|
||||
@@ -42,6 +42,11 @@ namespace PocketSharp
|
||||
/// </summary>
|
||||
protected string authentificationUri = "https://getpocket.com/auth/authorize?request_token={0}&redirect_uri={1}&mobile={2}";
|
||||
|
||||
/// <summary>
|
||||
/// The parser API URL
|
||||
/// </summary>
|
||||
protected Uri parserUri = null;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates, whether this client is used for mobile or desktop
|
||||
/// </summary>
|
||||
@@ -98,13 +103,15 @@ namespace PocketSharp
|
||||
/// <param name="handler">The HttpMessage handler.</param>
|
||||
/// <param name="timeout">Request timeout (in seconds).</param>
|
||||
/// <param name="isMobileClient">Indicates, whether this client is used for mobile or desktop</param>
|
||||
/// <param name="parserUri">Enables the wrapper for the private Text Parser API</param>
|
||||
public PocketClient(
|
||||
string consumerKey,
|
||||
string accessCode = null,
|
||||
string callbackUri = null,
|
||||
HttpMessageHandler handler = null,
|
||||
int? timeout = null,
|
||||
bool isMobileClient = true)
|
||||
bool isMobileClient = true,
|
||||
Uri parserUri = null)
|
||||
{
|
||||
// assign public properties
|
||||
ConsumerKey = consumerKey;
|
||||
@@ -123,6 +130,12 @@ namespace PocketSharp
|
||||
CallbackUri = Uri.EscapeUriString(callbackUri.ToString());
|
||||
}
|
||||
|
||||
// assign text parser uri if submitted
|
||||
if (parserUri != null)
|
||||
{
|
||||
this.parserUri = parserUri;
|
||||
}
|
||||
|
||||
// initialize REST client
|
||||
_restClient = new HttpClient(handler ?? new HttpClientHandler()
|
||||
{
|
||||
@@ -159,13 +172,29 @@ namespace PocketSharp
|
||||
string method,
|
||||
CancellationToken cancellationToken,
|
||||
Dictionary<string, string> parameters = null,
|
||||
bool requireAuth = true) where T : class, new()
|
||||
bool requireAuth = true,
|
||||
bool isReaderRequest = false) where T : class, new()
|
||||
{
|
||||
if (requireAuth && AccessCode == null)
|
||||
{
|
||||
throw new PocketException("SDK error: No access token available. Use authentication first.");
|
||||
}
|
||||
|
||||
// rewrite base if it is a request to the Parser API
|
||||
if (isReaderRequest)
|
||||
{
|
||||
if (parserUri == null)
|
||||
{
|
||||
throw new PocketException("Please pass the parserUri in the PocketClient ctor.");
|
||||
}
|
||||
|
||||
_restClient.BaseAddress = parserUri;
|
||||
}
|
||||
else
|
||||
{
|
||||
_restClient.BaseAddress = baseUri;
|
||||
}
|
||||
|
||||
// every single Pocket API endpoint requires HTTP POST data
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, method);
|
||||
HttpResponseMessage response = null;
|
||||
@@ -179,7 +208,7 @@ namespace PocketSharp
|
||||
parameters.Add("consumer_key", ConsumerKey);
|
||||
|
||||
// add access token (necessary for all requests except authentification)
|
||||
if (AccessCode != null)
|
||||
if (AccessCode != null && requireAuth)
|
||||
{
|
||||
parameters.Add("access_token", AccessCode);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Components\Statistics.cs" />
|
||||
<Compile Include="IPocketClient.cs" />
|
||||
<Compile Include="Models\PocketArticle.cs" />
|
||||
<Compile Include="Models\PocketBoolean.cs" />
|
||||
<Compile Include="Models\PocketLimits.cs" />
|
||||
<Compile Include="Models\PocketStatistics.cs" />
|
||||
|
||||
Reference in New Issue
Block a user