diff --git a/PocketSharp.Tests/GetTests.cs b/PocketSharp.Tests/GetTests.cs index fe8b2f9..b3fb0e5 100644 --- a/PocketSharp.Tests/GetTests.cs +++ b/PocketSharp.Tests/GetTests.cs @@ -33,23 +33,34 @@ namespace PocketSharp.Tests Assert.True(item.Uri == itemDuplicate.Uri); } -// [Fact] -// public async Task IsItemJsonPopulated() -// { -// List items = (await client.Get()).ToList(); -// string schemaJson = @"{ -// 'description': 'PocketItem', -// 'type': 'object' -// }"; -// JsonSchema schema = JsonSchema.Parse(schemaJson); -// foreach (var pocketItem in items) -// { -// Assert.True(!string.IsNullOrWhiteSpace(pocketItem.Json)); -// var jObject = JObject.Parse(pocketItem.Json); -// Assert.True(jObject.IsValid(schema)); -// } -// } + [Fact] + public async Task AreSuggestionsRetrieved() + { + var articles = await client.GetTrendingArticles(); + string itemId = articles.First().ID; + + List suggestions = (await client.GetSuggestions(itemId)).ToList(); + Assert.True(suggestions.Count > 0); + } + + // [Fact] + // public async Task IsItemJsonPopulated() + // { + // List items = (await client.Get()).ToList(); + // string schemaJson = @"{ + // 'description': 'PocketItem', + // 'type': 'object' + // }"; + + // JsonSchema schema = JsonSchema.Parse(schemaJson); + // foreach (var pocketItem in items) + // { + // Assert.True(!string.IsNullOrWhiteSpace(pocketItem.Json)); + // var jObject = JObject.Parse(pocketItem.Json); + // Assert.True(jObject.IsValid(schema)); + // } + // } [Fact] public async Task AreFilteredItemsRetrieved() diff --git a/PocketSharp.Tests/TrendingTests.cs b/PocketSharp.Tests/TrendingTests.cs index 85b3cb7..bc9281c 100644 --- a/PocketSharp.Tests/TrendingTests.cs +++ b/PocketSharp.Tests/TrendingTests.cs @@ -10,9 +10,7 @@ namespace PocketSharp.Tests [Fact] public async Task AreTrendingArticlesReturned() { - string guid = await client.GetGuid(); - var articles = await client.GetTrendingArticles(guid); - + var articles = await client.GetTrendingArticles(); Assert.NotEmpty(articles); } @@ -20,9 +18,7 @@ namespace PocketSharp.Tests [Fact] public async Task AreTrendingTopicsReturned() { - string guid = await client.GetGuid(); - var topics = await client.GetTrendingTopics(guid); - + var topics = await client.GetTrendingTopics(); Assert.NotEmpty(topics); } } diff --git a/PocketSharp/Components/Get.cs b/PocketSharp/Components/Get.cs index 4058425..81844d6 100644 --- a/PocketSharp/Components/Get.cs +++ b/PocketSharp/Components/Get.cs @@ -1,4 +1,4 @@ -using PocketSharp.Models; +using PocketSharp.Models; using System; using System.Collections.Generic; using System.Linq; @@ -224,6 +224,29 @@ namespace PocketSharp return await Request("", cancellationToken, parameters, false, true); } + + + /// + /// Get article suggestions for an existing Pocket item. + /// + /// Get suggestions based on this item. + /// Requested item count. + /// Two-letter language code for language-specific results. + /// The cancellation token. + /// + /// + public async Task> GetSuggestions(string itemId, int count = 3, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)) + { + Dictionary parameters = new Dictionary() + { + { "resolved_id", itemId }, + { "version", "1" }, + { "locale_lang", languageCode }, + { "count", count.ToString() } + }; + + return (await Request("getSuggestedItems", cancellationToken, parameters)).Items ?? new List(); + } } diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs index c693bcd..c6d021d 100644 --- a/PocketSharp/IPocketClient.cs +++ b/PocketSharp/IPocketClient.cs @@ -220,6 +220,17 @@ namespace PocketSharp /// /// Task GetArticle(Uri uri, bool includeImages = true, bool includeVideos = true, bool forceRefresh = false, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Get article suggestions for an existing Pocket item. + /// + /// Get suggestions based on this item. + /// Requested item count. + /// Two-letter language code for language-specific results. + /// The cancellation token. + /// + /// + Task> GetSuggestions(string itemId, int count = 3, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)); #endregion #region modify methods diff --git a/PocketSharp/Utilities/JsonExtensions.cs b/PocketSharp/Utilities/JsonExtensions.cs index a9cfbfe..25ac9b7 100644 --- a/PocketSharp/Utilities/JsonExtensions.cs +++ b/PocketSharp/Utilities/JsonExtensions.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using System; @@ -51,7 +51,19 @@ namespace PocketSharp return null; } - return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Convert.ToDouble(reader.Value)); + double value; + if (!Double.TryParse((string)reader.Value, out value)) + { + DateTime date; + if (DateTime.TryParse((string)reader.Value, out date)) + { + return date; + } + + return null; + } + + return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(value); } }