From cbbce90a432cc60fae483ba91ab32002ef482824 Mon Sep 17 00:00:00 2001 From: ceee Date: Fri, 14 Jun 2013 12:13:57 +0200 Subject: [PATCH] update Retrieve model to serve a List + Dictionary of items; --- PocketSharp.Console/Program.cs | 2 +- .../Components/{Get.cs => Retrieve.cs} | 12 ++--- PocketSharp/IPocketClient.cs | 50 ------------------- PocketSharp/Models/Retrieve.cs | 24 +++++++-- PocketSharp/PocketClient.cs | 8 +-- PocketSharp/PocketSharp.csproj | 3 +- 6 files changed, 33 insertions(+), 66 deletions(-) rename PocketSharp/Components/{Get.cs => Retrieve.cs} (53%) delete mode 100644 PocketSharp/IPocketClient.cs diff --git a/PocketSharp.Console/Program.cs b/PocketSharp.Console/Program.cs index b3a729c..0316273 100644 --- a/PocketSharp.Console/Program.cs +++ b/PocketSharp.Console/Program.cs @@ -16,7 +16,7 @@ namespace PocketSharp.Console PocketClient client = new PocketClient("15396-f6f92101d72c8e270a6c9bb3"); client.AccessCode = "a85134a7-243c-6656-ab82-97c901"; - client.Get(); + client.Retrieve(); System.Console.ReadKey(); } diff --git a/PocketSharp/Components/Get.cs b/PocketSharp/Components/Retrieve.cs similarity index 53% rename from PocketSharp/Components/Get.cs rename to PocketSharp/Components/Retrieve.cs index 5a5f042..05f6317 100644 --- a/PocketSharp/Components/Get.cs +++ b/PocketSharp/Components/Retrieve.cs @@ -7,14 +7,14 @@ using System.Text; namespace PocketSharp { - public partial class PocketClient : IPocketClient + public partial class PocketClient { - public bool Get() + public bool Retrieve() { - //var parameters = new List() - //{ - // new Parameter { Name = "favorite", Value = "1", Type = ParameterType.GetOrPost } - //}; + var parameters = new List() + { + new Parameter { Name = "favorite", Value = "1", Type = ParameterType.GetOrPost } + }; Retrieve result = GetResource("get", parameters); diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs deleted file mode 100644 index a282c34..0000000 --- a/PocketSharp/IPocketClient.cs +++ /dev/null @@ -1,50 +0,0 @@ -using RestSharp; -using System; -using System.Collections.Generic; - -namespace PocketSharp -{ - public interface IPocketClient - { - /// - /// base URL for the API - /// - Uri BaseUrl { get; set; } - - /// - /// Accessor for the Pocket API key - /// see: http://getpocket.com/developer - /// - string ConsumerKey { get; set; } - - /// - /// Returns all associated data from the last request - /// - IRestResponse LastRequestData { get; } - - /// - /// Makes a HTTP REST request to the API - /// - /// The request. - /// - string Request(RestRequest request); - - /// - /// Makes a typed HTTP REST request to the API - /// - /// - /// The request. - /// - T Request(RestRequest request) where T : new(); - - /// - /// Fetches a typed resource - /// - /// - /// Requested method (path after /v3/) - /// Additional POST parameters - /// - /// No access token available. Use authentification first. - T GetResource(string method, List parameters) where T : class, new(); - } -} diff --git a/PocketSharp/Models/Retrieve.cs b/PocketSharp/Models/Retrieve.cs index a5c1058..8966042 100644 --- a/PocketSharp/Models/Retrieve.cs +++ b/PocketSharp/Models/Retrieve.cs @@ -7,13 +7,31 @@ namespace PocketSharp.Models [DataContract] class Retrieve : ResponseBase { - [DataMember] - public bool Complete { get; set; } + [DataMember(Name = "complete")] + public int Complete; [DataMember] public int Since { get; set; } [DataMember(Name = "list")] - public List Items { get; set; } + public Dictionary ItemDictionary { get; set; } + + [IgnoreDataMember] + public List Items + { + get + { + var itemEnumerator = ItemDictionary.GetEnumerator(); + List result = new List(); + + while (itemEnumerator.MoveNext()) + { + result.Add(itemEnumerator.Current.Value); + } + + return result; + } + private set {} + } } } diff --git a/PocketSharp/PocketClient.cs b/PocketSharp/PocketClient.cs index 97add76..d9dc1fc 100644 --- a/PocketSharp/PocketClient.cs +++ b/PocketSharp/PocketClient.cs @@ -5,7 +5,7 @@ using System.Net; namespace PocketSharp { - public partial class PocketClient : IPocketClient + public partial class PocketClient { /// /// REST client used for the API communication @@ -87,7 +87,7 @@ namespace PocketSharp /// /// The request. /// - public string Request(RestRequest request) + protected string Request(RestRequest request) { IRestResponse response = _restClient.Execute(request); @@ -103,7 +103,7 @@ namespace PocketSharp /// /// The request. /// - public T Request(RestRequest request) where T : new() + protected T Request(RestRequest request) where T : new() { IRestResponse response = _restClient.Execute(request); @@ -122,7 +122,7 @@ namespace PocketSharp /// Additional POST parameters /// /// No access token available. Use authentification first. - public T GetResource(string method, List parameters) where T : class, new() + protected T GetResource(string method, List parameters) where T : class, new() { // every single Pocket API endpoint requires HTTP POST data var request = new RestRequest(method, Method.POST); diff --git a/PocketSharp/PocketSharp.csproj b/PocketSharp/PocketSharp.csproj index 8a67ed3..c1c8c67 100644 --- a/PocketSharp/PocketSharp.csproj +++ b/PocketSharp/PocketSharp.csproj @@ -48,8 +48,7 @@ - - +