diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c79bd..bd78d77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,3 @@ -... nohing to see here yet. \ No newline at end of file +### 0.1.0 (2014-11-25) + +* Basic implementation of all endpoints \ No newline at end of file diff --git a/FeedlySharp/Endpoints/Streams.cs b/FeedlySharp/Endpoints/Streams.cs index 330a53e..03ddbd6 100644 --- a/FeedlySharp/Endpoints/Streams.cs +++ b/FeedlySharp/Endpoints/Streams.cs @@ -9,15 +9,81 @@ namespace FeedlySharp { public partial class FeedlyClient { - public async Task GetStreamEntryIds(CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetStreamEntryIds( + string id, + ContentType type, + int? count = null, + FeedSorting sorting = FeedSorting.Newest, + bool? unreadOnly = null, + DateTime? newerThan = null, + string continuation = null, + CancellationToken cancellationToken = default(CancellationToken)) { - throw new NotImplementedException(); + Dictionary parameters = new Dictionary(); + parameters["streamId"] = ValueToResource(type, id); + parameters["ranked"] = sorting.ToString().ToLower(); + if (count.HasValue) + { + parameters["count"] = count.Value.ToString(); + } + if (unreadOnly.HasValue) + { + parameters["unreadOnly"] = unreadOnly.Value.ToString(); + } + 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(continuation)) + { + parameters["continuation"] = continuation; + } + + return await Client.Request(HttpMethod.Get, "v3/streams/ids", parameters, false, (type == ContentType.Category || type == ContentType.Tag), cancellationToken); } - public async Task GetStreamContent(CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetStreamEntries( + string id, + ContentType type, + int? count = null, + FeedSorting sorting = FeedSorting.Newest, + bool? unreadOnly = null, + DateTime? newerThan = null, + string continuation = null, + CancellationToken cancellationToken = default(CancellationToken)) { - throw new NotImplementedException(); + Dictionary parameters = new Dictionary(); + parameters["streamId"] = ValueToResource(type, id); + parameters["ranked"] = sorting.ToString().ToLower(); + if (count.HasValue) + { + parameters["count"] = count.Value.ToString(); + } + if (unreadOnly.HasValue) + { + parameters["unreadOnly"] = unreadOnly.Value.ToString(); + } + 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(continuation)) + { + parameters["continuation"] = continuation; + } + + return await Client.Request(HttpMethod.Get, "v3/streams/contents", parameters, false, (type == ContentType.Category || type == ContentType.Tag), cancellationToken); } } + + public enum FeedSorting + { + Newest, + Oldest + } } diff --git a/FeedlySharp/FeedlyClient.cs b/FeedlySharp/FeedlyClient.cs index 9dfe6ef..4f9bfe0 100644 --- a/FeedlySharp/FeedlyClient.cs +++ b/FeedlySharp/FeedlyClient.cs @@ -56,10 +56,24 @@ namespace FeedlySharp private string ValueToResource(string key, string value, bool encode = true) { - string text = value.StartsWith("user/") ? value : String.Format("user/{0}/{1}/{2}", UserId, key, value); + string text; + if (key == "feed") text = value.StartsWith("feed/") ? value : "feed/" + value; + else text = value.StartsWith("user/") ? value : String.Format("user/{0}/{1}/{2}", UserId, key, value); + return encode ? WebUtility.UrlEncode(text) : text; } + private string ValueToResource(ContentType type, string value, bool encode = true) + { + string key = type == ContentType.Feed ? "feed" : (type == ContentType.Tag ? "tag" : (type == ContentType.SystemCategory ? "systemcategory" : "category")); + if (key == "systemcategory") + { + return encode ? WebUtility.UrlEncode(value) : value; + } + + return ValueToResource(key, value, encode); + } + public void Dispose() { @@ -72,4 +86,12 @@ namespace FeedlySharp Production, Sandbox } + + public enum ContentType + { + Feed, + Category, + SystemCategory, + Tag + } } diff --git a/FeedlySharp/FeedlySharp.csproj b/FeedlySharp/FeedlySharp.csproj index 3e68e4e..e65e482 100644 --- a/FeedlySharp/FeedlySharp.csproj +++ b/FeedlySharp/FeedlySharp.csproj @@ -51,6 +51,8 @@ + + diff --git a/FeedlySharp/Models/FeedlyStreamEntriesResponse.cs b/FeedlySharp/Models/FeedlyStreamEntriesResponse.cs new file mode 100644 index 0000000..e03e334 --- /dev/null +++ b/FeedlySharp/Models/FeedlyStreamEntriesResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FeedlySharp.Models +{ + public class FeedlyStreamEntriesResponse + { + public string Continuation { get; set; } + + public List Items { get; set; } + } +} diff --git a/FeedlySharp/Models/FeedlyStreamEntryIdsResponse.cs b/FeedlySharp/Models/FeedlyStreamEntryIdsResponse.cs new file mode 100644 index 0000000..2162bfb --- /dev/null +++ b/FeedlySharp/Models/FeedlyStreamEntryIdsResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace FeedlySharp.Models +{ + public class FeedlyStreamEntryIdsResponse + { + public string Continuation { get; set; } + + public List Ids { get; set; } + } +} diff --git a/README.md b/README.md index 367d4e7..1a48aae 100644 --- a/README.md +++ b/README.md @@ -4,27 +4,10 @@ --- -**This project is work in progress!** +## This project is work in progress! Status: ---- - -## Status - -1. ✔ Authentication / OAuth -2. ✔ Categories endpoint -3. ✔ Profile endpoint -4. ✔ Preferences endpoint -5. ✔ Tags endpoint -6. ✔ Topics endpoint -7. ✔ OPML endpoint -8. ✔ Entries endpoint -9. ✔ Feeds endpoint -10. ✔ Markers endpoint -11. ✔ Mixes endpoint -12. Search endpoint -13. Streams endpoint -14. ✔ Subscriptions endpoint -15. Social endpoint (Dropbox, Evernote, Facebook, Microsoft, Twitter) +1. ✔ Add implementation for all endpoints +2. Write tests ## Supported platforms