subscription endpoint

This commit is contained in:
2014-11-19 23:06:09 +01:00
parent a0941d2a8a
commit 9a0b3f9cf4
7 changed files with 102 additions and 7 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ namespace FeedlySharp
public async Task<Dictionary<string, string>> UpdatePreferences(Dictionary<string, string> preferences, CancellationToken cancellationToken = default(CancellationToken))
{
return await Client.Request<Dictionary<string, string>>(HttpMethod.Post, "v3/preferences", preferences, true, true, cancellationToken);
return (await Client.Request<Dictionary<string, string>>(HttpMethod.Post, "v3/preferences", preferences, true, true, cancellationToken)) ?? new Dictionary<string, string>();
}
}
}
+45
View File
@@ -0,0 +1,45 @@
using FeedlySharp.Models;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
namespace FeedlySharp
{
public partial class FeedlyClient
{
public async Task<List<FeedlySubscription>> GetSubscriptions(CancellationToken cancellationToken = default(CancellationToken))
{
return await Client.Request<List<FeedlySubscription>>(HttpMethod.Get, "v3/subscriptions", null, false, true, cancellationToken);
}
public async Task<bool> AddOrUpdateSubscription(string id, List<FeedlyCategory> categories = null, string optionalTitle = null, CancellationToken cancellationToken = default(CancellationToken))
{
dynamic parameters = new { id = (id.StartsWith("feed/") ? id : "feed/" + id) };
if (categories != null && categories.Any())
{
parameters.categories = categories;
}
if (!String.IsNullOrEmpty(optionalTitle))
{
parameters.title = optionalTitle;
}
await Client.Request(HttpMethod.Post, "v3/subscriptions", parameters, true, true, cancellationToken);
return true;
}
public async Task<bool> RemoveSubscription(string id, CancellationToken cancellationToken = default(CancellationToken))
{
id = id.StartsWith("feed/") ? id : "feed/" + id;
await Client.Request(HttpMethod.Delete, String.Format("v3/subscriptions/{0}", WebUtility.UrlEncode(id)), null, false, true, cancellationToken);
return true;
}
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ namespace FeedlySharp
throw new ArgumentOutOfRangeException("Select low, medium or high for the interest.");
}
await Client.Request(HttpMethod.Post, "v3/topics", new { id = ValueToResource("topic", topic), interest = interest.ToString().ToLower() }, false, true, cancellationToken);
await Client.Request(HttpMethod.Post, "v3/topics", new { id = ValueToResource("topic", topic, false), interest = interest.ToString().ToLower() }, true, true, cancellationToken);
return true;
}
+3 -2
View File
@@ -54,9 +54,10 @@ namespace FeedlySharp
return String.Format("https://{0}.feedly.com", environment == CloudEnvironment.Production ? "cloud" : "sandbox");
}
private string ValueToResource(string key, string value)
private string ValueToResource(string key, string value, bool encode = true)
{
return WebUtility.UrlEncode(String.Format("user/{0}/{1}/{2}", UserId, key, value));
string text = String.Format("user/{0}/{1}/{2}", UserId, key, value);
return encode ? WebUtility.UrlEncode(text) : text;
}
+4 -2
View File
@@ -34,7 +34,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Endpoints\Topic.cs" />
<Compile Include="Endpoints\Subscriptions.cs" />
<Compile Include="Endpoints\Topics.cs" />
<Compile Include="Models\FeedlySubscription.cs" />
<Compile Include="Models\FeedlyTopic.cs" />
<Compile Include="Endpoints\OPML.cs" />
<Compile Include="Extensions\JsonExtensions.cs" />
@@ -44,7 +46,7 @@
<Compile Include="Endpoints\Auth.cs" />
<Compile Include="Endpoints\Categories.cs" />
<Compile Include="FeedlyClient.cs" />
<Compile Include="Endpoints\User.cs" />
<Compile Include="Endpoints\Profile.cs" />
<Compile Include="FeedlyHttpClient.cs" />
<Compile Include="FeedlySharpException.cs" />
<Compile Include="Models\FeedlyCategory.cs" />
+6 -1
View File
@@ -1,14 +1,19 @@
using Newtonsoft.Json;
using System;
using System.Linq;
namespace FeedlySharp.Models
{
public class FeedlyCategory
{
[JsonProperty("id")]
public string Id { get; set; }
public string Name { get { return Id == null ? String.Empty : Id.Split('/').Last(); } }
[JsonProperty("label")]
public string Label { get; set; }
public bool IsGlobal { get; set; }
public bool IsGlobal { get { return Name.StartsWith("global."); } }
}
}
+42
View File
@@ -0,0 +1,42 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FeedlySharp.Models
{
public class FeedlySubscription
{
public string Id { get; set; }
[JsonProperty("title")]
public string Name { get; set; }
[JsonProperty("visualUrl")]
public Uri Image { get; set; }
public string CoverColor { get; set; }
[JsonProperty("coverUrl")]
public Uri CoverImage { get; set; }
[JsonProperty("iconUrl")]
public Uri IconImage { get; set; }
[JsonProperty("website")]
public Uri Uri { get; set; }
public List<FeedlyCategory> Categories { get; set; }
public string[] Topics { get; set; }
public int? Subscribers { get; set; }
public double? Velocity { get; set; }
[JsonProperty("updated")]
public DateTime? UpdateDate { get; set; }
}
}