cancellationToken for Add and Account methods
This commit is contained in:
@@ -29,9 +29,9 @@ namespace PocketSharp.Tests
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task Are100ItemsRetrievedProperly()
|
||||
public async Task Are100IdingtemsRetrievedProperly()
|
||||
{
|
||||
// await FillAccount(1577, 10000);
|
||||
await FillAccount(3817, 10000);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PocketSharp
|
||||
@@ -18,6 +19,19 @@ namespace PocketSharp
|
||||
/// <exception cref="System.NullReferenceException">Authentication methods need a callbackUri on initialization of the PocketClient class</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
public async Task<string> GetRequestCode()
|
||||
{
|
||||
return await GetRequestCode(CancellationToken.None);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the requestCode from Pocket, which is used to generate the Authentication URI to authenticate the user
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.NullReferenceException">Authentication methods need a callbackUri on initialization of the PocketClient class</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
public async Task<string> GetRequestCode(CancellationToken cancellationToken)
|
||||
{
|
||||
// check if request code is available
|
||||
if (CallbackUri == null)
|
||||
@@ -26,7 +40,7 @@ namespace PocketSharp
|
||||
}
|
||||
|
||||
// do request
|
||||
RequestCode response = await Request<RequestCode>("oauth/request", new Dictionary<string, string>()
|
||||
RequestCode response = await Request<RequestCode>("oauth/request", cancellationToken, new Dictionary<string, string>()
|
||||
{
|
||||
{ "redirect_uri", CallbackUri }
|
||||
}, false);
|
||||
@@ -64,29 +78,31 @@ namespace PocketSharp
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Requests the access code after authentication
|
||||
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
|
||||
/// Requests the access code and username after authentication
|
||||
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
|
||||
/// </summary>
|
||||
/// <param name="requestCode">The requestCode. If no requestCode is supplied, the property from the PocketClient intialization is used.</param>
|
||||
/// <returns>The permanent access code, which is used to authenticate the user with the application</returns>
|
||||
/// <param name="requestCode">The request code.</param>
|
||||
/// <returns>
|
||||
/// The authenticated user
|
||||
/// </returns>
|
||||
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
[Obsolete("Please use GetUser instead")]
|
||||
public async Task<string> GetAccessCode(string requestCode = null)
|
||||
public async Task<PocketUser> GetUser(string requestCode = null)
|
||||
{
|
||||
await GetUser(requestCode);
|
||||
return AccessCode;
|
||||
return await GetUser(CancellationToken.None, requestCode);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Requests the access code and username after authentication
|
||||
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
|
||||
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="requestCode">The request code.</param>
|
||||
/// <returns>The authenticated user</returns>
|
||||
/// <returns>
|
||||
/// The authenticated user
|
||||
/// </returns>
|
||||
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
|
||||
public async Task<PocketUser> GetUser(string requestCode = null)
|
||||
public async Task<PocketUser> GetUser(CancellationToken cancellationToken, string requestCode = null)
|
||||
{
|
||||
// check if request code is available
|
||||
if (RequestCode == null && requestCode == null)
|
||||
@@ -101,7 +117,7 @@ namespace PocketSharp
|
||||
}
|
||||
|
||||
// do request
|
||||
PocketUser response = await Request<PocketUser>("oauth/authorize", new Dictionary<string, string>()
|
||||
PocketUser response = await Request<PocketUser>("oauth/authorize", cancellationToken, new Dictionary<string, string>()
|
||||
{
|
||||
{"code", RequestCode}
|
||||
}, false);
|
||||
@@ -122,15 +138,35 @@ namespace PocketSharp
|
||||
/// <param name="password">The password.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentNullException">All parameters are required</exception>
|
||||
/// <exception cref="System.FormatException">
|
||||
/// Invalid email address.
|
||||
/// <exception cref="System.FormatException">Invalid email address.
|
||||
/// or
|
||||
/// Invalid username. Please only use letters, numbers, and/or dashes and between 1-20 characters.
|
||||
/// or
|
||||
/// Invalid password.
|
||||
/// </exception>
|
||||
/// Invalid password.</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
public async Task<bool> RegisterAccount(string username, string email, string password)
|
||||
{
|
||||
return await RegisterAccount(CancellationToken.None, username, email, password);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new account.
|
||||
/// Account has to be activated via a activation email sent by Pocket.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="email">The email.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentNullException">All parameters are required</exception>
|
||||
/// <exception cref="System.FormatException">Invalid email address.
|
||||
/// or
|
||||
/// Invalid username. Please only use letters, numbers, and/or dashes and between 1-20 characters.
|
||||
/// or
|
||||
/// Invalid password.</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
public async Task<bool> RegisterAccount(CancellationToken cancellationToken, string username, string email, string password)
|
||||
{
|
||||
if (username == null || email == null || password == null)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PocketSharp.Models;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PocketSharp
|
||||
@@ -22,6 +23,25 @@ namespace PocketSharp
|
||||
/// <exception cref="System.FormatException">(1) Uri should be absolute.</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
public async Task<PocketItem> Add(Uri uri, string[] tags = null, string title = null, string tweetID = null)
|
||||
{
|
||||
return await Add(CancellationToken.None, uri, tags, title, tweetID);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new item to pocket
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="uri">The URL of the item you want to save</param>
|
||||
/// <param name="tags">A comma-separated list of tags to apply to the item</param>
|
||||
/// <param name="title">This can be included for cases where an item does not have a title, which is typical for image or PDF URLs. If Pocket detects a title from the content of the page, this parameter will be ignored.</param>
|
||||
/// <param name="tweetID">If you are adding Pocket support to a Twitter client, please send along a reference to the tweet status id. This allows Pocket to show the original tweet alongside the article.</param>
|
||||
/// <returns>
|
||||
/// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method)
|
||||
/// </returns>
|
||||
/// <exception cref="System.FormatException">(1) Uri should be absolute.</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
public async Task<PocketItem> Add(CancellationToken cancellationToken, Uri uri, string[] tags = null, string title = null, string tweetID = null)
|
||||
{
|
||||
if (!uri.IsAbsoluteUri)
|
||||
{
|
||||
@@ -36,7 +56,7 @@ namespace PocketSharp
|
||||
TweetID = tweetID
|
||||
};
|
||||
|
||||
Add response = await Request<Add>("add", parameters.Convert());
|
||||
Add response = await Request<Add>("add", cancellationToken, parameters.Convert());
|
||||
|
||||
return response.Item;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using PocketSharp.Models;
|
||||
using System.Threading;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
@@ -51,6 +52,15 @@ namespace PocketSharp
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<string> GetRequestCode();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the requestCode from Pocket, which is used to generate the Authentication URI to authenticate the user
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.NullReferenceException">Authentication methods need a callbackUri on initialization of the PocketClient class</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<string> GetRequestCode(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Generate Authentication URI from requestCode
|
||||
/// </summary>
|
||||
@@ -61,19 +71,6 @@ namespace PocketSharp
|
||||
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
|
||||
Uri GenerateAuthenticationUri(string requestCode = null);
|
||||
|
||||
/// <summary>
|
||||
/// Requests the access code after authentication
|
||||
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
|
||||
/// </summary>
|
||||
/// <param name="requestCode">The requestCode. If no requestCode is supplied, the property from the PocketClient intialization is used.</param>
|
||||
/// <returns>
|
||||
/// The permanent access code, which is used to authenticate the user with the application
|
||||
/// </returns>
|
||||
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
[Obsolete("Please use GetUser instead")]
|
||||
Task<string> GetAccessCode(string requestCode = null);
|
||||
|
||||
/// <summary>
|
||||
/// Requests the access code and username after authentication
|
||||
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
|
||||
@@ -85,6 +82,18 @@ namespace PocketSharp
|
||||
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
|
||||
Task<PocketUser> GetUser(string requestCode = null);
|
||||
|
||||
/// <summary>
|
||||
/// Requests the access code and username after authentication
|
||||
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="requestCode">The request code.</param>
|
||||
/// <returns>
|
||||
/// The authenticated user
|
||||
/// </returns>
|
||||
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
|
||||
Task<PocketUser> GetUser(CancellationToken cancellationToken, string requestCode = null);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new account.
|
||||
/// Account has to be activated via a activation email sent by Pocket.
|
||||
@@ -103,6 +112,24 @@ namespace PocketSharp
|
||||
/// </exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<bool> RegisterAccount(string username, string email, string password);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new account.
|
||||
/// Account has to be activated via a activation email sent by Pocket.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="email">The email.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentNullException">All parameters are required</exception>
|
||||
/// <exception cref="System.FormatException">Invalid email address.
|
||||
/// or
|
||||
/// Invalid username. Please only use letters, numbers, and/or dashes and between 1-20 characters.
|
||||
/// or
|
||||
/// Invalid password.</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<bool> RegisterAccount(CancellationToken cancellationToken, string username, string email, string password);
|
||||
#endregion
|
||||
|
||||
#region add methods
|
||||
@@ -119,6 +146,21 @@ namespace PocketSharp
|
||||
/// <exception cref="System.FormatException">(1) Uri should be absolute.</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<PocketItem> Add(Uri uri, string[] tags = null, string title = null, string tweetID = null);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new item to pocket
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="uri">The URL of the item you want to save</param>
|
||||
/// <param name="tags">A comma-separated list of tags to apply to the item</param>
|
||||
/// <param name="title">This can be included for cases where an item does not have a title, which is typical for image or PDF URLs. If Pocket detects a title from the content of the page, this parameter will be ignored.</param>
|
||||
/// <param name="tweetID">If you are adding Pocket support to a Twitter client, please send along a reference to the tweet status id. This allows Pocket to show the original tweet alongside the article.</param>
|
||||
/// <returns>
|
||||
/// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method)
|
||||
/// </returns>
|
||||
/// <exception cref="System.FormatException">(1) Uri should be absolute.</exception>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
Task<PocketItem> Add(CancellationToken cancellationToken, Uri uri, string[] tags = null, string title = null, string tweetID = null);
|
||||
#endregion
|
||||
|
||||
#region get methods
|
||||
|
||||
Reference in New Issue
Block a user