Merge branch 'master' of https://github.com/ceee/PocketSharp
This commit is contained in:
@@ -33,23 +33,34 @@ namespace PocketSharp.Tests
|
||||
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);
|
||||
// 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<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]
|
||||
public async Task AreFilteredItemsRetrieved()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using PocketSharp.Models;
|
||||
using PocketSharp.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
@@ -10,8 +10,7 @@ namespace PocketSharp.Tests
|
||||
{
|
||||
private int Incrementor = 0;
|
||||
|
||||
public MiscTests()
|
||||
: base()
|
||||
public MiscTests() : base()
|
||||
{
|
||||
client.PreRequest = method => Incrementor++;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using PocketSharp.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace PocketSharp.Tests
|
||||
{
|
||||
public class TrendingTests : TestsBase
|
||||
{
|
||||
[Fact]
|
||||
public async Task AreTrendingArticlesReturned()
|
||||
{
|
||||
var articles = await client.GetTrendingArticles();
|
||||
Assert.NotEmpty(articles);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task AreTrendingTopicsReturned()
|
||||
{
|
||||
var topics = await client.GetTrendingTopics();
|
||||
Assert.NotEmpty(topics);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using PocketSharp.Models;
|
||||
using PocketSharp.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -55,7 +55,8 @@ namespace PocketSharp
|
||||
Domain = domain,
|
||||
Since = since.HasValue ? ((DateTime)since).ToUniversalTime() : since,
|
||||
Count = count,
|
||||
Offset = offset
|
||||
Offset = offset,
|
||||
Version = 2
|
||||
};
|
||||
|
||||
return (await Request<Retrieve>("get", cancellationToken, parameters.Convert())).Items ?? new List<PocketItem>();
|
||||
@@ -224,6 +225,29 @@ namespace PocketSharp
|
||||
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using PocketSharp.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// PocketClient
|
||||
/// </summary>
|
||||
public partial class PocketClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Get trending articles on Pocket.
|
||||
/// </summary>
|
||||
/// <param name="count">Article 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>> GetTrendingArticles(int count = 20, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return (await Request<Retrieve>("getGlobalRecs", cancellationToken, new Dictionary<string, string>()
|
||||
{
|
||||
{ "locale_lang", languageCode },
|
||||
{ "count", count.ToString() },
|
||||
{ "version", "2" }
|
||||
}, false)).Items ?? new List<PocketItem>();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get trending topics on Pocket.
|
||||
/// </summary>
|
||||
/// <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<PocketTopic>> GetTrendingTopics(string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return (await Request<TopicsResponse>("getTrendingTopics", cancellationToken, new Dictionary<string, string>()
|
||||
{
|
||||
{ "locale_lang", languageCode },
|
||||
{ "version", "2" }
|
||||
}, false)).Items ?? new List<PocketTopic>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,6 +220,17 @@ namespace PocketSharp
|
||||
/// <returns></returns>
|
||||
/// <exception cref="PocketException"></exception>
|
||||
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
|
||||
|
||||
#region modify methods
|
||||
@@ -465,6 +476,30 @@ namespace PocketSharp
|
||||
Task<PocketLimits> GetUsageLimits(CancellationToken cancellationToken = default(CancellationToken));
|
||||
#endregion
|
||||
|
||||
#region trending methods
|
||||
/// <summary>
|
||||
/// Get trending articles on Pocket.
|
||||
/// Requires an active GUID from GetGuid() and will therefore make two HTTP requests.
|
||||
/// </summary>
|
||||
/// <param name="count">Article 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>> GetTrendingArticles(int count = 20, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get trending topics on Pocket.
|
||||
/// Requires an active GUID from GetGuid() and will therefore make two HTTP requests.
|
||||
/// </summary>
|
||||
/// <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<PocketTopic>> GetTrendingTopics(string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken));
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
@@ -74,4 +74,4 @@ namespace PocketSharp.Models
|
||||
return parameterDict;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
@@ -107,6 +107,15 @@ namespace PocketSharp.Models
|
||||
/// </value>
|
||||
[DataMember(Name = "offset")]
|
||||
public int? Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the version.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The version.
|
||||
/// </value>
|
||||
[DataMember(Name = "version")]
|
||||
public int? Version { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -299,6 +299,15 @@ namespace PocketSharp.Models
|
||||
[JsonProperty("time_favorited")]
|
||||
public DateTime? FavoriteTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the published time.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The time when the article was published.
|
||||
/// </value>
|
||||
[JsonProperty("date_published")]
|
||||
public DateTime? PublishedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tags as comma-separated strings.
|
||||
/// </summary>
|
||||
@@ -363,15 +372,6 @@ namespace PocketSharp.Models
|
||||
get { return Images != null && Images.Count() > 0 ? Images.First() : null; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets and sets the JSON the model was deserialized from
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// Model's original JSON representation
|
||||
/// </value>
|
||||
[JsonIgnore]
|
||||
public string Json { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Topic
|
||||
/// </summary>
|
||||
[JsonObject]
|
||||
public class PocketTopic
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the category.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The topic category.
|
||||
/// </value>
|
||||
[JsonProperty("category")]
|
||||
public string Category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The name of the topic.
|
||||
/// </value>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the URI.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// Link to the topic listing on Pocket.
|
||||
/// </value>
|
||||
[JsonProperty("url")]
|
||||
public Uri Uri { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Topics Response
|
||||
/// </summary>
|
||||
[JsonObject]
|
||||
internal class TopicsResponse : ResponseBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the topics.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The topics.
|
||||
/// </value>
|
||||
[JsonProperty("topics")]
|
||||
public IEnumerable<PocketTopic> Items { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using PocketSharp.Models;
|
||||
using System;
|
||||
@@ -103,6 +103,14 @@ namespace PocketSharp
|
||||
/// </value>
|
||||
public Action<string> PreRequest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Action which is executed after every request
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The after request callback.
|
||||
/// </value>
|
||||
public Action<string> AfterRequest { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PocketClient" /> class.
|
||||
@@ -233,10 +241,7 @@ namespace PocketSharp
|
||||
request.Content = new FormUrlEncodedContent(parameters);
|
||||
|
||||
// call pre request action
|
||||
if (PreRequest != null)
|
||||
{
|
||||
PreRequest(method);
|
||||
}
|
||||
PreRequest?.Invoke(method);
|
||||
|
||||
// make async request
|
||||
try
|
||||
@@ -280,6 +285,9 @@ namespace PocketSharp
|
||||
}
|
||||
}
|
||||
|
||||
// call after request action
|
||||
AfterRequest?.Invoke(responseString);
|
||||
|
||||
// cache response
|
||||
if (cacheHTTPResponseData)
|
||||
{
|
||||
|
||||
@@ -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(reader.Value.ToString(), out value))
|
||||
{
|
||||
DateTime date;
|
||||
if (DateTime.TryParse(reader.Value.ToString(), 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