cancellationToken for Get methods

This commit is contained in:
2013-11-08 01:24:58 +01:00
parent 50d896c670
commit feff91ffd8
3 changed files with 220 additions and 33 deletions
+1 -1
View File
@@ -198,7 +198,7 @@ namespace PocketSharp
Password = password
};
ResponseBase response = await Request<ResponseBase>("signup", parameters.Convert(), false);
ResponseBase response = await Request<ResponseBase>("signup", cancellationToken, parameters.Convert(), false);
return response.Status;
}
+129 -21
View File
@@ -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
/// </summary>
public partial class PocketClient
{
/// <summary>
/// Retrieves items from pocket
/// with the given filters
/// </summary>
/// <param name="state">The state.</param>
/// <param name="favorite">The favorite.</param>
/// <param name="tag">The tag.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="sort">The sort.</param>
/// <param name="search">The search.</param>
/// <param name="domain">The domain.</param>
/// <param name="since">The since.</param>
/// <param name="count">The count.</param>
/// <param name="offset">The offset.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
/// <summary>
/// Retrieves items from pocket
/// with the given filters
/// </summary>
/// <param name="state">The state.</param>
/// <param name="favorite">The favorite.</param>
/// <param name="tag">The tag.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="sort">The sort.</param>
/// <param name="search">The search.</param>
/// <param name="domain">The domain.</param>
/// <param name="since">The since.</param>
/// <param name="count">The count.</param>
/// <param name="offset">The offset.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> 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);
}
/// <summary>
/// Retrieves items from pocket
/// with the given filters
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="state">The state.</param>
/// <param name="favorite">The favorite.</param>
/// <param name="tag">The tag.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="sort">The sort.</param>
/// <param name="search">The search.</param>
/// <param name="domain">The domain.</param>
/// <param name="since">The since.</param>
/// <param name="count">The count.</param>
/// <param name="offset">The offset.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> 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<Retrieve>("get", parameters.Convert());
Retrieve response = await Request<Retrieve>("get", cancellationToken, parameters.Convert());
return response.Items;
}
@@ -69,8 +105,23 @@ namespace PocketSharp
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<PocketItem> Get(int itemID)
{
return await Get(CancellationToken.None, itemID);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="itemID">The item ID.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<PocketItem> Get(CancellationToken cancellationToken, int itemID)
{
List<PocketItem> items = await Get(
cancellationToken: cancellationToken,
state: State.all
);
@@ -85,10 +136,23 @@ namespace PocketSharp
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> Get(RetrieveFilter filter)
{
return await Get(CancellationToken.None, filter);
}
/// <summary>
/// Retrieves all items by a given filter
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="filter">The filter.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> 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<Retrieve>("get", parameters.Convert());
Retrieve response = await Request<Retrieve>("get", cancellationToken, parameters.Convert());
return response.Items;
}
@@ -128,8 +192,22 @@ namespace PocketSharp
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketTag>> GetTags()
{
return await GetTags(CancellationToken.None);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketTag>> GetTags(CancellationToken cancellationToken)
{
List<PocketItem> items = await Get(
cancellationToken: cancellationToken,
state: State.all
);
@@ -149,7 +227,23 @@ namespace PocketSharp
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> SearchByTag(string tag)
{
return await Get(tag: tag);
return await SearchByTag(CancellationToken.None, tag);
}
/// <summary>
/// Retrieves items by tag
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="tag">The tag.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> SearchByTag(CancellationToken cancellationToken, string tag)
{
return await Get(
cancellationToken: cancellationToken,
tag: tag
);
}
@@ -162,8 +256,22 @@ namespace PocketSharp
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> Search(string searchString, bool searchInUri = true)
{
List<PocketItem> items = await Get(RetrieveFilter.All);
return await Search(CancellationToken.None, searchString, searchInUri);
}
/// <summary>
/// Retrieves items which match the specified search string in title and URI
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="searchString">The search string.</param>
/// <param name="searchInUri">if set to <c>true</c> [search in URI].</param>
/// <returns></returns>
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
/// <exception cref="PocketException"></exception>
public async Task<List<PocketItem>> Search(CancellationToken cancellationToken, string searchString, bool searchInUri = true)
{
List<PocketItem> items = await Get(cancellationToken, RetrieveFilter.All);
return Search(items, searchString);
}
+90 -11
View File
@@ -181,17 +181,48 @@ namespace PocketSharp
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> 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
);
/// <summary>
/// Retrieves items from pocket
/// with the given filters
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="state">The state.</param>
/// <param name="favorite">The favorite.</param>
/// <param name="tag">The tag.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="sort">The sort.</param>
/// <param name="search">The search.</param>
/// <param name="domain">The domain.</param>
/// <param name="since">The since.</param>
/// <param name="count">The count.</param>
/// <param name="offset">The offset.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> 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
);
/// <summary>
/// Retrieves an item by a given ID
@@ -202,6 +233,16 @@ namespace PocketSharp
/// <exception cref="PocketException"></exception>
Task<PocketItem> Get(int itemID);
/// <summary>
/// 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.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="itemID">The item ID.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<PocketItem> Get(CancellationToken cancellationToken, int itemID);
/// <summary>
/// Retrieves all items by a given filter
/// </summary>
@@ -210,6 +251,15 @@ namespace PocketSharp
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> Get(RetrieveFilter filter);
/// <summary>
/// Retrieves all items by a given filter
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="filter">The filter.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> Get(CancellationToken cancellationToken, RetrieveFilter filter);
/// <summary>
/// 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
/// <exception cref="PocketException"></exception>
Task<List<PocketTag>> GetTags();
/// <summary>
/// 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.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<List<PocketTag>> GetTags(CancellationToken cancellationToken);
/// <summary>
/// Retrieves items by tag
/// </summary>
@@ -226,6 +285,15 @@ namespace PocketSharp
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> SearchByTag(string tag);
/// <summary>
/// Retrieves items by tag
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="tag">The tag.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> SearchByTag(CancellationToken cancellationToken, string tag);
/// <summary>
/// Retrieves items which match the specified search string in title and URI
/// </summary>
@@ -235,6 +303,17 @@ namespace PocketSharp
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> Search(string searchString, bool searchInUri = true);
/// <summary>
/// Retrieves items which match the specified search string in title and URI
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="searchString">The search string.</param>
/// <param name="searchInUri">if set to <c>true</c> [search in URI].</param>
/// <returns></returns>
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
/// <exception cref="PocketException"></exception>
Task<List<PocketItem>> Search(CancellationToken cancellationToken, string searchString, bool searchInUri = true);
/// <summary>
/// Finds the specified search string in title and URI for an available list of items
/// </summary>