add article suggestions
This commit is contained in:
@@ -33,23 +33,34 @@ namespace PocketSharp.Tests
|
|||||||
Assert.True(item.Uri == itemDuplicate.Uri);
|
Assert.True(item.Uri == itemDuplicate.Uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [Fact]
|
|
||||||
// public async Task IsItemJsonPopulated()
|
|
||||||
// {
|
|
||||||
// List<PocketItem> items = (await client.Get()).ToList();
|
|
||||||
// string schemaJson = @"{
|
|
||||||
// 'description': 'PocketItem',
|
|
||||||
// 'type': 'object'
|
|
||||||
// }";
|
|
||||||
|
|
||||||
// JsonSchema schema = JsonSchema.Parse(schemaJson);
|
[Fact]
|
||||||
// foreach (var pocketItem in items)
|
public async Task AreSuggestionsRetrieved()
|
||||||
// {
|
{
|
||||||
// Assert.True(!string.IsNullOrWhiteSpace(pocketItem.Json));
|
var articles = await client.GetTrendingArticles();
|
||||||
// var jObject = JObject.Parse(pocketItem.Json);
|
string itemId = articles.First().ID;
|
||||||
// Assert.True(jObject.IsValid(schema));
|
|
||||||
// }
|
List<PocketItem> suggestions = (await client.GetSuggestions(itemId)).ToList();
|
||||||
// }
|
Assert.True(suggestions.Count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task IsItemJsonPopulated()
|
||||||
|
// {
|
||||||
|
// List<PocketItem> 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]
|
[Fact]
|
||||||
public async Task AreFilteredItemsRetrieved()
|
public async Task AreFilteredItemsRetrieved()
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task AreTrendingArticlesReturned()
|
public async Task AreTrendingArticlesReturned()
|
||||||
{
|
{
|
||||||
string guid = await client.GetGuid();
|
var articles = await client.GetTrendingArticles();
|
||||||
var articles = await client.GetTrendingArticles(guid);
|
|
||||||
|
|
||||||
Assert.NotEmpty(articles);
|
Assert.NotEmpty(articles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,9 +18,7 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task AreTrendingTopicsReturned()
|
public async Task AreTrendingTopicsReturned()
|
||||||
{
|
{
|
||||||
string guid = await client.GetGuid();
|
var topics = await client.GetTrendingTopics();
|
||||||
var topics = await client.GetTrendingTopics(guid);
|
|
||||||
|
|
||||||
Assert.NotEmpty(topics);
|
Assert.NotEmpty(topics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using PocketSharp.Models;
|
using PocketSharp.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -224,6 +224,29 @@ namespace PocketSharp
|
|||||||
|
|
||||||
return await Request<PocketArticle>("", cancellationToken, parameters, false, true);
|
return await Request<PocketArticle>("", cancellationToken, parameters, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get article suggestions for an existing Pocket item.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemId">Get suggestions based on this item.</param>
|
||||||
|
/// <param name="count">Requested item count.</param>
|
||||||
|
/// <param name="languageCode">Two-letter language code for language-specific results.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="PocketException"></exception>
|
||||||
|
public async Task<IEnumerable<PocketItem>> GetSuggestions(string itemId, int count = 3, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken))
|
||||||
|
{
|
||||||
|
Dictionary<string, string> parameters = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "resolved_id", itemId },
|
||||||
|
{ "version", "1" },
|
||||||
|
{ "locale_lang", languageCode },
|
||||||
|
{ "count", count.ToString() }
|
||||||
|
};
|
||||||
|
|
||||||
|
return (await Request<Retrieve>("getSuggestedItems", cancellationToken, parameters)).Items ?? new List<PocketItem>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,17 @@ namespace PocketSharp
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
Task<PocketArticle> GetArticle(Uri uri, bool includeImages = true, bool includeVideos = true, bool forceRefresh = false, CancellationToken cancellationToken = default(CancellationToken));
|
Task<PocketArticle> GetArticle(Uri uri, bool includeImages = true, bool includeVideos = true, bool forceRefresh = false, CancellationToken cancellationToken = default(CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get article suggestions for an existing Pocket item.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemId">Get suggestions based on this item.</param>
|
||||||
|
/// <param name="count">Requested item count.</param>
|
||||||
|
/// <param name="languageCode">Two-letter language code for language-specific results.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="PocketException"></exception>
|
||||||
|
Task<IEnumerable<PocketItem>> GetSuggestions(string itemId, int count = 3, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken));
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region modify methods
|
#region modify methods
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
@@ -51,7 +51,19 @@ namespace PocketSharp
|
|||||||
return null;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user