refactor utilities into seperate namespace
This commit is contained in:
@@ -14,11 +14,13 @@ 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("15396-f6f92101d72c8e270a6c9bb3");
|
||||
PocketClient client = new PocketClient(
|
||||
consumerKey: "15396-f6f92101d72c8e270a6c9bb3"
|
||||
);
|
||||
|
||||
client.Retrieve(new RetrieveParameters()
|
||||
{
|
||||
Favorite = true
|
||||
|
||||
});
|
||||
|
||||
System.Console.ReadKey();
|
||||
|
||||
@@ -17,15 +17,15 @@ namespace PocketSharp
|
||||
// new Parameter { Name = "favorite", Value = "1", Type = ParameterType.GetOrPost }
|
||||
//};
|
||||
|
||||
var parameters = new RetrieveParameters()
|
||||
{
|
||||
Favorite = true,
|
||||
State = StateEnum.all
|
||||
};
|
||||
//var parameters = new RetrieveParameters()
|
||||
//{
|
||||
// Favorite = true,
|
||||
// State = StateEnum.all
|
||||
//};
|
||||
|
||||
var paramss = parameters.Convert();
|
||||
var paramss = para.Convert();
|
||||
|
||||
Retrieve result = GetResource<Retrieve>("get", parameters.Convert());
|
||||
Retrieve result = GetResource<Retrieve>("get", para.Convert());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using PocketSharp.Utilities;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
|
||||
@@ -46,10 +46,10 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="APIException.cs" />
|
||||
<Compile Include="Utilties\APIException.cs" />
|
||||
<Compile Include="Components\Authentification.cs" />
|
||||
<Compile Include="Components\Retrieve.cs" />
|
||||
<Compile Include="JsonDeserializer.cs" />
|
||||
<Compile Include="Utilties\JsonDeserializer.cs" />
|
||||
<Compile Include="Models\Authentification\AccessCode.cs" />
|
||||
<Compile Include="Models\Authentification\RequestCode.cs" />
|
||||
<Compile Include="Models\Parameters\ParameterBase.cs" />
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Utilities
|
||||
{
|
||||
[Serializable]
|
||||
public class APIException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// necessary constructors for the exception
|
||||
/// including inner exceptions and serialization
|
||||
/// </summary>
|
||||
public APIException()
|
||||
: base() { }
|
||||
|
||||
public APIException(string message)
|
||||
: base(message) { }
|
||||
|
||||
public APIException(string message, Exception innerException)
|
||||
: base(message, innerException) { }
|
||||
|
||||
protected APIException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using RestSharp;
|
||||
using RestSharp.Deserializers;
|
||||
using ServiceStack.Text;
|
||||
|
||||
namespace PocketSharp.Utilities
|
||||
{
|
||||
public class JsonDeserializer : IDeserializer
|
||||
{
|
||||
public const string JsonContentType = "application/json";
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the specified response.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="response">The response.</param>
|
||||
/// <returns></returns>
|
||||
public T Deserialize<T>(IRestResponse response)
|
||||
{
|
||||
var x = JsonSerializer.DeserializeFromString<T>(response.Content);
|
||||
return x;
|
||||
}
|
||||
|
||||
public string DateFormat { get; set; }
|
||||
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public string RootElement { get; set; }
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get { return JsonContentType; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user