cleanup parameters;
This commit is contained in:
@@ -4,10 +4,13 @@ using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models.Authentification
|
||||
{
|
||||
[DataContract]
|
||||
class RequestCode
|
||||
{
|
||||
[DataMember]
|
||||
public string Code { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string State { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class ActionParameter : ParameterBase
|
||||
public class ActionParameter
|
||||
{
|
||||
public string Action { get; set; }
|
||||
|
||||
@@ -31,15 +31,12 @@ namespace PocketSharp.Models
|
||||
{ "action", Action }
|
||||
};
|
||||
|
||||
if(Time != null)
|
||||
parameters.Add("time", (int)((DateTime)Time - new DateTime(1970, 1, 1)).TotalSeconds);
|
||||
|
||||
if (Time != null)
|
||||
parameters.Add("time", Utilities.GetUnixTimestamp(Time));
|
||||
if (Tags != null)
|
||||
parameters.Add("tags", String.Join(",", Tags));
|
||||
|
||||
if (OldTag != null)
|
||||
parameters.Add("old_tag", OldTag);
|
||||
|
||||
if (NewTag != null)
|
||||
parameters.Add("new_tag", NewTag);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class AddParameters : ParameterBase
|
||||
public class AddParameters
|
||||
{
|
||||
public Uri Uri { get; set; }
|
||||
|
||||
@@ -18,18 +18,13 @@ namespace PocketSharp.Models
|
||||
|
||||
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;
|
||||
return new List<Parameter>()
|
||||
{
|
||||
Utilities.CreateParam("url", Uri.ToString() ),
|
||||
Utilities.CreateParam("title", Title),
|
||||
Utilities.CreateParam("tags", String.Join(",", Tags)),
|
||||
Utilities.CreateParam("tweet_id", TweetID)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,21 @@ using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class ModifyParameters : ParameterBase
|
||||
public class ModifyParameters
|
||||
{
|
||||
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.ForEach(action => actions.Add(action.Convert()));
|
||||
|
||||
return new List<Parameter>()
|
||||
{
|
||||
actions.Add(action.Convert());
|
||||
});
|
||||
|
||||
parameters.Add(CreateParam("actions", JsonSerializer.SerializeToString(actions)));
|
||||
|
||||
return parameters;
|
||||
Utilities.CreateParam("actions", JsonSerializer.SerializeToString(actions))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
public class RetrieveParameters : ParameterBase
|
||||
public class RetrieveParameters
|
||||
{
|
||||
public StateEnum? State { get; set; }
|
||||
|
||||
@@ -33,32 +33,20 @@ namespace PocketSharp.Models
|
||||
|
||||
public List<Parameter> Convert()
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>();
|
||||
|
||||
if (State != null)
|
||||
parameters.Add(CreateParam("state", State.ToString()));
|
||||
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));
|
||||
if (Domain != null)
|
||||
parameters.Add(CreateParam("domain", Domain));
|
||||
if (Since != null)
|
||||
parameters.Add(CreateParam("since", (int)((DateTime)Since - new DateTime(1970, 1, 1)).TotalSeconds));
|
||||
if (Count != null)
|
||||
parameters.Add(CreateParam("count", Count));
|
||||
if (Offset != null)
|
||||
parameters.Add(CreateParam("offset", Offset));
|
||||
|
||||
return parameters;
|
||||
return new List<Parameter>()
|
||||
{
|
||||
Utilities.CreateParam("state", State != null ? State.ToString() : null ),
|
||||
Utilities.CreateParam("favorite", Favorite != null ? (bool)Favorite ? "1" : "0" : null),
|
||||
Utilities.CreateParam("tag", Tag),
|
||||
Utilities.CreateParam("contentType", ContentType != null ? ContentType.ToString() : null),
|
||||
Utilities.CreateParam("sort", Sort != null ? Sort.ToString() : null),
|
||||
Utilities.CreateParam("detailType", DetailType != null ? DetailType.ToString() : null),
|
||||
Utilities.CreateParam("search", Search),
|
||||
Utilities.CreateParam("domain", Domain),
|
||||
Utilities.CreateParam("since", Utilities.GetUnixTimestamp(Since)),
|
||||
Utilities.CreateParam("count", Count),
|
||||
Utilities.CreateParam("offset", Offset)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,6 @@
|
||||
<Compile Include="Models\Response\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" />
|
||||
@@ -74,6 +73,7 @@
|
||||
<Compile Include="Models\Response\Retrieve.cs" />
|
||||
<Compile Include="PocketClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
internal class Utilities
|
||||
{
|
||||
public static int? GetUnixTimestamp(DateTime? dateTime)
|
||||
{
|
||||
if(dateTime == null) return null;
|
||||
|
||||
return (int)((DateTime)dateTime - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
}
|
||||
|
||||
|
||||
public static Parameter CreateParam(string name, object value, ParameterType type = ParameterType.GetOrPost)
|
||||
{
|
||||
return new Parameter()
|
||||
{
|
||||
Name = name,
|
||||
Value = value,
|
||||
Type = type
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user