From 95d7a5d99317e128a1730a865b7ef36f312abae7 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Fri, 8 Nov 2013 09:31:35 +0100 Subject: [PATCH] make CancellationToken an optional parameter --- PocketSharp.Tests/GetTests.cs | 1 - PocketSharp.Tests/StressTests.cs | 2 +- PocketSharp/Components/Account.cs | 54 +--- PocketSharp/Components/Add.cs | 26 +- PocketSharp/Components/Get.cs | 113 +------ PocketSharp/Components/Modify.cs | 157 ++-------- PocketSharp/Components/ModifyTags.cs | 260 ++++------------ PocketSharp/Components/Statistics.cs | 28 +- PocketSharp/IPocketClient.cs | 424 ++++----------------------- 9 files changed, 142 insertions(+), 923 deletions(-) diff --git a/PocketSharp.Tests/GetTests.cs b/PocketSharp.Tests/GetTests.cs index 3678084..c383508 100644 --- a/PocketSharp.Tests/GetTests.cs +++ b/PocketSharp.Tests/GetTests.cs @@ -16,7 +16,6 @@ namespace PocketSharp.Tests public async Task AreItemsRetrieved() { List items = await client.Get(); - Assert.True(items.Count > 0); } diff --git a/PocketSharp.Tests/StressTests.cs b/PocketSharp.Tests/StressTests.cs index 4287c8d..2ff59e7 100644 --- a/PocketSharp.Tests/StressTests.cs +++ b/PocketSharp.Tests/StressTests.cs @@ -31,7 +31,7 @@ namespace PocketSharp.Tests [Fact] public async Task Are100IdingtemsRetrievedProperly() { - await FillAccount(3817, 10000); + await FillAccount(4457, 10000); } [Fact] diff --git a/PocketSharp/Components/Account.cs b/PocketSharp/Components/Account.cs index 79b4494..a382a72 100644 --- a/PocketSharp/Components/Account.cs +++ b/PocketSharp/Components/Account.cs @@ -12,18 +12,6 @@ namespace PocketSharp /// public partial class PocketClient { - /// - /// Retrieves the requestCode from Pocket, which is used to generate the Authentication URI to authenticate the user - /// - /// - /// Authentication methods need a callbackUri on initialization of the PocketClient class - /// - public async Task GetRequestCode() - { - return await GetRequestCode(CancellationToken.None); - } - - /// /// Retrieves the requestCode from Pocket, which is used to generate the Authentication URI to authenticate the user /// @@ -31,7 +19,7 @@ namespace PocketSharp /// /// Authentication methods need a callbackUri on initialization of the PocketClient class /// - public async Task GetRequestCode(CancellationToken cancellationToken) + public async Task GetRequestCode(CancellationToken cancellationToken = default(CancellationToken)) { // check if request code is available if (CallbackUri == null) @@ -77,21 +65,6 @@ namespace PocketSharp } - /// - /// 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 request code. - /// - /// The authenticated user - /// - /// Call GetRequestCode() first to receive a request_code - public async Task GetUser(string requestCode = null) - { - return await GetUser(CancellationToken.None, requestCode); - } - - /// /// 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. @@ -102,7 +75,7 @@ namespace PocketSharp /// The authenticated user /// /// Call GetRequestCode() first to receive a request_code - public async Task GetUser(CancellationToken cancellationToken, string requestCode = null) + public async Task GetUser(string requestCode = null, CancellationToken cancellationToken = default(CancellationToken)) { // check if request code is available if (RequestCode == null && requestCode == null) @@ -136,28 +109,7 @@ namespace PocketSharp /// The username. /// The email. /// The password. - /// - /// All parameters are required - /// Invalid email address. - /// or - /// Invalid username. Please only use letters, numbers, and/or dashes and between 1-20 characters. - /// or - /// Invalid password. - /// - public async Task RegisterAccount(string username, string email, string password) - { - return await RegisterAccount(CancellationToken.None, username, email, password); - } - - - /// - /// Registers a new account. - /// Account has to be activated via a activation email sent by Pocket. - /// /// The cancellation token. - /// The username. - /// The email. - /// The password. /// /// All parameters are required /// Invalid email address. @@ -166,7 +118,7 @@ namespace PocketSharp /// or /// Invalid password. /// - public async Task RegisterAccount(CancellationToken cancellationToken, string username, string email, string password) + public async Task RegisterAccount(string username, string email, string password, CancellationToken cancellationToken = default(CancellationToken)) { if (username == null || email == null || password == null) { diff --git a/PocketSharp/Components/Add.cs b/PocketSharp/Components/Add.cs index 18418f0..7e4fe79 100644 --- a/PocketSharp/Components/Add.cs +++ b/PocketSharp/Components/Add.cs @@ -17,31 +17,19 @@ namespace PocketSharp /// A comma-separated list of tags to apply to the item /// 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. /// 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. - /// - /// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method) - /// - /// (1) Uri should be absolute. - /// - public async Task Add(Uri uri, string[] tags = null, string title = null, string tweetID = null) - { - return await Add(CancellationToken.None, uri, tags, title, tweetID); - } - - - /// - /// Adds a new item to pocket - /// /// The cancellation token. - /// The URL of the item you want to save - /// A comma-separated list of tags to apply to the item - /// 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. - /// 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. /// /// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method) /// /// (1) Uri should be absolute. /// - public async Task Add(CancellationToken cancellationToken, Uri uri, string[] tags = null, string title = null, string tweetID = null) + public async Task Add( + Uri uri, + string[] tags = null, + string title = null, + string tweetID = null, + CancellationToken cancellationToken = default(CancellationToken) + ) { if (!uri.IsAbsoluteUri) { diff --git a/PocketSharp/Components/Get.cs b/PocketSharp/Components/Get.cs index 4a51a72..3206dca 100644 --- a/PocketSharp/Components/Get.cs +++ b/PocketSharp/Components/Get.cs @@ -26,44 +26,10 @@ namespace PocketSharp /// The since. /// The count. /// The offset. - /// - /// - public async 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 - ) - { - 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, @@ -73,7 +39,8 @@ namespace PocketSharp string domain = null, DateTime? since = null, int? count = null, - int? offset = null + int? offset = null, + CancellationToken cancellationToken = default(CancellationToken) ) { RetrieveParameters parameters = new RetrieveParameters() @@ -102,23 +69,10 @@ namespace PocketSharp /// 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 item ID. - /// - /// - 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) + public async Task Get(int itemID, CancellationToken cancellationToken = default(CancellationToken)) { List items = await Get( cancellationToken: cancellationToken, @@ -133,22 +87,10 @@ namespace PocketSharp /// Retrieves all items by a given filter /// /// The filter. - /// - /// - 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) + public async Task> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken)) { RetrieveParameters parameters = new RetrieveParameters(); @@ -185,18 +127,6 @@ namespace PocketSharp } - /// - /// 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. - /// - /// - /// - 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. @@ -204,7 +134,7 @@ namespace PocketSharp /// The cancellation token. /// /// - public async Task> GetTags(CancellationToken cancellationToken) + public async Task> GetTags(CancellationToken cancellationToken = default(CancellationToken)) { List items = await Get( cancellationToken: cancellationToken, @@ -223,22 +153,10 @@ namespace PocketSharp /// Retrieves items by tag /// /// The tag. - /// - /// - public async Task> SearchByTag(string tag) - { - return await SearchByTag(CancellationToken.None, tag); - } - - - /// - /// Retrieves items by tag - /// /// The cancellation token. - /// The tag. /// /// - public async Task> SearchByTag(CancellationToken cancellationToken, string tag) + public async Task> SearchByTag(string tag, CancellationToken cancellationToken = default(CancellationToken)) { return await Get( cancellationToken: cancellationToken, @@ -251,27 +169,14 @@ namespace PocketSharp /// Retrieves items which match the specified search string in title and URI /// /// The search string. - /// - /// Search string length has to be a minimum of 2 chars - /// - public async Task> Search(string searchString, bool searchInUri = true) - { - 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]. + /// The cancellation token. /// /// Search string length has to be a minimum of 2 chars /// - public async Task> Search(CancellationToken cancellationToken, string searchString, bool searchInUri = true) + public async Task> Search(string searchString, bool searchInUri = true, CancellationToken cancellationToken = default(CancellationToken)) { - List items = await Get(cancellationToken, RetrieveFilter.All); + List items = await Get(RetrieveFilter.All, cancellationToken); return Search(items, searchString); } diff --git a/PocketSharp/Components/Modify.cs b/PocketSharp/Components/Modify.cs index 8503a1f..0a697aa 100644 --- a/PocketSharp/Components/Modify.cs +++ b/PocketSharp/Components/Modify.cs @@ -13,34 +13,10 @@ namespace PocketSharp /// Archives the specified item. /// /// The item ID. - /// - /// - public async Task Archive(int itemID) - { - return await Archive(CancellationToken.None, itemID); - } - - - /// - /// Archives the specified item. - /// - /// The item. - /// - /// - public async Task Archive(PocketItem item) - { - return await Archive(CancellationToken.None, item.ID); - } - - - /// - /// Archives the specified item. - /// /// The cancellation token. - /// The item ID. /// /// - public async Task Archive(CancellationToken cancellationToken, int itemID) + public async Task Archive(int itemID, CancellationToken cancellationToken = default(CancellationToken)) { return await SendDefault(cancellationToken, itemID, "archive"); } @@ -49,13 +25,13 @@ namespace PocketSharp /// /// Archives the specified item. /// - /// The cancellation token. /// The item. + /// The cancellation token. /// /// - public async Task Archive(CancellationToken cancellationToken, PocketItem item) + public async Task Archive(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)) { - return await Archive(cancellationToken, item.ID); + return await Archive(item.ID, cancellationToken); } @@ -63,34 +39,10 @@ namespace PocketSharp /// Un-archives the specified item (alias for Readd). /// /// The item ID. - /// - /// - public async Task Unarchive(int itemID) - { - return await Unarchive(CancellationToken.None, itemID); - } - - - /// - /// Unarchives the specified item. - /// - /// The item. - /// - /// - public async Task Unarchive(PocketItem item) - { - return await Unarchive(CancellationToken.None, item.ID); - } - - - /// - /// Un-archives the specified item (alias for Readd). - /// /// The cancellation token. - /// The item ID. /// /// - public async Task Unarchive(CancellationToken cancellationToken, int itemID) + public async Task Unarchive(int itemID, CancellationToken cancellationToken = default(CancellationToken)) { return await SendDefault(cancellationToken, itemID, "readd"); } @@ -99,13 +51,13 @@ namespace PocketSharp /// /// Unarchives the specified item. /// - /// The cancellation token. /// The item. + /// The cancellation token. /// /// - public async Task Unarchive(CancellationToken cancellationToken, PocketItem item) + public async Task Unarchive(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)) { - return await Unarchive(cancellationToken, item.ID); + return await Unarchive(item.ID, cancellationToken); } @@ -113,34 +65,10 @@ namespace PocketSharp /// Favorites the specified item. /// /// The item ID. - /// - /// - public async Task Favorite(int itemID) - { - return await Favorite(CancellationToken.None, itemID); - } - - - /// - /// Favorites the specified item. - /// - /// The item. - /// - /// - public async Task Favorite(PocketItem item) - { - return await Favorite(CancellationToken.None, item.ID); - } - - - /// - /// Favorites the specified item. - /// /// The cancellation token. - /// The item ID. /// /// - public async Task Favorite(CancellationToken cancellationToken, int itemID) + public async Task Favorite(int itemID, CancellationToken cancellationToken = default(CancellationToken)) { return await SendDefault(cancellationToken, itemID, "favorite"); } @@ -149,13 +77,13 @@ namespace PocketSharp /// /// Favorites the specified item. /// - /// The cancellation token. /// The item. + /// The cancellation token. /// /// - public async Task Favorite(CancellationToken cancellationToken, PocketItem item) + public async Task Favorite(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)) { - return await Favorite(cancellationToken, item.ID); + return await Favorite(item.ID, cancellationToken); } @@ -163,34 +91,10 @@ namespace PocketSharp /// Un-favorites the specified item. /// /// The item ID. - /// - /// - public async Task Unfavorite(int itemID) - { - return await Unfavorite(CancellationToken.None, itemID); - } - - - /// - /// Un-favorites the specified item. - /// - /// The item. - /// - /// - public async Task Unfavorite(PocketItem item) - { - return await Unfavorite(CancellationToken.None, item.ID); - } - - - /// - /// Un-favorites the specified item. - /// /// The cancellation token. - /// The item ID. /// /// - public async Task Unfavorite(CancellationToken cancellationToken, int itemID) + public async Task Unfavorite(int itemID, CancellationToken cancellationToken = default(CancellationToken)) { return await SendDefault(cancellationToken, itemID, "unfavorite"); } @@ -199,36 +103,13 @@ namespace PocketSharp /// /// Un-favorites the specified item. /// + /// The item. /// The cancellation token. - /// The item. /// /// - public async Task Unfavorite(CancellationToken cancellationToken, PocketItem item) + public async Task Unfavorite(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)) { - return await Unfavorite(cancellationToken, item.ID); - } - - - /// - /// Deletes the specified item. - /// - /// The item ID. - /// - /// - public async Task Delete(int itemID) - { - return await Delete(CancellationToken.None, itemID); - } - - - /// - /// Deletes the specified item. - /// - /// The item. - /// - public async Task Delete(PocketItem item) - { - return await Delete(CancellationToken.None, item.ID); + return await Unfavorite(item.ID, cancellationToken); } @@ -239,7 +120,7 @@ namespace PocketSharp /// The item ID. /// /// - public async Task Delete(CancellationToken cancellationToken, int itemID) + public async Task Delete(int itemID, CancellationToken cancellationToken = default(CancellationToken)) { return await SendDefault(cancellationToken, itemID, "delete"); } @@ -251,9 +132,9 @@ namespace PocketSharp /// The cancellation token. /// The item. /// - public async Task Delete(CancellationToken cancellationToken, PocketItem item) + public async Task Delete(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)) { - return await Delete(cancellationToken, item.ID); + return await Delete(item.ID, cancellationToken); } diff --git a/PocketSharp/Components/ModifyTags.cs b/PocketSharp/Components/ModifyTags.cs index 4e81995..1ed0291 100644 --- a/PocketSharp/Components/ModifyTags.cs +++ b/PocketSharp/Components/ModifyTags.cs @@ -14,36 +14,10 @@ namespace PocketSharp /// /// The item ID. /// The tags. - /// - /// - public async Task AddTags(int itemID, string[] tags) - { - return await AddTags(CancellationToken.None, itemID, tags); - } - - - /// - /// Adds the specified tags to an item. - /// - /// The item. - /// The tags. - /// - /// - public async Task AddTags(PocketItem item, string[] tags) - { - return await AddTags(CancellationToken.None, item.ID, tags); - } - - - /// - /// Adds the specified tags to an item. - /// /// The cancellation token. - /// The item ID. - /// The tags. /// /// - public async Task AddTags(CancellationToken cancellationToken, int itemID, string[] tags) + public async Task AddTags(int itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken)) { return await SendTags(cancellationToken, itemID, "tags_add", tags); } @@ -52,14 +26,14 @@ namespace PocketSharp /// /// Adds the specified tags to an item. /// - /// The cancellation token. /// The item. /// The tags. + /// The cancellation token. /// /// - public async Task AddTags(CancellationToken cancellationToken, PocketItem item, string[] tags) + public async Task AddTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken)) { - return await AddTags(cancellationToken, item.ID, tags); + return await AddTags(item.ID, tags, cancellationToken); } @@ -68,36 +42,10 @@ namespace PocketSharp /// /// The item ID. /// The tags. - /// - /// - public async Task RemoveTags(int itemID, string[] tags) - { - return await RemoveTags(CancellationToken.None, itemID, tags); - } - - - /// - /// Removes the specified tags from an item. - /// - /// The item. - /// The tag. - /// - /// - public async Task RemoveTags(PocketItem item, string[] tags) - { - return await RemoveTags(CancellationToken.None, item.ID, tags); - } - - - /// - /// Removes the specified tags from an item. - /// /// The cancellation token. - /// The item ID. - /// The tags. /// /// - public async Task RemoveTags(CancellationToken cancellationToken, int itemID, string[] tags) + public async Task RemoveTags(int itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken)) { return await SendTags(cancellationToken, itemID, "tags_remove", tags); } @@ -106,52 +54,26 @@ namespace PocketSharp /// /// Removes the specified tags from an item. /// - /// The cancellation token. /// The item. /// The tag. - /// - /// - public async Task RemoveTags(CancellationToken cancellationToken, PocketItem item, string[] tags) - { - return await RemoveTags(cancellationToken, item.ID, tags); - } - - - /// - /// Removes a tag from an item. - /// - /// The item ID. - /// The tag. - /// - /// - public async Task RemoveTag(int itemID, string tag) - { - return await RemoveTag(CancellationToken.None, itemID, tag); - } - - - /// - /// Removes a tag from an item. - /// - /// The item. - /// The tags. - /// - /// - public async Task RemoveTag(PocketItem item, string tag) - { - return await RemoveTag(CancellationToken.None, item.ID, tag); - } - - - /// - /// Removes a tag from an item. - /// /// The cancellation token. + /// + /// + public async Task RemoveTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken)) + { + return await RemoveTags(item.ID, tags, cancellationToken); + } + + + /// + /// Removes a tag from an item. + /// /// The item ID. /// The tag. + /// The cancellation token. /// /// - public async Task RemoveTag(CancellationToken cancellationToken, int itemID, string tag) + public async Task RemoveTag(int itemID, string tag, CancellationToken cancellationToken = default(CancellationToken)) { return await SendTags(cancellationToken, itemID, "tags_remove", new string[] { tag }); } @@ -160,49 +82,25 @@ namespace PocketSharp /// /// Removes a tag from an item. /// - /// The cancellation token. /// The item. /// The tag. - /// - /// - public async Task RemoveTag(CancellationToken cancellationToken, PocketItem item, string tag) - { - return await RemoveTag(cancellationToken, item.ID, tag); - } - - - /// - /// Clears all tags from an item. - /// - /// The item ID. - /// - /// - public async Task RemoveTags(int itemID) - { - return await RemoveTags(CancellationToken.None, itemID); - } - - - /// - /// Clears all tags from an item. - /// - /// The item. - /// - /// - public async Task RemoveTags(PocketItem item) - { - return await RemoveTags(CancellationToken.None, item.ID); - } - - - /// - /// Clears all tags from an item. - /// /// The cancellation token. - /// The item ID. /// /// - public async Task RemoveTags(CancellationToken cancellationToken, int itemID) + public async Task RemoveTag(PocketItem item, string tag, CancellationToken cancellationToken = default(CancellationToken)) + { + return await RemoveTag(item.ID, tag, cancellationToken); + } + + + /// + /// Clears all tags from an item. + /// + /// The item ID. + /// The cancellation token. + /// + /// + public async Task RemoveTags(int itemID, CancellationToken cancellationToken = default(CancellationToken)) { return await SendDefault(cancellationToken, itemID, "tags_clear"); } @@ -211,13 +109,13 @@ namespace PocketSharp /// /// Clears all tags from an item. /// - /// The cancellation token. /// The item. + /// The cancellation token. /// /// - public async Task RemoveTags(CancellationToken cancellationToken, PocketItem item) + public async Task RemoveTags(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)) { - return await RemoveTags(cancellationToken, item.ID); + return await RemoveTags(item.ID, cancellationToken); } @@ -226,36 +124,10 @@ namespace PocketSharp /// /// The item ID. /// The tags. - /// - /// - public async Task ReplaceTags(int itemID, string[] tags) - { - return await ReplaceTags(CancellationToken.None, itemID, tags); - } - - - /// - /// Replaces all existing tags with the given new ones in an item. - /// - /// The item. - /// The tags. - /// - /// - public async Task ReplaceTags(PocketItem item, string[] tags) - { - return await ReplaceTags(CancellationToken.None, item.ID, tags); - } - - - /// - /// Replaces all existing tags with the given tags in an item. - /// /// The cancellation token. - /// The item ID. - /// The tags. /// /// - public async Task ReplaceTags(CancellationToken cancellationToken, int itemID, string[] tags) + public async Task ReplaceTags(int itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken)) { return await SendTags(cancellationToken, itemID, "tags_replace", tags); } @@ -264,55 +136,27 @@ namespace PocketSharp /// /// Replaces all existing tags with the given new ones in an item. /// - /// The cancellation token. /// The item. /// The tags. - /// - /// - public async Task ReplaceTags(CancellationToken cancellationToken, PocketItem item, string[] tags) - { - return await ReplaceTags(cancellationToken, item.ID, tags); - } - - - /// - /// Renames a tag in an item. - /// - /// The item ID. - /// The old tag. - /// The new tag name. - /// - /// - public async Task RenameTag(int itemID, string oldTag, string newTag) - { - return await RenameTag(CancellationToken.None, itemID, oldTag, newTag); - } - - - /// - /// Renames a tag in an item. - /// - /// The item. - /// The old tag. - /// The new tag name. - /// - /// - public async Task RenameTag(PocketItem item, string oldTag, string newTag) - { - return await RenameTag(CancellationToken.None, item.ID, oldTag, newTag); - } - - - /// - /// Renames a tag in an item. - /// /// The cancellation token. + /// + /// + public async Task ReplaceTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken)) + { + return await ReplaceTags(item.ID, tags, cancellationToken); + } + + + /// + /// Renames a tag in an item. + /// /// The item ID. /// The old tag. /// The new tag name. + /// The cancellation token. /// /// - public async Task RenameTag(CancellationToken cancellationToken, int itemID, string oldTag, string newTag) + public async Task RenameTag(int itemID, string oldTag, string newTag, CancellationToken cancellationToken = default(CancellationToken)) { return await Send(new ActionParameter() { @@ -327,15 +171,15 @@ namespace PocketSharp /// /// Renames a tag in an item. /// - /// The cancellation token. /// The item. /// The old tag. /// The new tag name. + /// The cancellation token. /// /// - public async Task RenameTag(CancellationToken cancellationToken, PocketItem item, string oldTag, string newTag) + public async Task RenameTag(PocketItem item, string oldTag, string newTag, CancellationToken cancellationToken = default(CancellationToken)) { - return await RenameTag(cancellationToken, item.ID, oldTag, newTag); + return await RenameTag(item.ID, oldTag, newTag, cancellationToken); } diff --git a/PocketSharp/Components/Statistics.cs b/PocketSharp/Components/Statistics.cs index 40d776a..6c15b57 100644 --- a/PocketSharp/Components/Statistics.cs +++ b/PocketSharp/Components/Statistics.cs @@ -10,42 +10,18 @@ namespace PocketSharp /// public partial class PocketClient { - /// - /// Statistics from the user account. - /// - /// - /// - public async Task GetUserStatistics() - { - return await GetUserStatistics(CancellationToken.None); - } - - /// /// Statistics from the user account. /// /// The cancellation token. /// /// - public async Task GetUserStatistics(CancellationToken cancellationToken) + public async Task GetUserStatistics(CancellationToken cancellationToken = default(CancellationToken)) { return await Request("stats", cancellationToken); } - /// - /// Returns API usage statistics. - /// If a request was made before, the data is returned synchronously from the cache. - /// Note: This method only works for authenticated users with a given AccessCode. - /// - /// - /// - public async Task GetUsageLimits() - { - return await GetUsageLimits(CancellationToken.None); - } - - /// /// Returns API usage statistics. /// If a request was made before, the data is returned synchronously from the cache. @@ -54,7 +30,7 @@ namespace PocketSharp /// The cancellation token. /// /// - public async Task GetUsageLimits(CancellationToken cancellationToken) + public async Task GetUsageLimits(CancellationToken cancellationToken = default(CancellationToken)) { string rateLimitForConsumerKey = TryGetHeaderValue(lastHeaders, "X-Limit-Key-Limit"); diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs index 5f47b3f..e27c032 100644 --- a/PocketSharp/IPocketClient.cs +++ b/PocketSharp/IPocketClient.cs @@ -44,14 +44,6 @@ namespace PocketSharp #endregion #region account methods - /// - /// Retrieves the requestCode from Pocket, which is used to generate the Authentication URI to authenticate the user - /// - /// - /// Authentication methods need a callbackUri on initialization of the PocketClient class - /// - Task GetRequestCode(); - /// /// Retrieves the requestCode from Pocket, which is used to generate the Authentication URI to authenticate the user /// @@ -59,7 +51,7 @@ namespace PocketSharp /// /// Authentication methods need a callbackUri on initialization of the PocketClient class /// - Task GetRequestCode(CancellationToken cancellationToken); + Task GetRequestCode(CancellationToken cancellationToken = default(CancellationToken)); /// /// Generate Authentication URI from requestCode @@ -76,23 +68,12 @@ namespace PocketSharp /// 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 request code. - /// - /// The authenticated user - /// - /// Call GetRequestCode() first to receive a request_code - Task GetUser(string requestCode = null); - - /// - /// 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 cancellation token. - /// The request code. /// /// The authenticated user /// /// Call GetRequestCode() first to receive a request_code - Task GetUser(CancellationToken cancellationToken, string requestCode = null); + Task GetUser(string requestCode = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Registers a new account. @@ -101,26 +82,7 @@ namespace PocketSharp /// The username. /// The email. /// The password. - /// - /// All parameters are required - /// - /// Invalid email address. - /// or - /// Invalid username. Please only use letters, numbers, and/or dashes and between 1-20 characters. - /// or - /// Invalid password. - /// - /// - Task RegisterAccount(string username, string email, string password); - - /// - /// Registers a new account. - /// Account has to be activated via a activation email sent by Pocket. - /// /// The cancellation token. - /// The username. - /// The email. - /// The password. /// /// All parameters are required /// Invalid email address. @@ -129,7 +91,7 @@ namespace PocketSharp /// or /// Invalid password. /// - Task RegisterAccount(CancellationToken cancellationToken, string username, string email, string password); + Task RegisterAccount(string username, string email, string password, CancellationToken cancellationToken = default(CancellationToken)); #endregion #region add methods @@ -140,27 +102,13 @@ namespace PocketSharp /// A comma-separated list of tags to apply to the item /// 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. /// 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. - /// - /// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method) - /// - /// (1) Uri should be absolute. - /// - Task Add(Uri uri, string[] tags = null, string title = null, string tweetID = null); - - /// - /// Adds a new item to pocket - /// /// The cancellation token. - /// The URL of the item you want to save - /// A comma-separated list of tags to apply to the item - /// 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. - /// 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. /// /// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method) /// /// (1) Uri should be absolute. /// - Task Add(CancellationToken cancellationToken, Uri uri, string[] tags = null, string title = null, string tweetID = null); + Task Add(Uri uri, string[] tags = null, string title = null, string tweetID = null, CancellationToken cancellationToken = default(CancellationToken)); #endregion #region get methods @@ -178,6 +126,7 @@ namespace PocketSharp /// The since. /// The count. /// The offset. + /// The cancellation token. /// /// Task> Get( @@ -190,38 +139,8 @@ namespace PocketSharp 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 + int? offset = null, + CancellationToken cancellationToken = default(CancellationToken) ); /// @@ -229,44 +148,19 @@ namespace PocketSharp /// 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 item ID. - /// - /// - 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); + Task Get(int itemID, CancellationToken cancellationToken = default(CancellationToken)); /// /// Retrieves all items by a given filter /// /// The filter. - /// - /// - 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. - /// - /// - /// - Task> GetTags(); + Task> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken)); /// /// Retrieves all available tags. @@ -275,44 +169,27 @@ namespace PocketSharp /// The cancellation token. /// /// - Task> GetTags(CancellationToken cancellationToken); + Task> GetTags(CancellationToken cancellationToken = default(CancellationToken)); /// /// Retrieves items by tag /// /// The tag. - /// - /// - Task> SearchByTag(string tag); - - /// - /// Retrieves items by tag - /// /// The cancellation token. - /// The tag. /// /// - Task> SearchByTag(CancellationToken cancellationToken, string tag); + Task> SearchByTag(string tag, CancellationToken cancellationToken = default(CancellationToken)); /// /// Retrieves items which match the specified search string in title and URI /// /// The search string. - /// - /// Search string length has to be a minimum of 2 chars - /// - 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]. + /// The cancellation token. /// /// Search string length has to be a minimum of 2 chars /// - Task> Search(CancellationToken cancellationToken, string searchString, bool searchInUri = true); + Task> Search(string searchString, bool searchInUri = true, CancellationToken cancellationToken = default(CancellationToken)); /// /// Finds the specified search string in title and URI for an available list of items @@ -330,169 +207,90 @@ namespace PocketSharp /// Archives the specified item. /// /// The item ID. + /// The cancellation token. /// /// - Task Archive(int itemID); + Task Archive(int itemID, CancellationToken cancellationToken = default(CancellationToken)); /// /// Archives the specified item. /// /// The item. - /// - /// - Task Archive(PocketItem item); - - /// - /// Archives the specified item. - /// /// The cancellation token. - /// The item ID. /// /// - Task Archive(CancellationToken cancellationToken, int itemID); - - /// - /// Archives the specified item. - /// - /// The cancellation token. - /// The item. - /// - /// - Task Archive(CancellationToken cancellationToken, PocketItem item); + Task Archive(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)); /// /// Un-archives the specified item (alias for Readd). /// /// The item ID. + /// The cancellation token. /// /// - Task Unarchive(int itemID); + Task Unarchive(int itemID, CancellationToken cancellationToken = default(CancellationToken)); /// /// Unarchives the specified item. /// /// The item. - /// - /// - Task Unarchive(PocketItem item); - - /// - /// Un-archives the specified item (alias for Readd). - /// /// The cancellation token. - /// The item ID. /// /// - Task Unarchive(CancellationToken cancellationToken, int itemID); - - /// - /// Unarchives the specified item. - /// - /// The cancellation token. - /// The item. - /// - /// - Task Unarchive(CancellationToken cancellationToken, PocketItem item); + Task Unarchive(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)); /// /// Favorites the specified item. /// /// The item ID. + /// The cancellation token. /// /// - Task Favorite(int itemID); + Task Favorite(int itemID, CancellationToken cancellationToken = default(CancellationToken)); /// /// Favorites the specified item. /// /// The item. - /// - /// - Task Favorite(PocketItem item); - - /// - /// Favorites the specified item. - /// /// The cancellation token. - /// The item ID. /// /// - Task Favorite(CancellationToken cancellationToken, int itemID); - - /// - /// Favorites the specified item. - /// - /// The cancellation token. - /// The item. - /// - /// - Task Favorite(CancellationToken cancellationToken, PocketItem item); + Task Favorite(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)); /// /// Un-favorites the specified item. /// /// The item ID. + /// The cancellation token. /// /// - Task Unfavorite(int itemID); + Task Unfavorite(int itemID, CancellationToken cancellationToken = default(CancellationToken)); /// /// Un-favorites the specified item. /// /// The item. - /// - /// - Task Unfavorite(PocketItem item); - - /// - /// Un-favorites the specified item. - /// /// The cancellation token. - /// The item ID. /// /// - Task Unfavorite(CancellationToken cancellationToken, int itemID); - - /// - /// Un-favorites the specified item. - /// - /// The cancellation token. - /// The item. - /// - /// - Task Unfavorite(CancellationToken cancellationToken, PocketItem item); + Task Unfavorite(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)); /// /// Deletes the specified item. /// /// The item ID. + /// The cancellation token. /// /// - Task Delete(int itemID); + Task Delete(int itemID, CancellationToken cancellationToken = default(CancellationToken)); /// /// Deletes the specified item. /// /// The item. - /// - Task Delete(PocketItem item); - - /// - /// Deletes the specified item. - /// /// The cancellation token. - /// The item ID. /// - /// - Task Delete(CancellationToken cancellationToken, int itemID); - - /// - /// Deletes the specified item. - /// - /// The cancellation token. - /// The item. - /// - Task Delete(CancellationToken cancellationToken, PocketItem item); + Task Delete(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)); #endregion #region modify tags methods @@ -501,186 +299,98 @@ namespace PocketSharp /// /// The item ID. /// The tags. + /// The cancellation token. /// /// - Task AddTags(int itemID, string[] tags); + Task AddTags(int itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken)); /// /// Adds the specified tags to an item. /// /// The item. /// The tags. - /// - /// - Task AddTags(PocketItem item, string[] tags); - - /// - /// Adds the specified tags to an item. - /// /// The cancellation token. - /// The item ID. - /// The tags. /// /// - Task AddTags(CancellationToken cancellationToken, int itemID, string[] tags); - - /// - /// Adds the specified tags to an item. - /// - /// The cancellation token. - /// The item. - /// The tags. - /// - /// - Task AddTags(CancellationToken cancellationToken, PocketItem item, string[] tags); + Task AddTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken)); /// /// Removes the specified tags from an item. /// /// The item ID. /// The tags. + /// The cancellation token. /// /// - Task RemoveTags(int itemID, string[] tags); + Task RemoveTags(int itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken)); /// /// Removes the specified tags from an item. /// /// The item. /// The tag. - /// - /// - Task RemoveTags(PocketItem item, string[] tags); - - /// - /// Removes the specified tags from an item. - /// /// The cancellation token. - /// The item ID. - /// The tags. /// /// - Task RemoveTags(CancellationToken cancellationToken, int itemID, string[] tags); - - /// - /// Removes the specified tags from an item. - /// - /// The cancellation token. - /// The item. - /// The tag. - /// - /// - Task RemoveTags(CancellationToken cancellationToken, PocketItem item, string[] tags); + Task RemoveTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken)); /// /// Removes a tag from an item. /// /// The item ID. - /// The tag. - /// - /// - Task RemoveTag(int itemID, string tag); - - /// - /// Removes a tag from an item. - /// - /// The item. - /// The tags. - /// - /// - Task RemoveTag(PocketItem item, string tag); - - /// - /// Removes a tag from an item. - /// - /// The cancellation token. - /// The item ID. /// The tag. + /// The cancellation token. /// /// - Task RemoveTag(CancellationToken cancellationToken, int itemID, string tag); + Task RemoveTag(int itemID, string tag, CancellationToken cancellationToken = default(CancellationToken)); /// /// Removes a tag from an item. /// - /// The cancellation token. /// The item. /// The tag. + /// The cancellation token. /// /// - Task RemoveTag(CancellationToken cancellationToken, PocketItem item, string tag); + Task RemoveTag(PocketItem item, string tag, CancellationToken cancellationToken = default(CancellationToken)); /// /// Clears all tags from an item. /// /// The item ID. + /// The cancellation token. /// /// - Task RemoveTags(int itemID); + Task RemoveTags(int itemID, CancellationToken cancellationToken = default(CancellationToken)); /// /// Clears all tags from an item. /// /// The item. - /// - /// - Task RemoveTags(PocketItem item); - - /// - /// Clears all tags from an item. - /// /// The cancellation token. - /// The item ID. /// /// - Task RemoveTags(CancellationToken cancellationToken, int itemID); - - /// - /// Clears all tags from an item. - /// - /// The cancellation token. - /// The item. - /// - /// - Task RemoveTags(CancellationToken cancellationToken, PocketItem item); + Task RemoveTags(PocketItem item, CancellationToken cancellationToken = default(CancellationToken)); /// /// Replaces all existing tags with the given tags in an item. /// /// The item ID. /// The tags. + /// The cancellation token. /// /// - Task ReplaceTags(int itemID, string[] tags); + Task ReplaceTags(int itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken)); /// /// Replaces all existing tags with the given new ones in an item. /// /// The item. /// The tags. - /// - /// - Task ReplaceTags(PocketItem item, string[] tags); - - /// - /// Replaces all existing tags with the given tags in an item. - /// /// The cancellation token. - /// The item ID. - /// The tags. /// /// - Task ReplaceTags(CancellationToken cancellationToken, int itemID, string[] tags); - - /// - /// Replaces all existing tags with the given new ones in an item. - /// - /// The cancellation token. - /// The item. - /// The tags. - /// - /// - Task ReplaceTags(CancellationToken cancellationToken, PocketItem item, string[] tags); + Task ReplaceTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken)); /// /// Renames a tag in an item. @@ -688,9 +398,10 @@ namespace PocketSharp /// The item ID. /// The old tag. /// The new tag name. + /// The cancellation token. /// /// - Task RenameTag(int itemID, string oldTag, string newTag); + Task RenameTag(int itemID, string oldTag, string newTag, CancellationToken cancellationToken = default(CancellationToken)); /// /// Renames a tag in an item. @@ -698,57 +409,20 @@ namespace PocketSharp /// The item. /// The old tag. /// The new tag name. - /// - /// - Task RenameTag(PocketItem item, string oldTag, string newTag); - - /// - /// Renames a tag in an item. - /// /// The cancellation token. - /// The item ID. - /// The old tag. - /// The new tag name. /// /// - Task RenameTag(CancellationToken cancellationToken, int itemID, string oldTag, string newTag); - - /// - /// Renames a tag in an item. - /// - /// The cancellation token. - /// The item. - /// The old tag. - /// The new tag name. - /// - /// - Task RenameTag(CancellationToken cancellationToken, PocketItem item, string oldTag, string newTag); + Task RenameTag(PocketItem item, string oldTag, string newTag, CancellationToken cancellationToken = default(CancellationToken)); #endregion #region statistics methods - /// - /// Statistics from the user account. - /// - /// - /// - Task GetUserStatistics(); - /// /// Statistics from the user account. /// /// The cancellation token. /// /// - Task GetUserStatistics(CancellationToken cancellationToken); - - /// - /// Returns API usage statistics. - /// If a request was made before, the data is returned synchronously from the cache. - /// Note: This method only works for authenticated users with a given AccessCode. - /// - /// - /// - Task GetUsageLimits(); + Task GetUserStatistics(CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns API usage statistics. @@ -758,7 +432,7 @@ namespace PocketSharp /// The cancellation token. /// /// - Task GetUsageLimits(CancellationToken cancellationToken); + Task GetUsageLimits(CancellationToken cancellationToken = default(CancellationToken)); #endregion } } \ No newline at end of file