From 5c6dae63f7669ac83aad67f6639527a1260ba415 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Tue, 18 Nov 2014 22:38:41 +0100 Subject: [PATCH] Get, Update and Delete categories --- FeedlySharp/FeedlyClient.Categories.cs | 33 ++++++++++++++++++++++++++ FeedlySharp/FeedlyHttpClient.cs | 9 +++++++ FeedlySharp/FeedlySharp.csproj | 2 ++ FeedlySharp/Models/FeedlyCategory.cs | 14 +++++++++++ 4 files changed, 58 insertions(+) create mode 100644 FeedlySharp/FeedlyClient.Categories.cs create mode 100644 FeedlySharp/Models/FeedlyCategory.cs diff --git a/FeedlySharp/FeedlyClient.Categories.cs b/FeedlySharp/FeedlyClient.Categories.cs new file mode 100644 index 0000000..1736a0f --- /dev/null +++ b/FeedlySharp/FeedlyClient.Categories.cs @@ -0,0 +1,33 @@ +using FeedlySharp.Models; +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace FeedlySharp +{ + public partial class FeedlyClient + { + public async Task> GetCategories(CancellationToken cancellationToken = default(CancellationToken)) + { + return await Client.AuthRequest>(HttpMethod.Get, "v3/categories", null, cancellationToken); + } + + + public async Task UpdateCategory(string id, string label, CancellationToken cancellationToken = default(CancellationToken)) + { + await Client.AuthRequest(HttpMethod.Post, String.Format("v3/categories/{0}", id), new Dictionary() + { + { "label", label } + }, cancellationToken); + } + + + public async Task DeleteCategory(string id, CancellationToken cancellationToken = default(CancellationToken)) + { + await Client.AuthRequest(HttpMethod.Delete, String.Format("v3/categories/{0}", id), null, cancellationToken); + } + } +} diff --git a/FeedlySharp/FeedlyHttpClient.cs b/FeedlySharp/FeedlyHttpClient.cs index 682de88..913cde3 100644 --- a/FeedlySharp/FeedlyHttpClient.cs +++ b/FeedlySharp/FeedlyHttpClient.cs @@ -88,6 +88,15 @@ namespace FeedlySharp } } + if (responseString == "[]") + { + return new T(); + } + if ((new string[] { "", "{}" }).Contains(responseString)) + { + return null; + } + return DeserializeJson(responseString); } diff --git a/FeedlySharp/FeedlySharp.csproj b/FeedlySharp/FeedlySharp.csproj index 5b1cdb8..c843f7d 100644 --- a/FeedlySharp/FeedlySharp.csproj +++ b/FeedlySharp/FeedlySharp.csproj @@ -37,10 +37,12 @@ + + diff --git a/FeedlySharp/Models/FeedlyCategory.cs b/FeedlySharp/Models/FeedlyCategory.cs new file mode 100644 index 0000000..4895a07 --- /dev/null +++ b/FeedlySharp/Models/FeedlyCategory.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; +using System; + +namespace FeedlySharp.Models +{ + public class FeedlyCategory + { + public string Id { get; set; } + + public string Label { get; set; } + + public bool IsGlobal { get; set; } + } +}