update list of retrieve methods;
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using PocketSharp;
|
||||
using PocketSharp.Models.Authentification;
|
||||
using PocketSharp.Models.Parameters;
|
||||
using PocketSharp.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp.Console
|
||||
{
|
||||
@@ -15,13 +17,16 @@ namespace PocketSharp.Console
|
||||
// this apiKey is just for demonstration purposes
|
||||
// please create your own application and retrieve it's key. It's a 1-step process ;-)
|
||||
PocketClient client = new PocketClient(
|
||||
consumerKey: "15396-f6f92101d72c8e270a6c9bb3"
|
||||
consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
|
||||
accessCode: "a85134a7-243c-6656-ab82-97c901"
|
||||
);
|
||||
|
||||
client.Retrieve(new RetrieveParameters()
|
||||
List<PocketItem> x = client.Retrieve(RetrieveFilter.Archive);
|
||||
|
||||
foreach(PocketItem item in x)
|
||||
{
|
||||
|
||||
});
|
||||
System.Console.WriteLine(">>> " + item.Title);
|
||||
}
|
||||
|
||||
System.Console.ReadKey();
|
||||
}
|
||||
|
||||
@@ -10,24 +10,93 @@ namespace PocketSharp
|
||||
{
|
||||
public partial class PocketClient
|
||||
{
|
||||
public bool Retrieve(RetrieveParameters para)
|
||||
/// <summary>
|
||||
/// Retrieves all items from pocket
|
||||
/// </summary>
|
||||
/// <param name="parameters">parameters, which are mapped to the officials from http://getpocket.com/developer/docs/v3/retrieve </param>
|
||||
/// <returns></returns>
|
||||
public List<PocketItem> Retrieve(RetrieveParameters parameters)
|
||||
{
|
||||
//var parameters = new List<Parameter>()
|
||||
//{
|
||||
// new Parameter { Name = "favorite", Value = "1", Type = ParameterType.GetOrPost }
|
||||
//};
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
//var parameters = new RetrieveParameters()
|
||||
//{
|
||||
// Favorite = true,
|
||||
// State = StateEnum.all
|
||||
//};
|
||||
|
||||
var paramss = para.Convert();
|
||||
/// <summary>
|
||||
/// Retrieves all items with a filter from pocket
|
||||
/// </summary>
|
||||
/// <param name="filter">The filter.</param>
|
||||
/// <returns></returns>
|
||||
public List<PocketItem> Retrieve(RetrieveFilter filter = RetrieveFilter.All)
|
||||
{
|
||||
RetrieveParameters parameters = new RetrieveParameters();
|
||||
|
||||
Retrieve result = GetResource<Retrieve>("get", para.Convert());
|
||||
switch(filter)
|
||||
{
|
||||
case RetrieveFilter.Article:
|
||||
parameters.ContentType = ContentTypeEnum.article;
|
||||
break;
|
||||
case RetrieveFilter.Image:
|
||||
parameters.ContentType = ContentTypeEnum.image;
|
||||
break;
|
||||
case RetrieveFilter.Video:
|
||||
parameters.ContentType = ContentTypeEnum.video;
|
||||
break;
|
||||
case RetrieveFilter.Favorite:
|
||||
parameters.Favorite = true;
|
||||
break;
|
||||
case RetrieveFilter.Unread:
|
||||
parameters.State = StateEnum.unread;
|
||||
break;
|
||||
case RetrieveFilter.Archive:
|
||||
parameters.State = StateEnum.archive;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves items by tag from pocket
|
||||
/// </summary>
|
||||
/// <param name="tag">The tag.</param>
|
||||
/// <returns></returns>
|
||||
public List<PocketItem> SearchByTag(string tag)
|
||||
{
|
||||
RetrieveParameters parameters = new RetrieveParameters()
|
||||
{
|
||||
Tag = tag
|
||||
};
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves items from pocket which match the specified search string in title or content
|
||||
/// </summary>
|
||||
/// <param name="tag">The tag.</param>
|
||||
/// <returns></returns>
|
||||
public List<PocketItem> Search(string searchString)
|
||||
{
|
||||
RetrieveParameters parameters = new RetrieveParameters()
|
||||
{
|
||||
Search = searchString
|
||||
};
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter for simple retrieve requests
|
||||
/// </summary>
|
||||
public enum RetrieveFilter
|
||||
{
|
||||
All,
|
||||
Unread,
|
||||
Archive,
|
||||
Favorite,
|
||||
Article,
|
||||
Video,
|
||||
Image
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models.Parameters
|
||||
@@ -17,19 +18,33 @@ namespace PocketSharp.Models.Parameters
|
||||
|
||||
public SortEnum? Sort { get; set; }
|
||||
|
||||
public DetailTypeEnum? DetailType { get; set; }
|
||||
|
||||
public string Search { get; set; }
|
||||
|
||||
public string Domain { get; set; }
|
||||
|
||||
|
||||
public List<Parameter> Convert()
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
|
||||
if(State != null)
|
||||
{
|
||||
if (State != null)
|
||||
parameters.Add(CreateParam("state", State.ToString()));
|
||||
}
|
||||
if(Favorite != null)
|
||||
{
|
||||
if (Favorite != null)
|
||||
parameters.Add(CreateParam("favorite", (bool)Favorite ? "1" : "0"));
|
||||
}
|
||||
if (Tag != null)
|
||||
parameters.Add(CreateParam("tag", Tag));
|
||||
if (ContentType != null)
|
||||
parameters.Add(CreateParam("contentType", ContentType.ToString()));
|
||||
if (Sort != null)
|
||||
parameters.Add(CreateParam("sort", Sort.ToString()));
|
||||
if (DetailType != null)
|
||||
parameters.Add(CreateParam("detailType", DetailType.ToString()));
|
||||
if (Search != null)
|
||||
parameters.Add(CreateParam("search", Search.ToString()));
|
||||
if (Domain != null)
|
||||
parameters.Add(CreateParam("domain", Domain.ToString()));
|
||||
|
||||
return parameters;
|
||||
}
|
||||
@@ -57,4 +72,10 @@ namespace PocketSharp.Models.Parameters
|
||||
video,
|
||||
image
|
||||
}
|
||||
|
||||
public enum DetailTypeEnum
|
||||
{
|
||||
simple,
|
||||
complete
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Runtime.Serialization;
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
class PocketItem
|
||||
public class PocketItem
|
||||
{
|
||||
[DataMember(Name = "item_id")]
|
||||
public int ID { get; set; }
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace PocketSharp.Models
|
||||
class Retrieve : ResponseBase
|
||||
{
|
||||
[DataMember(Name = "complete")]
|
||||
public int Complete;
|
||||
public int Complete { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int Since { get; set; }
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace PocketSharp
|
||||
/// <summary>
|
||||
/// base URL for the API
|
||||
/// </summary>
|
||||
public Uri BaseUrl { get; set; }
|
||||
protected Uri BaseUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Accessor for the Pocket API key
|
||||
/// see: http://getpocket.com/developer
|
||||
/// </summary>
|
||||
public string ConsumerKey { get; set; }
|
||||
protected string ConsumerKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns all associated data from the last request
|
||||
@@ -42,7 +42,7 @@ namespace PocketSharp
|
||||
/// <summary>
|
||||
/// Code retrieved on authentification-success
|
||||
/// </summary>
|
||||
public string AccessCode { get; set; }
|
||||
protected string AccessCode { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -89,6 +89,21 @@ namespace PocketSharp
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration from the PocketClient.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, object> GetConfiguration()
|
||||
{
|
||||
return new Dictionary<string, object>()
|
||||
{
|
||||
{ "baseUrl", BaseUrl },
|
||||
{ "consumerKey", ConsumerKey },
|
||||
{ "accessCode", AccessCode }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Makes a HTTP REST request to the API
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user