From 00b44e917e19eae7377f43c3ac683bfdaa484357 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 2 Jul 2018 15:56:57 +0200 Subject: [PATCH 1/6] basic implementation of trending articles & topics --- .../PocketSharp.UWP.nuget.props | 20 ++++---- .../PocketSharp.UWP.nuget.targets | 14 +++--- .../PocketSharp.UWP/project.lock.json | 9 +--- PocketSharp.Tests/MiscTests.cs | 5 +- PocketSharp.Tests/TrendingTests.cs | 29 ++++++++++++ PocketSharp/Components/Trending.cs | 47 +++++++++++++++++++ PocketSharp/IPocketClient.cs | 4 ++ PocketSharp/Models/Parameters/Parameters.cs | 6 ++- PocketSharp/Models/PocketTopic.cs | 39 +++++++++++++++ PocketSharp/Models/Response/Topics.cs | 22 +++++++++ 10 files changed, 166 insertions(+), 29 deletions(-) create mode 100644 PocketSharp.Tests/TrendingTests.cs create mode 100644 PocketSharp/Components/Trending.cs create mode 100644 PocketSharp/Models/PocketTopic.cs create mode 100644 PocketSharp/Models/Response/Topics.cs diff --git a/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.props b/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.props index 71e96f2..5a1c4ae 100644 --- a/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.props +++ b/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.props @@ -5,21 +5,21 @@ NuGet O:\PocketSharp\PocketSharp.Examples\PocketSharp.UWP\project.lock.json $(UserProfile)\.nuget\packages\ - C:\Users\cee\.nuget\packages\;C:\Program Files (x86)\Microsoft SDKs\NuGetPackagesFallback\ + C:\Users\cee\.nuget\packages\ ProjectJson - 4.6.2 + 4.7.0 $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.targets b/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.targets index 4176878..a1d5ce9 100644 --- a/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.targets +++ b/PocketSharp.Examples/PocketSharp.UWP/PocketSharp.UWP.nuget.targets @@ -4,14 +4,14 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - + + + - - - - + + + + \ No newline at end of file diff --git a/PocketSharp.Examples/PocketSharp.UWP/project.lock.json b/PocketSharp.Examples/PocketSharp.UWP/project.lock.json index e4eddfa..3a11d31 100644 --- a/PocketSharp.Examples/PocketSharp.UWP/project.lock.json +++ b/PocketSharp.Examples/PocketSharp.UWP/project.lock.json @@ -6687,8 +6687,7 @@ "UAP,Version=v10.0.16299": [] }, "packageFolders": { - "C:\\Users\\cee\\.nuget\\packages\\": {}, - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackagesFallback\\": {} + "C:\\Users\\cee\\.nuget\\packages\\": {} }, "project": { "restore": { @@ -6699,14 +6698,10 @@ "packagesPath": "C:\\Users\\cee\\.nuget\\packages\\", "outputPath": "O:\\PocketSharp\\PocketSharp.Examples\\PocketSharp.UWP\\obj\\", "projectStyle": "ProjectJson", - "fallbackFolders": [ - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackagesFallback\\" - ], "configFilePaths": [ "O:\\PocketSharp\\.nuget\\NuGet.Config", "C:\\Users\\cee\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.Fallback.config" + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" ], "sources": { "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, diff --git a/PocketSharp.Tests/MiscTests.cs b/PocketSharp.Tests/MiscTests.cs index 60582e7..a0f822c 100644 --- a/PocketSharp.Tests/MiscTests.cs +++ b/PocketSharp.Tests/MiscTests.cs @@ -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++; } diff --git a/PocketSharp.Tests/TrendingTests.cs b/PocketSharp.Tests/TrendingTests.cs new file mode 100644 index 0000000..85b3cb7 --- /dev/null +++ b/PocketSharp.Tests/TrendingTests.cs @@ -0,0 +1,29 @@ +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() + { + string guid = await client.GetGuid(); + var articles = await client.GetTrendingArticles(guid); + + Assert.NotEmpty(articles); + } + + + [Fact] + public async Task AreTrendingTopicsReturned() + { + string guid = await client.GetGuid(); + var topics = await client.GetTrendingTopics(guid); + + Assert.NotEmpty(topics); + } + } +} diff --git a/PocketSharp/Components/Trending.cs b/PocketSharp/Components/Trending.cs new file mode 100644 index 0000000..027a619 --- /dev/null +++ b/PocketSharp/Components/Trending.cs @@ -0,0 +1,47 @@ +using PocketSharp.Models; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace PocketSharp +{ + /// + /// PocketClient + /// + public partial class PocketClient + { + /// + /// Statistics from the user account. + /// + /// The cancellation token. + /// + /// + public async Task> GetTrendingArticles(string guid, string languageCode = "en", int count = 20, CancellationToken cancellationToken = default(CancellationToken)) + { + return (await Request("getGlobalRecs", cancellationToken, new Dictionary() + { + { "guid", guid }, + { "locale_lang", languageCode }, + { "count", count.ToString() }, + { "version", "2" } + }, false)).Items ?? new List(); + } + + + /// + /// Statistics from the user account. + /// + /// The cancellation token. + /// + /// + public async Task> GetTrendingTopics(string guid, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)) + { + return (await Request("getTrendingTopics", cancellationToken, new Dictionary() + { + { "guid", guid }, + { "locale_lang", languageCode }, + { "version", "2" } + }, false)).Items ?? new List(); + } + } +} diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs index feb0b61..1aeec0a 100644 --- a/PocketSharp/IPocketClient.cs +++ b/PocketSharp/IPocketClient.cs @@ -465,6 +465,10 @@ namespace PocketSharp Task GetUsageLimits(CancellationToken cancellationToken = default(CancellationToken)); #endregion + Task> GetTrendingArticles(string guid, string languageCode = "en", int count = 20, CancellationToken cancellationToken = default(CancellationToken)); + + Task> GetTrendingTopics(string guid, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)); + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// diff --git a/PocketSharp/Models/Parameters/Parameters.cs b/PocketSharp/Models/Parameters/Parameters.cs index a8b11b1..c03d547 100644 --- a/PocketSharp/Models/Parameters/Parameters.cs +++ b/PocketSharp/Models/Parameters/Parameters.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.Serialization; @@ -71,7 +71,9 @@ namespace PocketSharp.Models parameterDict.Add(name, value.ToString()); } + parameterDict.Add("version", "2"); + return parameterDict; } } -} \ No newline at end of file +} diff --git a/PocketSharp/Models/PocketTopic.cs b/PocketSharp/Models/PocketTopic.cs new file mode 100644 index 0000000..1c55413 --- /dev/null +++ b/PocketSharp/Models/PocketTopic.cs @@ -0,0 +1,39 @@ +using Newtonsoft.Json; +using System; + +namespace PocketSharp.Models +{ + /// + /// Topic + /// + [JsonObject] + public class PocketTopic + { + /// + /// Gets or sets the category. + /// + /// + /// The topic category. + /// + [JsonProperty("category")] + public string Category { get; set; } + + /// + /// Gets or sets the name. + /// + /// + /// The name of the topic. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Gets or sets the URI. + /// + /// + /// Link to the topic listing on Pocket. + /// + [JsonProperty("url")] + public Uri Uri { get; set; } + } +} diff --git a/PocketSharp/Models/Response/Topics.cs b/PocketSharp/Models/Response/Topics.cs new file mode 100644 index 0000000..bb1fa02 --- /dev/null +++ b/PocketSharp/Models/Response/Topics.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace PocketSharp.Models +{ + /// + /// Topics Response + /// + [JsonObject] + internal class TopicsResponse : ResponseBase + { + /// + /// Gets the topics. + /// + /// + /// The topics. + /// + [JsonProperty("topics")] + public IEnumerable Items { get; set; } + } +} From 7edc82d7260e52e96776fd94dd8b8cbcede4a765 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 2 Jul 2018 16:25:09 +0200 Subject: [PATCH 2/6] complete new requests for trending --- PocketSharp/Components/Trending.cs | 17 +++++++++++++---- PocketSharp/IPocketClient.cs | 24 ++++++++++++++++++++++-- PocketSharp/Models/PocketItem.cs | 11 ++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/PocketSharp/Components/Trending.cs b/PocketSharp/Components/Trending.cs index 027a619..0514b19 100644 --- a/PocketSharp/Components/Trending.cs +++ b/PocketSharp/Components/Trending.cs @@ -11,13 +11,18 @@ namespace PocketSharp public partial class PocketClient { /// - /// Statistics from the user account. + /// Get trending articles on Pocket. + /// Requires an active GUID from GetGuid() and will therefore make two HTTP requests. /// + /// Article count. + /// Two-letter language code for language-specific results. /// The cancellation token. /// /// - public async Task> GetTrendingArticles(string guid, string languageCode = "en", int count = 20, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> GetTrendingArticles(int count = 20, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)) { + string guid = await GetGuid(cancellationToken); + return (await Request("getGlobalRecs", cancellationToken, new Dictionary() { { "guid", guid }, @@ -29,13 +34,17 @@ namespace PocketSharp /// - /// Statistics from the user account. + /// Get trending topics on Pocket. + /// Requires an active GUID from GetGuid() and will therefore make two HTTP requests. /// + /// Two-letter language code for language-specific results. /// The cancellation token. /// /// - public async Task> GetTrendingTopics(string guid, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)) + public async Task> GetTrendingTopics(string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)) { + string guid = await GetGuid(cancellationToken); + return (await Request("getTrendingTopics", cancellationToken, new Dictionary() { { "guid", guid }, diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs index 1aeec0a..c693bcd 100644 --- a/PocketSharp/IPocketClient.cs +++ b/PocketSharp/IPocketClient.cs @@ -465,9 +465,29 @@ namespace PocketSharp Task GetUsageLimits(CancellationToken cancellationToken = default(CancellationToken)); #endregion - Task> GetTrendingArticles(string guid, string languageCode = "en", int count = 20, CancellationToken cancellationToken = default(CancellationToken)); + #region trending methods + /// + /// Get trending articles on Pocket. + /// Requires an active GUID from GetGuid() and will therefore make two HTTP requests. + /// + /// Article count. + /// Two-letter language code for language-specific results. + /// The cancellation token. + /// + /// + Task> GetTrendingArticles(int count = 20, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)); - Task> GetTrendingTopics(string guid, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Get trending topics on Pocket. + /// Requires an active GUID from GetGuid() and will therefore make two HTTP requests. + /// + /// Two-letter language code for language-specific results. + /// The cancellation token. + /// + /// + Task> GetTrendingTopics(string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)); + #endregion /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. diff --git a/PocketSharp/Models/PocketItem.cs b/PocketSharp/Models/PocketItem.cs index ecfc6da..f204c7f 100644 --- a/PocketSharp/Models/PocketItem.cs +++ b/PocketSharp/Models/PocketItem.cs @@ -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; } + /// + /// Gets or sets the published time. + /// + /// + /// The time when the article was published. + /// + [JsonProperty("date_published")] + public DateTime? PublishedTime { get; set; } + /// /// Gets or sets the tags as comma-separated strings. /// From 8248f90b5b97176a8b3fc5117f56b2fae730dc71 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 2 Jul 2018 16:41:18 +0200 Subject: [PATCH 3/6] remove JSON prop from PocketItem and introduce an AfterRequest action with the passed raw response --- PocketSharp/Models/PocketItem.cs | 9 --------- PocketSharp/PocketClient.cs | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/PocketSharp/Models/PocketItem.cs b/PocketSharp/Models/PocketItem.cs index f204c7f..aff44ee 100644 --- a/PocketSharp/Models/PocketItem.cs +++ b/PocketSharp/Models/PocketItem.cs @@ -372,15 +372,6 @@ namespace PocketSharp.Models get { return Images != null && Images.Count() > 0 ? Images.First() : null; } } - /// - /// Gets and sets the JSON the model was deserialized from - /// - /// - /// Model's original JSON representation - /// - [JsonIgnore] - public string Json { get; set; } - /// /// 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. /// diff --git a/PocketSharp/PocketClient.cs b/PocketSharp/PocketClient.cs index a72f75f..6e987fc 100644 --- a/PocketSharp/PocketClient.cs +++ b/PocketSharp/PocketClient.cs @@ -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 /// public Action PreRequest { get; set; } + /// + /// Action which is executed after every request + /// + /// + /// The after request callback. + /// + public Action AfterRequest { get; set; } + /// /// Initializes a new instance of the 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) { From 281034a16d24104831fb02293e1e893ccb945b5f Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Tue, 3 Jul 2018 12:20:16 +0200 Subject: [PATCH 4/6] add article suggestions --- PocketSharp.Tests/GetTests.cs | 43 ++++++++++++++++--------- PocketSharp.Tests/TrendingTests.cs | 8 ++--- PocketSharp/Components/Get.cs | 25 +++++++++++++- PocketSharp/IPocketClient.cs | 11 +++++++ PocketSharp/Utilities/JsonExtensions.cs | 16 +++++++-- 5 files changed, 78 insertions(+), 25 deletions(-) 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); } } From 000c821661b9c58cbfc30cfd5888ae1df339df7c Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Thu, 12 Jul 2018 11:30:20 +0200 Subject: [PATCH 5/6] fix json converter bug --- PocketSharp/Components/Get.cs | 3 ++- PocketSharp/Models/Parameters/Parameters.cs | 2 -- PocketSharp/Models/Parameters/RetrieveParameters.cs | 11 ++++++++++- PocketSharp/Utilities/JsonExtensions.cs | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/PocketSharp/Components/Get.cs b/PocketSharp/Components/Get.cs index 81844d6..58c3a04 100644 --- a/PocketSharp/Components/Get.cs +++ b/PocketSharp/Components/Get.cs @@ -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("get", cancellationToken, parameters.Convert())).Items ?? new List(); diff --git a/PocketSharp/Models/Parameters/Parameters.cs b/PocketSharp/Models/Parameters/Parameters.cs index c03d547..2f05165 100644 --- a/PocketSharp/Models/Parameters/Parameters.cs +++ b/PocketSharp/Models/Parameters/Parameters.cs @@ -71,8 +71,6 @@ namespace PocketSharp.Models parameterDict.Add(name, value.ToString()); } - parameterDict.Add("version", "2"); - return parameterDict; } } diff --git a/PocketSharp/Models/Parameters/RetrieveParameters.cs b/PocketSharp/Models/Parameters/RetrieveParameters.cs index 8672323..7904cf3 100644 --- a/PocketSharp/Models/Parameters/RetrieveParameters.cs +++ b/PocketSharp/Models/Parameters/RetrieveParameters.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.Serialization; namespace PocketSharp.Models @@ -107,6 +107,15 @@ namespace PocketSharp.Models /// [DataMember(Name = "offset")] public int? Offset { get; set; } + + /// + /// Gets or sets the version. + /// + /// + /// The version. + /// + [DataMember(Name = "version")] + public int? Version { get; set; } } diff --git a/PocketSharp/Utilities/JsonExtensions.cs b/PocketSharp/Utilities/JsonExtensions.cs index 25ac9b7..6481d18 100644 --- a/PocketSharp/Utilities/JsonExtensions.cs +++ b/PocketSharp/Utilities/JsonExtensions.cs @@ -52,10 +52,10 @@ namespace PocketSharp } double value; - if (!Double.TryParse((string)reader.Value, out value)) + if (!Double.TryParse(reader.Value.ToString(), out value)) { DateTime date; - if (DateTime.TryParse((string)reader.Value, out date)) + if (DateTime.TryParse(reader.Value.ToString(), out date)) { return date; } From 6bd23cb4feccaf6d2717f7760726f6aa4a573c39 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Thu, 12 Jul 2018 11:34:07 +0200 Subject: [PATCH 6/6] trending methods do not require a GUID --- PocketSharp/Components/Trending.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/PocketSharp/Components/Trending.cs b/PocketSharp/Components/Trending.cs index 0514b19..a0c9b55 100644 --- a/PocketSharp/Components/Trending.cs +++ b/PocketSharp/Components/Trending.cs @@ -12,7 +12,6 @@ namespace PocketSharp { /// /// Get trending articles on Pocket. - /// Requires an active GUID from GetGuid() and will therefore make two HTTP requests. /// /// Article count. /// Two-letter language code for language-specific results. @@ -21,11 +20,8 @@ namespace PocketSharp /// public async Task> GetTrendingArticles(int count = 20, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)) { - string guid = await GetGuid(cancellationToken); - return (await Request("getGlobalRecs", cancellationToken, new Dictionary() { - { "guid", guid }, { "locale_lang", languageCode }, { "count", count.ToString() }, { "version", "2" } @@ -35,7 +31,6 @@ namespace PocketSharp /// /// Get trending topics on Pocket. - /// Requires an active GUID from GetGuid() and will therefore make two HTTP requests. /// /// Two-letter language code for language-specific results. /// The cancellation token. @@ -43,11 +38,8 @@ namespace PocketSharp /// public async Task> GetTrendingTopics(string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken)) { - string guid = await GetGuid(cancellationToken); - return (await Request("getTrendingTopics", cancellationToken, new Dictionary() { - { "guid", guid }, { "locale_lang", languageCode }, { "version", "2" } }, false)).Items ?? new List();