add Add method to add new PocketItem;
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using PocketSharp.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// PocketClient
|
||||
/// </summary>
|
||||
public partial class PocketClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a new item to pocket
|
||||
/// </summary>
|
||||
/// <param name="uri">The URL of the item you want to save</param>
|
||||
/// <param name="tags">A comma-separated list of tags to apply to the item</param>
|
||||
/// <param name="title">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.</param>
|
||||
/// <param name="tweetID">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.</param>
|
||||
/// <returns></returns>
|
||||
public PocketItem Add(Uri uri, string[] tags = null, string title = null, string tweetID = null)
|
||||
{
|
||||
ExpectAuthentification();
|
||||
AddParameters parameters = new AddParameters()
|
||||
{
|
||||
Uri = uri,
|
||||
Tags = tags,
|
||||
Title = title,
|
||||
TweetID = tweetID
|
||||
};
|
||||
return Get<Add>("add", parameters.Convert()).Item;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new item to pocket
|
||||
/// </summary>
|
||||
/// <param name="uri">The URL of the item you want to save</param>
|
||||
/// <returns></returns>
|
||||
public PocketItem Add(Uri uri)
|
||||
{
|
||||
return Add(uri, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
public bool Archive(int itemID)
|
||||
{
|
||||
return PutAction(itemID, "archive");
|
||||
return PutSendAction(itemID, "archive");
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
public bool Unarchive(int itemID)
|
||||
{
|
||||
return PutAction(itemID, "readd");
|
||||
return PutSendAction(itemID, "readd");
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
public bool Favorite(int itemID)
|
||||
{
|
||||
return PutAction(itemID, "favorite");
|
||||
return PutSendAction(itemID, "favorite");
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
public bool Unfavorite(int itemID)
|
||||
{
|
||||
return PutAction(itemID, "unfavorite");
|
||||
return PutSendAction(itemID, "unfavorite");
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
public bool Delete(int itemID)
|
||||
{
|
||||
return PutAction(itemID, "delete");
|
||||
return PutSendAction(itemID, "delete");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class AddParameters : ParameterBase
|
||||
{
|
||||
public Uri Uri { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string[] Tags { get; set; }
|
||||
|
||||
public string TweetID { get; set; }
|
||||
|
||||
public List<Parameter> Convert()
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
|
||||
if (Uri != null)
|
||||
parameters.Add(CreateParam("url", Uri.ToString()));
|
||||
if (Title != null)
|
||||
parameters.Add(CreateParam("title", Title));
|
||||
if (Tags != null)
|
||||
parameters.Add(CreateParam("tags", String.Join(",", Tags)));
|
||||
if (TweetID != null)
|
||||
parameters.Add(CreateParam("tweet_id", TweetID));
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
class Add : ResponseBase
|
||||
{
|
||||
[DataMember]
|
||||
public PocketItem Item { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,5 @@ namespace PocketSharp.Models
|
||||
{
|
||||
[DataMember(Name = "action_results")]
|
||||
public bool[] ActionResults { get; set; }
|
||||
|
||||
[DataMember(Name = "status")]
|
||||
public int Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
class ResponseBase
|
||||
{
|
||||
[DataMember(Name = "status")]
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
+11
-38
@@ -183,54 +183,27 @@ namespace PocketSharp
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Puts/Updates a typed resource
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="method">Requested method (path after /v3/)</param>
|
||||
/// <param name="actions">Additional action parameters</param>
|
||||
/// <returns></returns>
|
||||
protected T Put<T>(string method, List<ActionParameter> actions) where T : class, new()
|
||||
{
|
||||
// put requests only with authentification
|
||||
ExpectAuthentification();
|
||||
|
||||
ModifyParameters parameters = new ModifyParameters()
|
||||
{
|
||||
Actions = actions
|
||||
};
|
||||
return Get<T>(method, parameters.Convert());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Puts/Updates a typed resource
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="method">Requested method (path after /v3/)</param>
|
||||
/// <param name="action">action parameter</param>
|
||||
/// <returns></returns>
|
||||
protected T Put<T>(string method, ActionParameter action) where T : class, new()
|
||||
{
|
||||
return Put<T>(method, new List<ActionParameter>() { action });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Puts an action
|
||||
/// </summary>
|
||||
/// <param name="itemID">The item ID.</param>
|
||||
/// <param name="action">The action.</param>
|
||||
/// <returns></returns>
|
||||
protected bool PutAction(int itemID, string action)
|
||||
protected bool PutSendAction(int itemID, string action)
|
||||
{
|
||||
ActionParameter actionParam = new ActionParameter()
|
||||
ModifyParameters parameters = new ModifyParameters()
|
||||
{
|
||||
Action = action,
|
||||
ID = itemID
|
||||
Actions = new List<ActionParameter>()
|
||||
{
|
||||
new ActionParameter()
|
||||
{
|
||||
Action = action,
|
||||
ID = itemID
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return Put<Modify>("send", actionParam).Status == 1;
|
||||
return Get<Modify>("send", parameters.Convert()).Status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="APIException.cs" />
|
||||
<Compile Include="Components\Add.cs" />
|
||||
<Compile Include="Components\Authentification.cs" />
|
||||
<Compile Include="Components\Modify.cs" />
|
||||
<Compile Include="Components\ModifyTags.cs" />
|
||||
@@ -57,9 +58,11 @@
|
||||
<Compile Include="JsonDeserializer.cs" />
|
||||
<Compile Include="Models\Authentification\AccessCode.cs" />
|
||||
<Compile Include="Models\Authentification\RequestCode.cs" />
|
||||
<Compile Include="Models\Parameters\AddParameters.cs" />
|
||||
<Compile Include="Models\PocketAuthor.cs" />
|
||||
<Compile Include="Models\PocketImage.cs" />
|
||||
<Compile Include="Models\PocketVideo.cs" />
|
||||
<Compile Include="Models\Response\Add.cs" />
|
||||
<Compile Include="Models\Response\Modify.cs" />
|
||||
<Compile Include="Models\Parameters\ActionParameter.cs" />
|
||||
<Compile Include="Models\Parameters\ModifyParameters.cs" />
|
||||
|
||||
Reference in New Issue
Block a user