markers endpoint

This commit is contained in:
2014-11-23 16:48:17 +01:00
parent caebff5c80
commit 543a3310e7
9 changed files with 210 additions and 47 deletions
+118
View File
@@ -0,0 +1,118 @@
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;
using System.Dynamic;
namespace FeedlySharp
{
public partial class FeedlyClient
{
public async Task<List<FeedlyCategoryUnreadCount>> GetMarkersUnreadCount(bool isAutoRefresh = false, DateTime? newerThan = null, string categoryId = null, CancellationToken cancellationToken = default(CancellationToken))
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
if (isAutoRefresh)
{
parameters["autorefresh"] = "true";
}
if (newerThan.HasValue)
{
DateTime date = ((DateTime)newerThan.Value).ToUniversalTime();
DateTime epoc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
parameters["newerThan"] = Math.Truncate(date.Subtract(epoc).TotalMilliseconds).ToString();
}
if (!String.IsNullOrEmpty(categoryId))
{
parameters["streamId"] = ValueToResource("category", categoryId, false);
}
return (await Client.Request<CategoryUnreadCountResponse>(HttpMethod.Get, "v3/markers/counts", parameters, false, true, cancellationToken)).List;
}
public async Task<bool> MarkEntriesAsRead(string[] entryIds, CancellationToken cancellationToken = default(CancellationToken))
{
await Client.Request(HttpMethod.Post, "v3/markers", new { action = "markAsRead", entryIds = entryIds, type = "entries" }, true, true, cancellationToken);
return true;
}
public async Task<bool> MarkEntryAsRead(string entryId, CancellationToken cancellationToken = default(CancellationToken))
{
return await MarkEntriesAsRead(new string[] { entryId }, cancellationToken);
}
public async Task<bool> KeepEntriesAsUnread(string[] entryIds, CancellationToken cancellationToken = default(CancellationToken))
{
await Client.Request(HttpMethod.Post, "v3/markers", new { action = "keepUnread", entryIds = entryIds, type = "entries" }, true, true, cancellationToken);
return true;
}
public async Task<bool> KeepEntryAsUnread(string entryId, CancellationToken cancellationToken = default(CancellationToken))
{
return await KeepEntriesAsUnread(new string[] { entryId }, cancellationToken);
}
public async Task<bool> MarkFeedsAsRead(string[] feedIds, CancellationToken cancellationToken = default(CancellationToken))
{
await Client.Request(HttpMethod.Post, "v3/markers", new { action = "markAsRead", feedIds = feedIds, type = "feeds" }, true, true, cancellationToken);
return true;
}
public async Task<bool> MarkFeedAsRead(string feedId, CancellationToken cancellationToken = default(CancellationToken))
{
return await MarkFeedsAsRead(new string[] { feedId }, cancellationToken);
}
public async Task<bool> MarkCategoriesAsRead(string[] categoryIds, CancellationToken cancellationToken = default(CancellationToken))
{
categoryIds = categoryIds.Select(x => ValueToResource("category", x, false)).ToArray();
await Client.Request(HttpMethod.Post, "v3/markers", new { action = "markAsRead", categoryIds = categoryIds, type = "categories" }, true, true, cancellationToken);
return true;
}
public async Task<bool> MarkCategoryAsRead(string categoryId, CancellationToken cancellationToken = default(CancellationToken))
{
return await MarkCategoriesAsRead(new string[] { categoryId }, cancellationToken);
}
public async Task<bool> MarkEntriesAsSaved(string[] entryIds, CancellationToken cancellationToken = default(CancellationToken))
{
await Client.Request(HttpMethod.Post, "v3/markers", new { action = "markAsSaved", categoryIds = entryIds, type = "entries" }, true, true, cancellationToken);
return true;
}
public async Task<bool> MarkEntryAsSaved(string entryId, CancellationToken cancellationToken = default(CancellationToken))
{
return await MarkEntriesAsSaved(new string[] { entryId }, cancellationToken);
}
public async Task<bool> MarkEntriesAsUnsaved(string[] entryIds, CancellationToken cancellationToken = default(CancellationToken))
{
await Client.Request(HttpMethod.Post, "v3/markers", new { action = "markAsUnsaved", categoryIds = entryIds, type = "entries" }, true, true, cancellationToken);
return true;
}
public async Task<bool> MarkEntryAsUnsaved(string entryId, CancellationToken cancellationToken = default(CancellationToken))
{
return await MarkEntriesAsUnsaved(new string[] { entryId }, cancellationToken);
}
public async Task<FeedlyReadOperations> GetMarkersReadOperations(DateTime newerThan, CancellationToken cancellationToken = default(CancellationToken))
{
return await Client.Request<FeedlyReadOperations>(HttpMethod.Get, "v3/markers/reads", new Dictionary<string, string>()
{
{ "newerThan", Math.Truncate(newerThan.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds).ToString() }
}, false, true, cancellationToken);
}
}
}
+25
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
namespace FeedlySharp.Extensions
{
@@ -23,5 +24,29 @@ namespace FeedlySharp.Extensions
return output;
}
internal static string ToQueryString(this IDictionary<string, string> dict)
{
if (dict.Count == 0) return string.Empty;
var buffer = new StringBuilder();
int count = 0;
bool end = false;
foreach (var key in dict.Keys)
{
string value = WebUtility.UrlEncode(dict[key]);
if (count == dict.Count - 1) end = true;
if (end) buffer.AppendFormat("{0}={1}", key, value);
else buffer.AppendFormat("{0}={1}&", key, value);
count++;
}
return buffer.ToString();
}
}
}
+2 -2
View File
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace FeedlySharp
{
public partial class FeedlyClient : IDisposable, FeedlySharp.IFeedlyClient
public partial class FeedlyClient : IDisposable
{
public readonly CloudEnvironment Environment;
@@ -56,7 +56,7 @@ namespace FeedlySharp
private string ValueToResource(string key, string value, bool encode = true)
{
string text = String.Format("user/{0}/{1}/{2}", UserId, key, value);
string text = value.StartsWith("user/") ? value : String.Format("user/{0}/{1}/{2}", UserId, key, value);
return encode ? WebUtility.UrlEncode(text) : text;
}
+4 -3
View File
@@ -58,14 +58,15 @@ namespace FeedlySharp
CancellationToken cancellationToken = default(CancellationToken)
)
{
HttpRequestMessage request = new HttpRequestMessage(method, requestUri);
string append = body != null && !bodyAsJson && method == HttpMethod.Get ? ((requestUri.Contains("?") ? "&" : "?") + (body as Dictionary<string, string>).ToQueryString()) : "";
HttpRequestMessage request = new HttpRequestMessage(method, requestUri + append);
// content of the request
if (body != null && !bodyAsJson)
if (body != null && !bodyAsJson && method != HttpMethod.Get)
{
request.Content = new FormUrlEncodedContent(body as Dictionary<string, string>);
}
else if (body != null)
else if (body != null && method != HttpMethod.Get)
{
request.Content = new StringContent(JsonConvert.SerializeObject(body));
}
+3
View File
@@ -36,13 +36,16 @@
<ItemGroup>
<Compile Include="Endpoints\Entries.cs" />
<Compile Include="Endpoints\Feeds.cs" />
<Compile Include="Endpoints\Markers.cs" />
<Compile Include="Endpoints\Subscriptions.cs" />
<Compile Include="Endpoints\Topics.cs" />
<Compile Include="Models\FeedlyCategoryUnreadCount.cs" />
<Compile Include="Models\FeedlyEntry.cs" />
<Compile Include="Models\FeedlyFeed.cs" />
<Compile Include="Models\FeedlyImage.cs" />
<Compile Include="Models\FeedlyLink.cs" />
<Compile Include="Models\FeedlyOrigin.cs" />
<Compile Include="Models\FeedlyReadOperations.cs" />
<Compile Include="Models\FeedlySubscription.cs" />
<Compile Include="Models\FeedlyText.cs" />
<Compile Include="Models\FeedlyTopic.cs" />
-42
View File
@@ -1,42 +0,0 @@
using System;
using System.Threading;
namespace FeedlySharp
{
public interface IFeedlyClient
{
void Activate(string accessToken, string userId);
System.Threading.Tasks.Task<bool> AddOrUpdateSubscription(string id, System.Collections.Generic.List<FeedlySharp.Models.FeedlyCategory> categories = null, string optionalTitle = null, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> AddOrUpdateTopic(string topic, FeedlySharp.Models.Interest interest = Interest.Low, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task DeleteCategory(string id, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
void Dispose();
string GetAuthenticationUri(string scope = "subscriptions", string state = default(String));
System.Threading.Tasks.Task<System.Collections.Generic.List<FeedlySharp.Models.FeedlyCategory>> GetCategories(System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<System.Collections.Generic.List<FeedlySharp.Models.FeedlyEntry>> GetEntries(string[] ids, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<FeedlySharp.Models.FeedlyEntry> GetEntry(string id, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<FeedlySharp.Models.FeedlyFeed> GetFeed(string id, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<System.Collections.Generic.List<FeedlySharp.Models.FeedlyFeed>> GetFeeds(string[] ids, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<string> GetOPML(System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<string, string>> GetPreferences(System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<FeedlySharp.Models.FeedlyUser> GetProfile(System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<System.Collections.Generic.List<FeedlySharp.Models.FeedlySubscription>> GetSubscriptions(System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<System.Collections.Generic.List<FeedlySharp.Models.FeedlyTag>> GetTags(System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<System.Collections.Generic.List<FeedlySharp.Models.FeedlyTopic>> GetTopics(System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> ImportOPML(string opml, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
FeedlySharp.Models.AuthenticationResponse ParseAuthenticationResponseUri(string uri);
FeedlySharp.Models.AuthenticationResponse ParseAuthenticationResponseUri(Uri uri);
System.Threading.Tasks.Task<bool> RemoveSubscription(string id, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> RemoveTags(string[] entryIds, string[] tags, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> RemoveTags(string[] tags, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> RemoveTopic(string topic, FeedlySharp.Models.Interest interest = Interest.Low, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task RenameCategory(string id, string label, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> RenameTag(string oldTag, string newTag, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<FeedlySharp.Models.AccessTokenResponse> RequestAccessToken(string authenticationCode, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<FeedlySharp.Models.AccessTokenResponse> RequestRefreshToken(string refreshToken, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task RevokeRefreshToken(string refreshToken, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<string, string>> UpdatePreferences(System.Collections.Generic.Dictionary<string, string> preferences, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<FeedlySharp.Models.FeedlyUser> UpdateProfile(System.Collections.Generic.Dictionary<string, string> parameters, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> UpdateTags(string entryId, string[] tags, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
System.Threading.Tasks.Task<bool> UpdateTags(string[] entryIds, string[] tags, System.Threading.CancellationToken cancellationToken = default(CancellationToken));
}
}
@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FeedlySharp.Models
{
public class FeedlyCategoryUnreadCount
{
[JsonProperty("updated")]
public DateTime? UpdatedAt { get; set; }
public int Count { get; set; }
public string Id { get; set; }
public string Name { get { return Id == null ? String.Empty : Id.Split('/').Last(); } }
}
}
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FeedlySharp.Models
{
public class FeedlyReadOperations
{
[JsonProperty("feeds")]
public List<FeedlyReadOperationsFeed> ReadFeeds { get; set; }
[JsonProperty("entries")]
public List<string> ReadEntries { get; set; }
[JsonProperty("unread")]
public List<string> UnreadEntries { get; set; }
}
public class FeedlyReadOperationsFeed
{
[JsonProperty("asOf")]
public DateTime? ReadAt { get; set; }
public string Id { get; set; }
}
}
+8
View File
@@ -1,6 +1,7 @@
using FeedlySharp.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace FeedlySharp.Models
{
@@ -35,6 +36,13 @@ namespace FeedlySharp.Models
}
internal class CategoryUnreadCountResponse
{
[JsonProperty("unreadcounts")]
public List<FeedlyCategoryUnreadCount> List { get; set; }
}
public enum FeedlyUserAccountPlan
{
Standard,