preferences (get, update) endpoint

This commit is contained in:
2014-11-19 18:31:32 +01:00
parent 1fbec8b809
commit 50fee10ce6
5 changed files with 59 additions and 11 deletions
+3 -6
View File
@@ -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<FeedlyUser>(HttpMethod.Post, String.Format("v3/categories/{0}", id), new Dictionary<string, string>()
{
{ "label", label }
}, cancellationToken);
await Client.AuthRequest<FeedlyUser>(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<FeedlyUser>(HttpMethod.Delete, String.Format("v3/categories/{0}", id), null, cancellationToken);
await Client.AuthRequest<FeedlyUser>(HttpMethod.Delete, String.Format("v3/categories/{0}", ValueToResource("category", id)), null, cancellationToken);
}
}
}
+24
View File
@@ -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<Dictionary<string, string>> GetPreferences(CancellationToken cancellationToken = default(CancellationToken))
{
return (await Client.AuthRequest<Dictionary<string, string>>(HttpMethod.Get, "v3/preferences", null, cancellationToken)) ?? new Dictionary<string, string>();
}
public async Task<Dictionary<string, string>> UpdatePreferences(Dictionary<string, string> preferences, CancellationToken cancellationToken = default(CancellationToken))
{
return await Client.AuthRequest<Dictionary<string, string>>(HttpMethod.Post, "v3/preferences", preferences, true, cancellationToken);
}
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ namespace FeedlySharp
}
public async Task<FeedlyUser> UpdateUser(Dictionary<string, string> parameters, CancellationToken cancellationToken = default(CancellationToken))
public async Task<FeedlyUser> UpdateUser(dynamic parameters, CancellationToken cancellationToken = default(CancellationToken))
{
return await Client.AuthRequest<FeedlyUser>(HttpMethod.Post, "v3/profile", parameters, cancellationToken);
}
+30 -4
View File
@@ -32,7 +32,21 @@ namespace FeedlySharp
throw new FeedlySharpException("This request requires an access token.");
}
return await Request<T>(method, requestUri, parameters, null, cancellationToken, new Dictionary<string,string>()
return await Request<T>(method, requestUri, parameters, null, false, cancellationToken, new Dictionary<string,string>()
{
{ "Authorization", String.Format("OAuth {0}", AccessToken) }
});
}
public async Task<T> AuthRequest<T>(HttpMethod method, string requestUri, Dictionary<string, string> 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<T>(method, requestUri, parameters, null, bodyAsJson, cancellationToken, new Dictionary<string, string>()
{
{ "Authorization", String.Format("OAuth {0}", AccessToken) }
});
@@ -46,24 +60,36 @@ namespace FeedlySharp
throw new FeedlySharpException("This request requires an access token.");
}
return await Request<T>(method, requestUri, null, body, cancellationToken, new Dictionary<string, string>()
return await Request<T>(method, requestUri, null, body, true, cancellationToken, new Dictionary<string, string>()
{
{ "Authorization", String.Format("OAuth {0}", AccessToken) }
});
}
public async Task<T> Request<T>(HttpMethod method, string requestUri, Dictionary<string, string> parameters = null, dynamic body = null, CancellationToken cancellationToken = default(CancellationToken), Dictionary<string, string> headers = null) where T : class, new()
public async Task<T> Request<T>(
HttpMethod method,
string requestUri,
Dictionary<string, string> parameters = null,
dynamic body = null,
bool bodyAsJson = false,
CancellationToken cancellationToken = default(CancellationToken),
Dictionary<string, string> 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)
{
+1
View File
@@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="Extensions\JsonExtensions.cs" />
<Compile Include="Extensions\UriExtensions.cs" />
<Compile Include="FeedlyClient.Preferences.cs" />
<Compile Include="FeedlyClient.Tags.cs" />
<Compile Include="FeedlyClient.Auth.cs" />
<Compile Include="FeedlyClient.Categories.cs" />