diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-05 21:38:24 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-05 21:38:24 -0400 |
commit | 570b19ca7a16dc6af901a8869f178a8196147fb0 (patch) | |
tree | ba8bdf421df0349087415d4a5ac6d0fface49b62 /src/StardewModdingAPI.Toolkit | |
parent | 172862db29db99dd6b7cbe9110c96df5086526d5 (diff) | |
download | SMAPI-570b19ca7a16dc6af901a8869f178a8196147fb0.tar.gz SMAPI-570b19ca7a16dc6af901a8869f178a8196147fb0.tar.bz2 SMAPI-570b19ca7a16dc6af901a8869f178a8196147fb0.zip |
tweak client for reuse in toolkit (#532)
Diffstat (limited to 'src/StardewModdingAPI.Toolkit')
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs index 277fbeeb..d94b0259 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using Newtonsoft.Json; namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi { /// <summary>Provides methods for interacting with the SMAPI web API.</summary> - internal class WebApiClient + public class WebApiClient { /********* ** Properties @@ -26,9 +27,6 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi /// <param name="version">The web API version.</param> public WebApiClient(string baseUrl, ISemanticVersion version) { -#if !SMAPI_FOR_WINDOWS - baseUrl = baseUrl.Replace("https://", "http://"); // workaround for OpenSSL issues with the game's bundled Mono on Linux/Mac -#endif this.BaseUrl = new Uri(baseUrl); this.Version = version; } @@ -43,6 +41,34 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi ); } + /// <summary>Get the latest version for a mod.</summary> + /// <param name="updateKeys">The update keys to search.</param> + public ISemanticVersion GetLatestVersion(string[] updateKeys) + { + if (!updateKeys.Any()) + return null; + + // fetch update results + ModInfoModel[] results = this + .GetModInfo(updateKeys) + .Values + .Where(p => p.Error == null) + .ToArray(); + if (!results.Any()) + return null; + + ISemanticVersion latest = null; + foreach (ModInfoModel result in results) + { + if (!SemanticVersion.TryParse(result.PreviewVersion ?? result.Version, out ISemanticVersion cur)) + continue; + + if (latest == null || cur.IsNewerThan(latest)) + latest = cur; + } + return latest; + } + /********* ** Private methods |