add first version of Modify;
This commit is contained in:
@@ -19,18 +19,28 @@ namespace PocketSharp.Console
|
||||
consumerKey: "15396-f6f92101d72c8e270a6c9bb3"
|
||||
);
|
||||
|
||||
Uri redirect = client.Authenticate(new Uri("http://example.com"));
|
||||
//Uri redirect = client.Authenticate(new Uri("http://example.com"));
|
||||
|
||||
System.Console.WriteLine(redirect.ToString());
|
||||
//System.Console.WriteLine(redirect.ToString());
|
||||
|
||||
System.Console.WriteLine("---------------------------------");
|
||||
System.Console.WriteLine("Press Any key after you've authenticated the user via the given URI");
|
||||
//System.Console.WriteLine("---------------------------------");
|
||||
//System.Console.WriteLine("Press Any key after you've authenticated the user via the given URI");
|
||||
|
||||
System.Console.ReadKey();
|
||||
//System.Console.ReadKey();
|
||||
|
||||
//System.Console.WriteLine("---------------------------------");
|
||||
|
||||
//System.Console.WriteLine(client.GetAccessCode());
|
||||
|
||||
client.Search("css").ForEach(delegate(PocketItem item)
|
||||
{
|
||||
System.Console.WriteLine(item.ID + " ::: " + item.FullTitle);
|
||||
});
|
||||
|
||||
System.Console.WriteLine("---------------------------------");
|
||||
|
||||
System.Console.WriteLine(client.GetAccessCode());
|
||||
client.Archive(330361896);
|
||||
|
||||
|
||||
System.Console.ReadKey();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
public Uri Authenticate(Uri callbackUri)
|
||||
{
|
||||
RequestCode response = GetResource<RequestCode>("oauth/request", new List<Parameter>()
|
||||
RequestCode response = Get<RequestCode>("oauth/request", new List<Parameter>()
|
||||
{
|
||||
new Parameter() { Name = "redirect_uri", Value = callbackUri, Type = ParameterType.GetOrPost }
|
||||
});
|
||||
@@ -41,7 +41,7 @@ namespace PocketSharp
|
||||
throw new APIException("Authenticate the user first to receive a request_code");
|
||||
}
|
||||
|
||||
AccessCode response = GetResource<AccessCode>("oauth/authorize", new List<Parameter>()
|
||||
AccessCode response = Get<AccessCode>("oauth/authorize", new List<Parameter>()
|
||||
{
|
||||
new Parameter() { Name = "code", Value = RequestCode, Type = ParameterType.GetOrPost }
|
||||
});
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using PocketSharp.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
public partial class PocketClient
|
||||
{
|
||||
public bool Archive(int itemID)
|
||||
{
|
||||
List<ActionParameter> actions = new List<ActionParameter>()
|
||||
{
|
||||
new ActionParameter() { Action = "archive", ID = itemID }
|
||||
};
|
||||
|
||||
return Put<Modify>("send", actions).Status == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace PocketSharp
|
||||
public List<PocketItem> Retrieve(RetrieveParameters parameters)
|
||||
{
|
||||
ExpectAuthentification();
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
return Get<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace PocketSharp
|
||||
break;
|
||||
}
|
||||
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
return Get<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace PocketSharp
|
||||
{
|
||||
Tag = tag
|
||||
};
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
return Get<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace PocketSharp
|
||||
{
|
||||
Search = searchString
|
||||
};
|
||||
return GetResource<Retrieve>("get", parameters.Convert()).Items;
|
||||
return Get<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
class Modify : ResponseBase
|
||||
{
|
||||
[DataMember(Name = "action_results")]
|
||||
public bool[] ActionResults { get; set; }
|
||||
|
||||
[DataMember(Name = "status")]
|
||||
public int Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class ActionParameter : ParameterBase
|
||||
{
|
||||
public string Action { get; set; }
|
||||
|
||||
public int ID { get; set; }
|
||||
|
||||
public DateTime? Time { get; set; }
|
||||
|
||||
|
||||
public object Convert()
|
||||
{
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>
|
||||
{
|
||||
{ "item_id", ID.ToString() },
|
||||
{ "action", Action }
|
||||
};
|
||||
|
||||
if(Time != null)
|
||||
parameters.Add( "time", (int)((DateTime)Time - new DateTime(1970, 1, 1)).TotalSeconds );
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using RestSharp;
|
||||
using ServiceStack.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class ModifyParameters : ParameterBase
|
||||
{
|
||||
public List<ActionParameter> Actions { get; set; }
|
||||
|
||||
|
||||
public List<Parameter> Convert()
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
List<object> actions = new List<object>();
|
||||
|
||||
Actions.ForEach(delegate(ActionParameter action)
|
||||
{
|
||||
actions.Add(action.Convert());
|
||||
});
|
||||
|
||||
parameters.Add(CreateParam("actions", JsonSerializer.SerializeToString(actions)));
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace PocketSharp.Models
|
||||
{
|
||||
public abstract class ParameterBase
|
||||
{
|
||||
protected Parameter CreateParam(string name, object value, ParameterType type = ParameterType.GetOrPost)
|
||||
protected static Parameter CreateParam(string name, object value, ParameterType type = ParameterType.GetOrPost)
|
||||
{
|
||||
return new Parameter()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class PocketTag
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using RestSharp;
|
||||
using PocketSharp.Models;
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using ServiceStack.Text;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
@@ -131,14 +133,14 @@ namespace PocketSharp
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a typed resource
|
||||
/// Fetches/Updates a typed resource
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="method">Requested method (path after /v3/)</param>
|
||||
/// <param name="parameters">Additional POST parameters</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="APIException">No access token available. Use authentification first.</exception>
|
||||
protected T GetResource<T>(string method, List<Parameter> parameters = null) where T : class, new()
|
||||
protected T Get<T>(string method, List<Parameter> parameters = null) where T : class, new()
|
||||
{
|
||||
// every single Pocket API endpoint requires HTTP POST data
|
||||
var request = new RestRequest(method, Method.POST);
|
||||
@@ -163,6 +165,22 @@ namespace PocketSharp
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
//var x = (parameters.Convert());
|
||||
|
||||
return Get<T>(method, parameters.Convert());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validates the response.
|
||||
/// </summary>
|
||||
|
||||
@@ -48,13 +48,18 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="APIException.cs" />
|
||||
<Compile Include="Components\Authentification.cs" />
|
||||
<Compile Include="Components\Modify.cs" />
|
||||
<Compile Include="Components\Retrieve.cs" />
|
||||
<Compile Include="JsonDeserializer.cs" />
|
||||
<Compile Include="Models\Authentification\AccessCode.cs" />
|
||||
<Compile Include="Models\Authentification\RequestCode.cs" />
|
||||
<Compile Include="Models\Modify.cs" />
|
||||
<Compile Include="Models\Parameters\ActionParameter.cs" />
|
||||
<Compile Include="Models\Parameters\ModifyParameters.cs" />
|
||||
<Compile Include="Models\Parameters\ParameterBase.cs" />
|
||||
<Compile Include="Models\Parameters\RetrieveParameters.cs" />
|
||||
<Compile Include="Models\PocketItem.cs" />
|
||||
<Compile Include="Models\PocketTag.cs" />
|
||||
<Compile Include="Models\ResponseBase.cs" />
|
||||
<Compile Include="Models\Retrieve.cs" />
|
||||
<Compile Include="PocketClient.cs" />
|
||||
|
||||
Reference in New Issue
Block a user