diff --git a/PocketSharp/Components/Account.cs b/PocketSharp/Components/Account.cs index cac5889..79b4494 100644 --- a/PocketSharp/Components/Account.cs +++ b/PocketSharp/Components/Account.cs @@ -198,7 +198,7 @@ namespace PocketSharp Password = password }; - ResponseBase response = await Request("signup", parameters.Convert(), false); + ResponseBase response = await Request("signup", cancellationToken, parameters.Convert(), false); return response.Status; } diff --git a/PocketSharp/Components/Get.cs b/PocketSharp/Components/Get.cs index 0eadcc4..4a51a72 100644 --- a/PocketSharp/Components/Get.cs +++ b/PocketSharp/Components/Get.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; +using System.Threading; namespace PocketSharp { @@ -11,22 +12,22 @@ namespace PocketSharp /// public partial class PocketClient { - /// - /// Retrieves items from pocket - /// with the given filters - /// - /// The state. - /// The favorite. - /// The tag. - /// Type of the content. - /// The sort. - /// The search. - /// The domain. - /// The since. - /// The count. - /// The offset. - /// - /// + /// + /// Retrieves items from pocket + /// with the given filters + /// + /// The state. + /// The favorite. + /// The tag. + /// Type of the content. + /// The sort. + /// The search. + /// The domain. + /// The since. + /// The count. + /// The offset. + /// + /// public async Task> Get( State? state = null, bool? favorite = null, @@ -39,6 +40,41 @@ namespace PocketSharp int? count = null, int? offset = null ) + { + return await Get(CancellationToken.None, state, favorite, tag, contentType, sort, search, domain, since, count, offset); + } + + + /// + /// Retrieves items from pocket + /// with the given filters + /// + /// The cancellation token. + /// The state. + /// The favorite. + /// The tag. + /// Type of the content. + /// The sort. + /// The search. + /// The domain. + /// The since. + /// The count. + /// The offset. + /// + /// + public async Task> Get( + CancellationToken cancellationToken, + State? state = null, + bool? favorite = null, + string tag = null, + ContentType? contentType = null, + Sort? sort = null, + string search = null, + string domain = null, + DateTime? since = null, + int? count = null, + int? offset = null + ) { RetrieveParameters parameters = new RetrieveParameters() { @@ -55,7 +91,7 @@ namespace PocketSharp Offset = offset }; - Retrieve response = await Request("get", parameters.Convert()); + Retrieve response = await Request("get", cancellationToken, parameters.Convert()); return response.Items; } @@ -69,8 +105,23 @@ namespace PocketSharp /// /// public async Task Get(int itemID) + { + return await Get(CancellationToken.None, itemID); + } + + + /// + /// Retrieves an item by a given ID + /// Note: The Pocket API contains no method, which allows to retrieve a single item, so all items are retrieved and filtered locally by the ID. + /// + /// The cancellation token. + /// The item ID. + /// + /// + public async Task Get(CancellationToken cancellationToken, int itemID) { List items = await Get( + cancellationToken: cancellationToken, state: State.all ); @@ -85,10 +136,23 @@ namespace PocketSharp /// /// public async Task> Get(RetrieveFilter filter) + { + return await Get(CancellationToken.None, filter); + } + + + /// + /// Retrieves all items by a given filter + /// + /// The cancellation token. + /// The filter. + /// + /// + public async Task> Get(CancellationToken cancellationToken, RetrieveFilter filter) { RetrieveParameters parameters = new RetrieveParameters(); - switch(filter) + switch (filter) { case RetrieveFilter.Article: parameters.ContentType = ContentType.article; @@ -115,7 +179,7 @@ namespace PocketSharp parameters.DetailType = DetailType.complete; - Retrieve response = await Request("get", parameters.Convert()); + Retrieve response = await Request("get", cancellationToken, parameters.Convert()); return response.Items; } @@ -128,8 +192,22 @@ namespace PocketSharp /// /// public async Task> GetTags() + { + return await GetTags(CancellationToken.None); + } + + + /// + /// Retrieves all available tags. + /// Note: The Pocket API contains no method, which allows to retrieve all tags, so all items are retrieved and the associated tags extracted. + /// + /// The cancellation token. + /// + /// + public async Task> GetTags(CancellationToken cancellationToken) { List items = await Get( + cancellationToken: cancellationToken, state: State.all ); @@ -149,7 +227,23 @@ namespace PocketSharp /// public async Task> SearchByTag(string tag) { - return await Get(tag: tag); + return await SearchByTag(CancellationToken.None, tag); + } + + + /// + /// Retrieves items by tag + /// + /// The cancellation token. + /// The tag. + /// + /// + public async Task> SearchByTag(CancellationToken cancellationToken, string tag) + { + return await Get( + cancellationToken: cancellationToken, + tag: tag + ); } @@ -162,8 +256,22 @@ namespace PocketSharp /// public async Task> Search(string searchString, bool searchInUri = true) { - List items = await Get(RetrieveFilter.All); + return await Search(CancellationToken.None, searchString, searchInUri); + } + + /// + /// Retrieves items which match the specified search string in title and URI + /// + /// The cancellation token. + /// The search string. + /// if set to true [search in URI]. + /// + /// Search string length has to be a minimum of 2 chars + /// + public async Task> Search(CancellationToken cancellationToken, string searchString, bool searchInUri = true) + { + List items = await Get(cancellationToken, RetrieveFilter.All); return Search(items, searchString); } diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs index f35c389..03fb22e 100644 --- a/PocketSharp/IPocketClient.cs +++ b/PocketSharp/IPocketClient.cs @@ -181,17 +181,48 @@ namespace PocketSharp /// /// Task> Get( - State? state = null, - bool? favorite = null, - string tag = null, - ContentType? contentType = null, - Sort? sort = null, - string search = null, - string domain = null, - DateTime? since = null, - int? count = null, - int? offset = null - ); + State? state = null, + bool? favorite = null, + string tag = null, + ContentType? contentType = null, + Sort? sort = null, + string search = null, + string domain = null, + DateTime? since = null, + int? count = null, + int? offset = null + ); + + /// + /// Retrieves items from pocket + /// with the given filters + /// + /// The cancellation token. + /// The state. + /// The favorite. + /// The tag. + /// Type of the content. + /// The sort. + /// The search. + /// The domain. + /// The since. + /// The count. + /// The offset. + /// + /// + Task> Get( + CancellationToken cancellationToken, + State? state = null, + bool? favorite = null, + string tag = null, + ContentType? contentType = null, + Sort? sort = null, + string search = null, + string domain = null, + DateTime? since = null, + int? count = null, + int? offset = null + ); /// /// Retrieves an item by a given ID @@ -202,6 +233,16 @@ namespace PocketSharp /// Task Get(int itemID); + /// + /// Retrieves an item by a given ID + /// Note: The Pocket API contains no method, which allows to retrieve a single item, so all items are retrieved and filtered locally by the ID. + /// + /// The cancellation token. + /// The item ID. + /// + /// + Task Get(CancellationToken cancellationToken, int itemID); + /// /// Retrieves all items by a given filter /// @@ -210,6 +251,15 @@ namespace PocketSharp /// Task> Get(RetrieveFilter filter); + /// + /// Retrieves all items by a given filter + /// + /// The cancellation token. + /// The filter. + /// + /// + Task> Get(CancellationToken cancellationToken, RetrieveFilter filter); + /// /// Retrieves all available tags. /// Note: The Pocket API contains no method, which allows to retrieve all tags, so all items are retrieved and the associated tags extracted. @@ -218,6 +268,15 @@ namespace PocketSharp /// Task> GetTags(); + /// + /// Retrieves all available tags. + /// Note: The Pocket API contains no method, which allows to retrieve all tags, so all items are retrieved and the associated tags extracted. + /// + /// The cancellation token. + /// + /// + Task> GetTags(CancellationToken cancellationToken); + /// /// Retrieves items by tag /// @@ -226,6 +285,15 @@ namespace PocketSharp /// Task> SearchByTag(string tag); + /// + /// Retrieves items by tag + /// + /// The cancellation token. + /// The tag. + /// + /// + Task> SearchByTag(CancellationToken cancellationToken, string tag); + /// /// Retrieves items which match the specified search string in title and URI /// @@ -235,6 +303,17 @@ namespace PocketSharp /// Task> Search(string searchString, bool searchInUri = true); + /// + /// Retrieves items which match the specified search string in title and URI + /// + /// The cancellation token. + /// The search string. + /// if set to true [search in URI]. + /// + /// Search string length has to be a minimum of 2 chars + /// + Task> Search(CancellationToken cancellationToken, string searchString, bool searchInUri = true); + /// /// Finds the specified search string in title and URI for an available list of items ///