diff --git a/PocketSharp/Components/ModifyTags.cs b/PocketSharp/Components/ModifyTags.cs
index 0429e21..4e81995 100644
--- a/PocketSharp/Components/ModifyTags.cs
+++ b/PocketSharp/Components/ModifyTags.cs
@@ -1,4 +1,5 @@
using PocketSharp.Models;
+using System.Threading;
using System.Threading.Tasks;
namespace PocketSharp
@@ -17,7 +18,7 @@ namespace PocketSharp
///
public async Task AddTags(int itemID, string[] tags)
{
- return await SendTags(itemID, "tags_add", tags);
+ return await AddTags(CancellationToken.None, itemID, tags);
}
@@ -30,7 +31,35 @@ namespace PocketSharp
///
public async Task AddTags(PocketItem item, string[] tags)
{
- return await AddTags(item.ID, 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)
+ {
+ return await SendTags(cancellationToken, itemID, "tags_add", tags);
+ }
+
+
+ ///
+ /// Adds the specified tags to an item.
+ ///
+ /// The cancellation token.
+ /// The item.
+ /// The tags.
+ ///
+ ///
+ public async Task AddTags(CancellationToken cancellationToken, PocketItem item, string[] tags)
+ {
+ return await AddTags(cancellationToken, item.ID, tags);
}
@@ -43,7 +72,7 @@ namespace PocketSharp
///
public async Task RemoveTags(int itemID, string[] tags)
{
- return await SendTags(itemID, "tags_remove", tags);
+ return await RemoveTags(CancellationToken.None, itemID, tags);
}
@@ -56,7 +85,35 @@ namespace PocketSharp
///
public async Task RemoveTags(PocketItem item, string[] tags)
{
- return await RemoveTags(item.ID, 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)
+ {
+ return await SendTags(cancellationToken, itemID, "tags_remove", tags);
+ }
+
+
+ ///
+ /// 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);
}
@@ -69,7 +126,7 @@ namespace PocketSharp
///
public async Task RemoveTag(int itemID, string tag)
{
- return await SendTags(itemID, "tags_remove", new string[] { tag });
+ return await RemoveTag(CancellationToken.None, itemID, tag);
}
@@ -82,7 +139,35 @@ namespace PocketSharp
///
public async Task RemoveTag(PocketItem item, string tag)
{
- return await RemoveTag(item.ID, tag);
+ return await RemoveTag(CancellationToken.None, item.ID, tag);
+ }
+
+
+ ///
+ /// Removes a tag from an item.
+ ///
+ /// The cancellation token.
+ /// The item ID.
+ /// The tag.
+ ///
+ ///
+ public async Task RemoveTag(CancellationToken cancellationToken, int itemID, string tag)
+ {
+ return await SendTags(cancellationToken, itemID, "tags_remove", new string[] { tag });
+ }
+
+
+ ///
+ /// 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);
}
@@ -94,7 +179,7 @@ namespace PocketSharp
///
public async Task RemoveTags(int itemID)
{
- return await SendDefault(itemID, "tags_clear");
+ return await RemoveTags(CancellationToken.None, itemID);
}
@@ -106,7 +191,33 @@ namespace PocketSharp
///
public async Task RemoveTags(PocketItem item)
{
- return await RemoveTags(item.ID);
+ 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)
+ {
+ return await SendDefault(cancellationToken, itemID, "tags_clear");
+ }
+
+
+ ///
+ /// Clears all tags from an item.
+ ///
+ /// The cancellation token.
+ /// The item.
+ ///
+ ///
+ public async Task RemoveTags(CancellationToken cancellationToken, PocketItem item)
+ {
+ return await RemoveTags(cancellationToken, item.ID);
}
@@ -119,7 +230,7 @@ namespace PocketSharp
///
public async Task ReplaceTags(int itemID, string[] tags)
{
- return await SendTags(itemID, "tags_replace", tags);
+ return await ReplaceTags(CancellationToken.None, itemID, tags);
}
@@ -132,7 +243,35 @@ namespace PocketSharp
///
public async Task ReplaceTags(PocketItem item, string[] tags)
{
- return await ReplaceTags(item.ID, 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)
+ {
+ return await SendTags(cancellationToken, itemID, "tags_replace", tags);
+ }
+
+
+ ///
+ /// 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);
}
@@ -146,13 +285,7 @@ namespace PocketSharp
///
public async Task RenameTag(int itemID, string oldTag, string newTag)
{
- return await Send(new ActionParameter()
- {
- Action = "tag_rename",
- ID = itemID,
- OldTag = oldTag,
- NewTag = newTag
- });
+ return await RenameTag(CancellationToken.None, itemID, oldTag, newTag);
}
@@ -166,25 +299,62 @@ namespace PocketSharp
///
public async Task RenameTag(PocketItem item, string oldTag, string newTag)
{
- return await RenameTag(item.ID, oldTag, newTag);
+ return await RenameTag(CancellationToken.None, item.ID, oldTag, newTag);
+ }
+
+
+ ///
+ /// Renames a tag in an item.
+ ///
+ /// The cancellation token.
+ /// The item ID.
+ /// The old tag.
+ /// The new tag name.
+ ///
+ ///
+ public async Task RenameTag(CancellationToken cancellationToken, int itemID, string oldTag, string newTag)
+ {
+ return await Send(new ActionParameter()
+ {
+ Action = "tag_rename",
+ ID = itemID,
+ OldTag = oldTag,
+ NewTag = newTag
+ }, cancellationToken);
+ }
+
+
+ ///
+ /// Renames a tag in an item.
+ ///
+ /// The cancellation token.
+ /// The item.
+ /// The old tag.
+ /// The new tag name.
+ ///
+ ///
+ public async Task RenameTag(CancellationToken cancellationToken, PocketItem item, string oldTag, string newTag)
+ {
+ return await RenameTag(cancellationToken, item.ID, oldTag, newTag);
}
///
/// Puts the send action for tags.
///
+ /// The cancellation token.
/// The item ID.
/// The action.
/// The tags.
///
- protected async Task SendTags(int itemID, string action, string[] tags)
+ protected async Task SendTags(CancellationToken cancellationToken, int itemID, string action, string[] tags)
{
return await Send(new ActionParameter()
{
Action = action,
ID = itemID,
Tags = tags
- });
+ }, cancellationToken);
}
}
}
diff --git a/PocketSharp/Components/Statistics.cs b/PocketSharp/Components/Statistics.cs
index 10c16cc..40d776a 100644
--- a/PocketSharp/Components/Statistics.cs
+++ b/PocketSharp/Components/Statistics.cs
@@ -1,5 +1,6 @@
using PocketSharp.Models;
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace PocketSharp
@@ -16,19 +17,19 @@ namespace PocketSharp
///
public async Task GetUserStatistics()
{
- return await Request("stats");
+ return await GetUserStatistics(CancellationToken.None);
}
///
/// Statistics from the user account.
///
+ /// The cancellation token.
///
///
- [Obsolete("Please use GetUserStatistics instead")]
- public async Task Statistics()
+ public async Task GetUserStatistics(CancellationToken cancellationToken)
{
- return await GetUserStatistics();
+ return await Request("stats", cancellationToken);
}
@@ -40,13 +41,30 @@ namespace PocketSharp
///
///
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.
+ /// Note: This method only works for authenticated users with a given AccessCode.
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ public async Task GetUsageLimits(CancellationToken cancellationToken)
{
string rateLimitForConsumerKey = TryGetHeaderValue(lastHeaders, "X-Limit-Key-Limit");
if (rateLimitForConsumerKey == null)
{
// this is the fastest way to do a non-failing request to receive the correct headers
- await Get(count: 1);
+ await Get(
+ cancellationToken: cancellationToken,
+ count: 1
+ );
}
return new PocketLimits()
diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs
index d4f5150..5f47b3f 100644
--- a/PocketSharp/IPocketClient.cs
+++ b/PocketSharp/IPocketClient.cs
@@ -514,6 +514,26 @@ namespace PocketSharp
///
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);
+
///
/// Removes the specified tags from an item.
///
@@ -532,6 +552,26 @@ namespace PocketSharp
///
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);
+
///
/// Removes a tag from an item.
///
@@ -550,6 +590,26 @@ namespace PocketSharp
///
Task RemoveTag(PocketItem item, string tag);
+ ///
+ /// Removes a tag from an item.
+ ///
+ /// The cancellation token.
+ /// The item ID.
+ /// The tag.
+ ///
+ ///
+ Task RemoveTag(CancellationToken cancellationToken, int itemID, string tag);
+
+ ///
+ /// Removes a tag from an item.
+ ///
+ /// The cancellation token.
+ /// The item.
+ /// The tag.
+ ///
+ ///
+ Task RemoveTag(CancellationToken cancellationToken, PocketItem item, string tag);
+
///
/// Clears all tags from an item.
///
@@ -566,6 +626,24 @@ namespace PocketSharp
///
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);
+
///
/// Replaces all existing tags with the given tags in an item.
///
@@ -584,6 +662,26 @@ namespace PocketSharp
///
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);
+
///
/// Renames a tag in an item.
///
@@ -603,6 +701,28 @@ namespace PocketSharp
///
///
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);
#endregion
#region statistics methods
@@ -616,10 +736,10 @@ namespace PocketSharp
///
/// Statistics from the user account.
///
+ /// The cancellation token.
///
///
- [Obsolete("Please use GetUserStatistics instead")]
- Task Statistics();
+ Task GetUserStatistics(CancellationToken cancellationToken);
///
/// Returns API usage statistics.
@@ -629,6 +749,16 @@ namespace PocketSharp
///
///
Task GetUsageLimits();
+
+ ///
+ /// 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.
+ ///
+ /// The cancellation token.
+ ///
+ ///
+ Task GetUsageLimits(CancellationToken cancellationToken);
#endregion
}
}
\ No newline at end of file