From 91c2fadacfd58336ff6a3fb73308cf1dee9094fe Mon Sep 17 00:00:00 2001 From: ceee Date: Wed, 19 Jun 2013 23:05:12 +0200 Subject: [PATCH] refactor utilities into seperate namespace --- PocketSharp.Console/Program.cs | 6 +++-- PocketSharp/Components/Retrieve.cs | 14 +++++----- PocketSharp/PocketClient.cs | 1 + PocketSharp/PocketSharp.csproj | 4 +-- PocketSharp/Utilties/APIException.cs | 25 +++++++++++++++++ PocketSharp/Utilties/JsonDeserializer.cs | 34 ++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 PocketSharp/Utilties/APIException.cs create mode 100644 PocketSharp/Utilties/JsonDeserializer.cs diff --git a/PocketSharp.Console/Program.cs b/PocketSharp.Console/Program.cs index a5c8aec..048372d 100644 --- a/PocketSharp.Console/Program.cs +++ b/PocketSharp.Console/Program.cs @@ -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(); diff --git a/PocketSharp/Components/Retrieve.cs b/PocketSharp/Components/Retrieve.cs index 62b185d..1d5fe53 100644 --- a/PocketSharp/Components/Retrieve.cs +++ b/PocketSharp/Components/Retrieve.cs @@ -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("get", parameters.Convert()); + Retrieve result = GetResource("get", para.Convert()); return true; } diff --git a/PocketSharp/PocketClient.cs b/PocketSharp/PocketClient.cs index 045d7a0..d8d1a23 100644 --- a/PocketSharp/PocketClient.cs +++ b/PocketSharp/PocketClient.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Net; +using PocketSharp.Utilities; namespace PocketSharp { diff --git a/PocketSharp/PocketSharp.csproj b/PocketSharp/PocketSharp.csproj index 1f78d05..55a985a 100644 --- a/PocketSharp/PocketSharp.csproj +++ b/PocketSharp/PocketSharp.csproj @@ -46,10 +46,10 @@ - + - + diff --git a/PocketSharp/Utilties/APIException.cs b/PocketSharp/Utilties/APIException.cs new file mode 100644 index 0000000..6e12410 --- /dev/null +++ b/PocketSharp/Utilties/APIException.cs @@ -0,0 +1,25 @@ +using System; +using System.Runtime.Serialization; + +namespace PocketSharp.Utilities +{ + [Serializable] + public class APIException : Exception + { + /// + /// necessary constructors for the exception + /// including inner exceptions and serialization + /// + 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) { } + } +} diff --git a/PocketSharp/Utilties/JsonDeserializer.cs b/PocketSharp/Utilties/JsonDeserializer.cs new file mode 100644 index 0000000..6ea252e --- /dev/null +++ b/PocketSharp/Utilties/JsonDeserializer.cs @@ -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"; + + /// + /// Deserializes the specified response. + /// + /// + /// The response. + /// + public T Deserialize(IRestResponse response) + { + var x = JsonSerializer.DeserializeFromString(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; } + } + } +}