diff --git a/FeedlySharp/FeedlyClient.Categories.cs b/FeedlySharp/FeedlyClient.Categories.cs index 1736a0f..749b459 100644 --- a/FeedlySharp/FeedlyClient.Categories.cs +++ b/FeedlySharp/FeedlyClient.Categories.cs @@ -16,18 +16,15 @@ namespace FeedlySharp } - public async Task UpdateCategory(string id, string label, CancellationToken cancellationToken = default(CancellationToken)) + public async Task RenameCategory(string id, string label, CancellationToken cancellationToken = default(CancellationToken)) { - await Client.AuthRequest(HttpMethod.Post, String.Format("v3/categories/{0}", id), new Dictionary() - { - { "label", label } - }, cancellationToken); + await Client.AuthRequest(HttpMethod.Post, String.Format("v3/categories/{0}", ValueToResource("category", id)), new { 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); + await Client.AuthRequest(HttpMethod.Delete, String.Format("v3/categories/{0}", ValueToResource("category", id)), null, cancellationToken); } } } diff --git a/FeedlySharp/FeedlyClient.Preferences.cs b/FeedlySharp/FeedlyClient.Preferences.cs new file mode 100644 index 0000000..20a729e --- /dev/null +++ b/FeedlySharp/FeedlyClient.Preferences.cs @@ -0,0 +1,24 @@ +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> GetPreferences(CancellationToken cancellationToken = default(CancellationToken)) + { + return (await Client.AuthRequest>(HttpMethod.Get, "v3/preferences", null, cancellationToken)) ?? new Dictionary(); + } + + + public async Task> UpdatePreferences(Dictionary preferences, CancellationToken cancellationToken = default(CancellationToken)) + { + return await Client.AuthRequest>(HttpMethod.Post, "v3/preferences", preferences, true, cancellationToken); + } + } +} diff --git a/FeedlySharp/FeedlyClient.User.cs b/FeedlySharp/FeedlyClient.User.cs index 338f5d7..61acc19 100644 --- a/FeedlySharp/FeedlyClient.User.cs +++ b/FeedlySharp/FeedlyClient.User.cs @@ -16,7 +16,7 @@ namespace FeedlySharp } - public async Task UpdateUser(Dictionary parameters, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateUser(dynamic parameters, CancellationToken cancellationToken = default(CancellationToken)) { return await Client.AuthRequest(HttpMethod.Post, "v3/profile", parameters, cancellationToken); } diff --git a/FeedlySharp/FeedlyHttpClient.cs b/FeedlySharp/FeedlyHttpClient.cs index 4bab7ed..208f8ed 100644 --- a/FeedlySharp/FeedlyHttpClient.cs +++ b/FeedlySharp/FeedlyHttpClient.cs @@ -32,7 +32,21 @@ namespace FeedlySharp throw new FeedlySharpException("This request requires an access token."); } - return await Request(method, requestUri, parameters, null, cancellationToken, new Dictionary() + return await Request(method, requestUri, parameters, null, false, cancellationToken, new Dictionary() + { + { "Authorization", String.Format("OAuth {0}", AccessToken) } + }); + } + + + public async Task AuthRequest(HttpMethod method, string requestUri, Dictionary parameters = null, bool bodyAsJson = false, CancellationToken cancellationToken = default(CancellationToken)) where T : class, new() + { + if (String.IsNullOrEmpty(AccessToken)) + { + throw new FeedlySharpException("This request requires an access token."); + } + + return await Request(method, requestUri, parameters, null, bodyAsJson, cancellationToken, new Dictionary() { { "Authorization", String.Format("OAuth {0}", AccessToken) } }); @@ -46,24 +60,36 @@ namespace FeedlySharp throw new FeedlySharpException("This request requires an access token."); } - return await Request(method, requestUri, null, body, cancellationToken, new Dictionary() + return await Request(method, requestUri, null, body, true, cancellationToken, new Dictionary() { { "Authorization", String.Format("OAuth {0}", AccessToken) } }); } - public async Task Request(HttpMethod method, string requestUri, Dictionary parameters = null, dynamic body = null, CancellationToken cancellationToken = default(CancellationToken), Dictionary headers = null) where T : class, new() + public async Task Request( + HttpMethod method, + string requestUri, + Dictionary parameters = null, + dynamic body = null, + bool bodyAsJson = false, + CancellationToken cancellationToken = default(CancellationToken), + Dictionary headers = null + ) where T : class, new() { HttpRequestMessage request = new HttpRequestMessage(method, requestUri); HttpResponseMessage response = null; string responseString = null; // content of the request - if (parameters != null) + if (parameters != null && !bodyAsJson) { request.Content = new FormUrlEncodedContent(parameters); } + else if (parameters != null) + { + request.Content = new StringContent(JsonConvert.SerializeObject(parameters)); + } // additional headers if (headers != null) { diff --git a/FeedlySharp/FeedlySharp.csproj b/FeedlySharp/FeedlySharp.csproj index afcafaf..110cc7a 100644 --- a/FeedlySharp/FeedlySharp.csproj +++ b/FeedlySharp/FeedlySharp.csproj @@ -36,6 +36,7 @@ +