diff --git a/FeedlySharp/Endpoints/Preferences.cs b/FeedlySharp/Endpoints/Preferences.cs index 0ae75a3..862ead7 100644 --- a/FeedlySharp/Endpoints/Preferences.cs +++ b/FeedlySharp/Endpoints/Preferences.cs @@ -18,7 +18,7 @@ namespace FeedlySharp public async Task> UpdatePreferences(Dictionary preferences, CancellationToken cancellationToken = default(CancellationToken)) { - return await Client.Request>(HttpMethod.Post, "v3/preferences", preferences, true, true, cancellationToken); + return (await Client.Request>(HttpMethod.Post, "v3/preferences", preferences, true, true, cancellationToken)) ?? new Dictionary(); } } } diff --git a/FeedlySharp/Endpoints/Subscriptions.cs b/FeedlySharp/Endpoints/Subscriptions.cs new file mode 100644 index 0000000..45171c2 --- /dev/null +++ b/FeedlySharp/Endpoints/Subscriptions.cs @@ -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> GetSubscriptions(CancellationToken cancellationToken = default(CancellationToken)) + { + return await Client.Request>(HttpMethod.Get, "v3/subscriptions", null, false, true, cancellationToken); + } + + + public async Task AddOrUpdateSubscription(string id, List 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 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; + } + } +} diff --git a/FeedlySharp/Endpoints/Topics.cs b/FeedlySharp/Endpoints/Topics.cs index 19f7c0a..57c3a17 100644 --- a/FeedlySharp/Endpoints/Topics.cs +++ b/FeedlySharp/Endpoints/Topics.cs @@ -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; } diff --git a/FeedlySharp/FeedlyClient.cs b/FeedlySharp/FeedlyClient.cs index 79964cc..f417135 100644 --- a/FeedlySharp/FeedlyClient.cs +++ b/FeedlySharp/FeedlyClient.cs @@ -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; } diff --git a/FeedlySharp/FeedlySharp.csproj b/FeedlySharp/FeedlySharp.csproj index 16625ff..75216af 100644 --- a/FeedlySharp/FeedlySharp.csproj +++ b/FeedlySharp/FeedlySharp.csproj @@ -34,7 +34,9 @@ 4 - + + + @@ -44,7 +46,7 @@ - + diff --git a/FeedlySharp/Models/FeedlyCategory.cs b/FeedlySharp/Models/FeedlyCategory.cs index 4895a07..966547c 100644 --- a/FeedlySharp/Models/FeedlyCategory.cs +++ b/FeedlySharp/Models/FeedlyCategory.cs @@ -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."); } } } } diff --git a/FeedlySharp/Models/FeedlySubscription.cs b/FeedlySharp/Models/FeedlySubscription.cs new file mode 100644 index 0000000..892ac4e --- /dev/null +++ b/FeedlySharp/Models/FeedlySubscription.cs @@ -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 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; } + } +}