6 Commits

Author SHA1 Message Date
swcs 4e40aaa0dc update readme 2013-09-18 21:19:38 +02:00
swcs 242428f94c bump version 2013-09-18 21:17:56 +02:00
swcs d009afd033 correct serialization of DateTime and Boolean values 2013-09-18 21:14:07 +02:00
swcs de1e4efc70 update retrieve tests 2013-09-18 21:01:51 +02:00
swcs e198ecdd6b update docs 2013-09-17 23:28:28 +02:00
swcs fb92cb19c8 update retrieve methods - work with named parameters 2013-09-17 23:08:15 +02:00
7 changed files with 139 additions and 89 deletions
+29 -11
View File
@@ -20,20 +20,38 @@ namespace PocketSharp.Tests
}
//[Fact]
//public async Task ItemContainsUri()
//{
// List<PocketItem> items = await client.Retrieve(new RetrieveParameters()
// {
// Count = 1
// });
[Fact]
public async Task AreFilteredItemsRetrieved()
{
List<PocketItem> items = await client.RetrieveByFilter(RetrieveFilter.Favorite);
// Assert.True(items.Count == 1);
Assert.True(items.Count > 0);
}
// PocketItem item = items[0];
// Assert.True(item.Uri.ToString().StartsWith("http"));
//}
[Fact]
public async Task RetrieveWithMultipleFilters()
{
List<PocketItem> items = await client.Retrieve(
state: State.unread,
tag: "pocket",
sort: Sort.title,
since: new DateTime(2010, 12, 10),
count: 2
);
Assert.InRange<int>(items.Count, 0, 2);
}
[Fact]
public async Task ItemContainsUri()
{
List<PocketItem> items = await client.Retrieve(count: 1);
Assert.True(items.Count == 1);
Assert.True(items[0].Uri.ToString().StartsWith("http"));
}
[Fact]
+31 -35
View File
@@ -32,6 +32,8 @@
</h1>
<p class="app-description">
PocketSharp is a C#.NET class library, that integrates the Pocket API v3
<br><br>
Current version: <b>1.2.0</b>
</p>
<div class="app-nuget">
<code>Install-Package PocketSharp</code>
@@ -122,6 +124,8 @@ using PocketSharp.Models;</code></pre>
<h2>Release History</h2>
<ul>
<li>2013-09-17 v1.2.0 simplified retrieve methods</li>
<li>2013-09-17 v1.1.0 fix modification requests</li>
<li>2013-09-15 v1.0.0 convert to PCL &amp; implement async</li>
<li>2013-08-16 v0.3.2 tag modification fixed and full retrieval of items for Retrieve method</li>
<li>2013-07-07 v0.3.1 authentication fixes</li>
@@ -186,42 +190,34 @@ Note that <code>GetAccessCode</code> can only be called with an existing <em>req
<div data-part="retrieve">
<h2>Retrieve</h2>
<p>Get list of all items:</p>
<pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.Retrieve();
// equivalent to: await _client.Retrieve(RetrieveFilter.All)</code></pre>
<p>Find items by a tag:</p>
<pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.SearchByTag(&quot;tutorial&quot;);</code></pre>
<p>Find items by a search string:</p>
<pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.Search(&quot;css&quot;);</code></pre>
<p>Find items by a filter:</p>
<pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.Retrieve(RetrieveFilter.Favorite); // only favorites</code></pre>
<p>The RetrieveFilter Enum is specified as follows:</p>
<pre class="language-clike"><code>enum RetrieveFilter { All, Unread, Archive, Favorite, Article, Video, Image }</code></pre>
<h4>Custom Parameters</h4>
<p>You can create a completely custom parameter list for retrieval with the POCO <code>RetrieveParameters</code>:</p>
<pre class="language-clike"><code>
var parameters = new RetrieveParameters()
{
Count = 50,
Offset = 100,
Sort = SortEnum.oldest
...
};
List&lt;pocketitem&gt; items = await _client.Retrieve(parameters);
</code></pre>
<p>Get list of all items:</p>
<p><pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.Retrieve();
// equivalent to: await _client.RetrieveByFilter(RetrieveFilter.All)</code></pre></p>
<p>Get a list with specific parameters (explanation in the <a href="http://getpocket.com/developer/docs/v3/retrieve">Pocket Docs</a>):</p>
<p><pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.Retrieve(
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
);</code></pre></p>
<p>It's best to use parameters as <em>named parameters</em>, to avoid typing <code>null</code> values:</p>
<p><pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.Retrieve(count: 10, offset: 20, sort: Sort.oldest);</code></pre></p>
<p>Find items by a tag:</p>
<p><pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.SearchByTag(&quot;tutorial&quot;);</code></pre></p>
<p>Find items by a search string:</p>
<p><pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.Search(&quot;css&quot;);</code></pre></p>
<p>Get a filtered list:</p>
<p><pre class="language-clike"><code>List&lt;PocketItem&gt; items = await _client.RetrieveByFilter(RetrieveFilter.Favorite);
// returns favorites only</code></pre></p>
<p>The RetrieveFilter Enum is specified as follows:</p>
<p><pre class="language-clike"><code>enum RetrieveFilter { All, Unread, Archive, Favorite, Article, Video, Image }</code></pre></p>
</div>
<div data-part="add">
+31 -20
View File
@@ -1,4 +1,5 @@
using PocketSharp.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -14,8 +15,34 @@ namespace PocketSharp
/// </summary>
/// <param name="parameters">parameters, which are mapped to the officials from http://getpocket.com/developer/docs/v3/retrieve </param>
/// <returns></returns>
internal async Task<List<PocketItem>> Retrieve(RetrieveParameters parameters)
public async Task<List<PocketItem>> Retrieve(
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()
{
State = state,
Favorite = favorite,
Tag = tag,
ContentType = contentType,
Sort = sort,
DetailType = DetailType.complete,
Search = search,
Domain = domain,
Since = since,
Count = count,
Offset = offset
};
Retrieve response = await Request<Retrieve>("get", parameters.Convert());
return response.Items;
@@ -27,7 +54,7 @@ namespace PocketSharp
/// </summary>
/// <param name="filter">The filter.</param>
/// <returns></returns>
public async Task<List<PocketItem>> Retrieve(RetrieveFilter filter = RetrieveFilter.All)
public async Task<List<PocketItem>> RetrieveByFilter(RetrieveFilter filter = RetrieveFilter.All)
{
RetrieveParameters parameters = new RetrieveParameters();
@@ -68,15 +95,7 @@ namespace PocketSharp
/// <returns></returns>
public async Task<List<PocketItem>> SearchByTag(string tag)
{
RetrieveParameters parameters = new RetrieveParameters()
{
Tag = tag,
DetailType = DetailType.complete
};
Retrieve response = await Request<Retrieve>("get", parameters.Convert());
return response.Items;
return await Retrieve(tag: tag);
}
@@ -87,15 +106,7 @@ namespace PocketSharp
/// <returns></returns>
public async Task<List<PocketItem>> Search(string searchString)
{
RetrieveParameters parameters = new RetrieveParameters()
{
Search = searchString,
DetailType = DetailType.complete
};
Retrieve response = await Request<Retrieve>("get", parameters.Convert());
return response.Items;
return await Retrieve(search: searchString);
}
}
@@ -35,16 +35,30 @@ namespace PocketSharp.Models
string name = attribute.Name ?? propertyInfo.Name.ToLower();
object value = propertyInfo.GetValue(this, null);
// invalid parameter
if (value == null)
{
continue;
}
// convert array to comma-seperated list
if (value is IEnumerable && value.GetType().GetElementType() == typeof(string))
{
value = string.Join(",", ((IEnumerable)value).Cast<object>().Select(x => x.ToString()).ToArray());
}
// convert booleans
if (value is bool)
{
value = System.Convert.ToBoolean(value) ? "1" : "0";
}
// convert DateTime to UNIX timestamp
if (value is DateTime)
{
value = (int)((DateTime)value - new DateTime(1970, 1, 1)).TotalSeconds;
}
parameterDict.Add(name, value.ToString());
}
+1 -1
View File
@@ -10,7 +10,7 @@
<projectUrl>http://pocketsharp.frontendplay.com</projectUrl>
<iconUrl>http://pocketsharp.frontendplay.com/Assets/Images/pocketsharp.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<description>PocketSharp is a .NET class library, that integrates the Pocket API v3</description>
<language>en-US</language>
<releaseNotes>
<![CDATA[
+2 -2
View File
@@ -25,5 +25,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyVersion("1.2.1")]
[assembly: AssemblyFileVersion("1.2.1")]
+31 -20
View File
@@ -19,7 +19,7 @@ PocketSharp is a **Portable Class Library** (since 1.0.0), therefore it's compat
- **Windows Phone** >= 7.5
- **Windows Store**
You can find examples for Silverlight 5, WP8 and WPF in the `PocketSharp.Examples` folder.
You can find examples for Silverlight 5, WP8 and WPF in the `PocketSharp.Examples` ([@github](https://github.com/ceee/PocketSharp/tree/master/PocketSharp.Examples)) folder.
## Async Support
@@ -142,7 +142,30 @@ Get list of all items:
```csharp
List<PocketItem> items = await _client.Retrieve();
// equivalent to: await _client.Retrieve(RetrieveFilter.All)
// equivalent to: await _client.RetrieveByFilter(RetrieveFilter.All)
```
Get a list with specific parameters (explanation in the [Pocket Docs](http://getpocket.com/developer/docs/v3/retrieve)):
```csharp
List<PocketItem> items = await _client.Retrieve(
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
);
```
It's best to use parameters as _named parameters_, to avoid typing `null` values:
```csharp
List<PocketItem> items = await _client.Retrieve(count: 10, offset: 20, sort: Sort.oldest);
```
Find items by a tag:
@@ -157,10 +180,11 @@ Find items by a search string:
List<PocketItem> items = await _client.Search("css");
```
Find items by a filter:
Get a filtered list:
```csharp
List<PocketItem> items = await _client.Retrieve(RetrieveFilter.Favorite); // only favorites
List<PocketItem> items = await _client.RetrieveByFilter(RetrieveFilter.Favorite);
// returns favorites only
```
The RetrieveFilter Enum is specified as follows:
@@ -169,22 +193,6 @@ The RetrieveFilter Enum is specified as follows:
enum RetrieveFilter { All, Unread, Archive, Favorite, Article, Video, Image }
```
#### Custom Parameters
You can create a completely custom parameter list for retrieval with the POCO `RetrieveParameters`:
```csharp
var parameters = new RetrieveParameters()
{
Count = 50,
Offset = 100,
Sort = Sort.oldest
...
};
List<PocketItem> items = await _client.Retrieve(parameters);
```
## Add
Adds a new item to your pocket list.
@@ -257,6 +265,9 @@ Renames a tag for the specified item:
## Release History
- 2013-09-18 v1.2.1 correct parameter conversion for DateTime and Boolean
- 2013-09-17 v1.2.0 simplified retrieve methods
- 2013-09-17 v1.1.0 fix modification requests
- 2013-09-15 v1.0.0 convert to PCL & implement async
- 2013-08-16 v0.3.2 tag modification fixed and full retrieval of items for Retrieve method
- 2013-07-07 v0.3.1 authentication fixes