diff --git a/FeedlySharp/Endpoints/Mixes.cs b/FeedlySharp/Endpoints/Mixes.cs new file mode 100644 index 0000000..73c4527 --- /dev/null +++ b/FeedlySharp/Endpoints/Mixes.cs @@ -0,0 +1,51 @@ +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> GetMixes( + string contentId, + int? count = null, + bool unreadOnly = false, + int? limitHours = null, + DateTime? newerThan = null, + bool backfill = true, + CancellationToken cancellationToken = default(CancellationToken)) + { + if (newerThan.HasValue && limitHours.HasValue) + { + throw new ArgumentException("It is not possible to use both newerThan and limitHours"); + } + + Dictionary parameters = new Dictionary(); + parameters["streamId"] = contentId; + parameters["unreadOnly"] = unreadOnly.ToString(); + parameters["backfill"] = backfill.ToString(); + + if (count.HasValue) + { + parameters["count"] = count.Value.ToString(); + } + if (limitHours.HasValue) + { + parameters["hours"] = limitHours.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(); + } + + return (await Client.Request(HttpMethod.Get, "v3/mixes/contents", parameters, false, true, cancellationToken)).List; + } + } +} diff --git a/FeedlySharp/Extensions/UriExtensions.cs b/FeedlySharp/Extensions/UriExtensions.cs index d690504..ef87cff 100644 --- a/FeedlySharp/Extensions/UriExtensions.cs +++ b/FeedlySharp/Extensions/UriExtensions.cs @@ -28,7 +28,7 @@ namespace FeedlySharp.Extensions internal static string ToQueryString(this IDictionary dict) { - if (dict.Count == 0) return string.Empty; + if (dict.Count == 0) return String.Empty; var buffer = new StringBuilder(); int count = 0; @@ -36,9 +36,17 @@ namespace FeedlySharp.Extensions foreach (var key in dict.Keys) { + if (String.IsNullOrWhiteSpace(dict[key])) + { + continue; + } + string value = WebUtility.UrlEncode(dict[key]); - if (count == dict.Count - 1) end = true; + if (count == dict.Count - 1) + { + end = true; + } if (end) buffer.AppendFormat("{0}={1}", key, value); else buffer.AppendFormat("{0}={1}&", key, value); diff --git a/FeedlySharp/FeedlySharp.csproj b/FeedlySharp/FeedlySharp.csproj index 30374c4..3e21678 100644 --- a/FeedlySharp/FeedlySharp.csproj +++ b/FeedlySharp/FeedlySharp.csproj @@ -37,6 +37,7 @@ + diff --git a/FeedlySharp/Models/Responses.cs b/FeedlySharp/Models/Responses.cs index 47ab75a..38f7703 100644 --- a/FeedlySharp/Models/Responses.cs +++ b/FeedlySharp/Models/Responses.cs @@ -42,6 +42,12 @@ namespace FeedlySharp.Models public List List { get; set; } } + internal class MixesResponse + { + [JsonProperty("items")] + public List List { get; set; } + } + public enum FeedlyUserAccountPlan { diff --git a/README.md b/README.md index 8023bc5..367d4e7 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ 7. ✔ OPML endpoint 8. ✔ Entries endpoint 9. ✔ Feeds endpoint -10. Markers endpoint -11. Mixes endpoint +10. ✔ Markers endpoint +11. ✔ Mixes endpoint 12. Search endpoint 13. Streams endpoint 14. ✔ Subscriptions endpoint