refactor utilities into seperate namespace

This commit is contained in:
2013-06-19 23:05:12 +02:00
parent 95aa0d0841
commit 91c2fadacf
6 changed files with 73 additions and 11 deletions
+4 -2
View File
@@ -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();
+7 -7
View File
@@ -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;
}
+1
View File
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using PocketSharp.Utilities;
namespace PocketSharp
{
+2 -2
View File
@@ -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" />
+25
View File
@@ -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) { }
}
}
+34
View File
@@ -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; }
}
}
}