opml (get) endpoint
This commit is contained in:
@@ -55,7 +55,7 @@ namespace FeedlySharp
|
||||
{ "client_secret", ClientSecret },
|
||||
{ "redirect_uri", RedirectUri },
|
||||
{ "grant_type", "authorization_code" }
|
||||
}, cancellationToken);
|
||||
}, false, false, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace FeedlySharp
|
||||
{ "client_id", ClientId },
|
||||
{ "client_secret", ClientSecret },
|
||||
{ "grant_type", "refresh_token" }
|
||||
}, cancellationToken);
|
||||
}, false, false, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace FeedlySharp
|
||||
{ "client_id", ClientId },
|
||||
{ "client_secret", ClientSecret },
|
||||
{ "grant_type", "revoke_token" }
|
||||
}, cancellationToken);
|
||||
}, false, false, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,19 @@ namespace FeedlySharp
|
||||
{
|
||||
public async Task<List<FeedlyCategory>> GetCategories(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await Client.AuthRequest<List<FeedlyCategory>>(HttpMethod.Get, "v3/categories", null, cancellationToken);
|
||||
return await Client.Request<List<FeedlyCategory>>(HttpMethod.Get, "v3/categories", null, false, true, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public async Task RenameCategory(string id, string label, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
await Client.AuthRequest<FeedlyUser>(HttpMethod.Post, String.Format("v3/categories/{0}", ValueToResource("category", id)), new { label = label }, cancellationToken);
|
||||
await Client.Request<FeedlyUser>(HttpMethod.Post, String.Format("v3/categories/{0}", ValueToResource("category", id)), new { label = label }, true, true, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public async Task DeleteCategory(string id, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
await Client.AuthRequest<FeedlyUser>(HttpMethod.Delete, String.Format("v3/categories/{0}", ValueToResource("category", id)), null, cancellationToken);
|
||||
await Client.Request<FeedlyUser>(HttpMethod.Delete, String.Format("v3/categories/{0}", ValueToResource("category", id)), null, false, true, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<string> GetOPML(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await Client.Request(HttpMethod.Get, "v3/opml", null, false, true, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public async Task ImportOPML(string opml, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,13 @@ namespace FeedlySharp
|
||||
{
|
||||
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>();
|
||||
return (await Client.Request<Dictionary<string, string>>(HttpMethod.Get, "v3/preferences", null, false, true, 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);
|
||||
return await Client.Request<Dictionary<string, string>>(HttpMethod.Post, "v3/preferences", preferences, true, true, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,14 @@ namespace FeedlySharp
|
||||
{
|
||||
public async Task<List<FeedlyTag>> GetTags(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await Client.AuthRequest<List<FeedlyTag>>(HttpMethod.Get, "v3/tags", null, cancellationToken);
|
||||
return await Client.Request<List<FeedlyTag>>(HttpMethod.Get, "v3/tags", null, false, true, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateTags(string entryId, string[] tags, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
string tagsString = String.Join(",", tags.Select(x => ValueToResource("tag", x)));
|
||||
await Client.AuthRequest<object>(HttpMethod.Put, String.Format("v3/tags/{0}", tagsString), new { entryId = entryId }, cancellationToken);
|
||||
await Client.Request<object>(HttpMethod.Put, String.Format("v3/tags/{0}", tagsString), new { entryId = entryId }, true, true, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ namespace FeedlySharp
|
||||
public async Task<bool> UpdateTags(string[] entryIds, string[] tags, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
string tagsString = String.Join(",", tags.Select(x => ValueToResource("tag", x)));
|
||||
await Client.AuthRequest<object>(HttpMethod.Put, String.Format("v3/tags/{0}", tagsString), new { entryIds = entryIds }, cancellationToken);
|
||||
await Client.Request<object>(HttpMethod.Put, String.Format("v3/tags/{0}", tagsString), new { entryIds = entryIds }, true, true, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> RenameTag(string oldTag, string newTag, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
await Client.AuthRequest<object>(HttpMethod.Post, String.Format("v3/tags/{0}", ValueToResource("tag", oldTag)), new { label = newTag }, cancellationToken);
|
||||
await Client.Request<object>(HttpMethod.Post, String.Format("v3/tags/{0}", ValueToResource("tag", oldTag)), new { label = newTag }, true, true, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace FeedlySharp
|
||||
{
|
||||
string tagsString = String.Join(",", tags.Select(x => ValueToResource("tag", x)));
|
||||
string entryIdsString = String.Join(",", entryIds.Select(x => WebUtility.UrlEncode(x)));
|
||||
await Client.AuthRequest<object>(HttpMethod.Delete, String.Format("v3/tags/{0}/{1}", tagsString, entryIdsString), null, cancellationToken);
|
||||
await Client.Request<object>(HttpMethod.Delete, String.Format("v3/tags/{0}/{1}", tagsString, entryIdsString), null, false, true, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace FeedlySharp
|
||||
public async Task<bool> RemoveTags(string[] tags, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
string tagsString = String.Join(",", tags.Select(x => ValueToResource("tag", x)));
|
||||
await Client.AuthRequest<object>(HttpMethod.Delete, String.Format("v3/tags/{0}", tagsString), null, cancellationToken);
|
||||
await Client.Request<object>(HttpMethod.Delete, String.Format("v3/tags/{0}", tagsString), null, false, true, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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<FeedlyUser> GetUser(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await Client.Request<FeedlyUser>(HttpMethod.Get, "v3/profile", null, false, true, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public async Task<FeedlyUser> UpdateUser(Dictionary<string, string> parameters, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await Client.Request<FeedlyUser>(HttpMethod.Post, "v3/profile", parameters, true, true, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
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<FeedlyUser> GetUser(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await Client.AuthRequest<FeedlyUser>(HttpMethod.Get, "v3/profile", null, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public async Task<FeedlyUser> UpdateUser(dynamic parameters, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await Client.AuthRequest<FeedlyUser>(HttpMethod.Post, "v3/profile", parameters, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,85 +25,59 @@ namespace FeedlySharp
|
||||
}
|
||||
|
||||
|
||||
public async Task<T> AuthRequest<T>(HttpMethod method, string requestUri, Dictionary<string, string> parameters = null, 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, 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) }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public async Task<T> AuthRequest<T>(HttpMethod method, string requestUri, dynamic body = null, 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, 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,
|
||||
object body = null,
|
||||
bool bodyAsJson = false,
|
||||
CancellationToken cancellationToken = default(CancellationToken),
|
||||
Dictionary<string, string> headers = null
|
||||
bool isOauth = true,
|
||||
CancellationToken cancellationToken = default(CancellationToken)
|
||||
) where T : class, new()
|
||||
{
|
||||
string responseString = await Request(method, requestUri, body, bodyAsJson, isOauth, cancellationToken);
|
||||
|
||||
if (responseString == "[]")
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
if ((new string[] { "", "{}" }).Contains(responseString))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return DeserializeJson<T>(responseString);
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Request(
|
||||
HttpMethod method,
|
||||
string requestUri,
|
||||
object body = null,
|
||||
bool bodyAsJson = false,
|
||||
bool isOauth = true,
|
||||
CancellationToken cancellationToken = default(CancellationToken)
|
||||
)
|
||||
{
|
||||
HttpRequestMessage request = new HttpRequestMessage(method, requestUri);
|
||||
HttpResponseMessage response = null;
|
||||
string responseString = null;
|
||||
|
||||
// content of the request
|
||||
if (parameters != null && !bodyAsJson)
|
||||
if (body != null && !bodyAsJson)
|
||||
{
|
||||
request.Content = new FormUrlEncodedContent(parameters);
|
||||
request.Content = new FormUrlEncodedContent(body as Dictionary<string, string>);
|
||||
}
|
||||
else if (parameters != null)
|
||||
{
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(parameters));
|
||||
}
|
||||
// additional headers
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> header in headers)
|
||||
{
|
||||
request.Headers.Add(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
// body
|
||||
if (body != null)
|
||||
else if (body != null)
|
||||
{
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(body));
|
||||
}
|
||||
|
||||
// OAuth header
|
||||
if (isOauth)
|
||||
{
|
||||
request.Headers.Add("Authorization", String.Format("OAuth {0}", AccessToken));
|
||||
}
|
||||
|
||||
// make async request
|
||||
try
|
||||
{
|
||||
@@ -133,16 +107,7 @@ namespace FeedlySharp
|
||||
}
|
||||
}
|
||||
|
||||
if (responseString == "[]")
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
if ((new string[] { "", "{}" }).Contains(responseString))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return DeserializeJson<T>(responseString);
|
||||
return responseString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,14 +34,15 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Endpoints\OPML.cs" />
|
||||
<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" />
|
||||
<Compile Include="Endpoints\Preferences.cs" />
|
||||
<Compile Include="Endpoints\Tags.cs" />
|
||||
<Compile Include="Endpoints\Auth.cs" />
|
||||
<Compile Include="Endpoints\Categories.cs" />
|
||||
<Compile Include="FeedlyClient.cs" />
|
||||
<Compile Include="FeedlyClient.User.cs" />
|
||||
<Compile Include="Endpoints\User.cs" />
|
||||
<Compile Include="FeedlyHttpClient.cs" />
|
||||
<Compile Include="FeedlySharpException.cs" />
|
||||
<Compile Include="Models\FeedlyCategory.cs" />
|
||||
|
||||
Reference in New Issue
Block a user