summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Toolkit
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-10-20 20:19:12 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-10-20 20:19:12 -0400
commitde561e52d7785597f1af2c6fd0d712d19ac5f928 (patch)
tree45d542f4d89f86a87d5828a209b85135e053a3ad /src/StardewModdingAPI.Toolkit
parentb729ef012925ca00f2f9b4c6a2091d6cf78b239c (diff)
downloadSMAPI-de561e52d7785597f1af2c6fd0d712d19ac5f928.tar.gz
SMAPI-de561e52d7785597f1af2c6fd0d712d19ac5f928.tar.bz2
SMAPI-de561e52d7785597f1af2c6fd0d712d19ac5f928.zip
fetch game versions from the wiki (#597)
Diffstat (limited to 'src/StardewModdingAPI.Toolkit')
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs (renamed from src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiCompatibilityClient.cs)22
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModList.cs18
-rw-r--r--src/StardewModdingAPI.Toolkit/ModToolkit.cs6
3 files changed, 37 insertions, 9 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiCompatibilityClient.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs
index 20436e66..9be760f8 100644
--- a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiCompatibilityClient.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs
@@ -8,8 +8,8 @@ using Pathoschild.Http.Client;
namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki
{
- /// <summary>An HTTP client for fetching mod metadata from the wiki compatibility list.</summary>
- public class WikiCompatibilityClient : IDisposable
+ /// <summary>An HTTP client for fetching mod metadata from the wiki.</summary>
+ public class WikiClient : IDisposable
{
/*********
** Properties
@@ -24,13 +24,13 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki
/// <summary>Construct an instance.</summary>
/// <param name="userAgent">The user agent for the wiki API.</param>
/// <param name="baseUrl">The base URL for the wiki API.</param>
- public WikiCompatibilityClient(string userAgent, string baseUrl = "https://stardewvalleywiki.com/mediawiki/api.php")
+ public WikiClient(string userAgent, string baseUrl = "https://stardewvalleywiki.com/mediawiki/api.php")
{
this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent);
}
- /// <summary>Fetch mod compatibility entries.</summary>
- public async Task<WikiModEntry[]> FetchAsync()
+ /// <summary>Fetch mods from the compatibility list.</summary>
+ public async Task<WikiModList> FetchModsAsync()
{
// fetch HTML
ResponseModel response = await this.Client
@@ -48,13 +48,23 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki
var doc = new HtmlDocument();
doc.LoadHtml(html);
+ // fetch game versions
+ string stableVersion = doc.DocumentNode.SelectSingleNode("div[@class='game-stable-version']")?.InnerText;
+ string betaVersion = doc.DocumentNode.SelectSingleNode("div[@class='game-beta-version']")?.InnerText;
+
// find mod entries
HtmlNodeCollection modNodes = doc.DocumentNode.SelectNodes("table[@id='mod-list']//tr[@class='mod']");
if (modNodes == null)
throw new InvalidOperationException("Can't parse wiki compatibility list, no mods found.");
// parse
- return this.ParseEntries(modNodes).ToArray();
+ WikiModEntry[] mods = this.ParseEntries(modNodes).ToArray();
+ return new WikiModList
+ {
+ StableVersion = stableVersion,
+ BetaVersion = betaVersion,
+ Mods = mods
+ };
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModList.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModList.cs
new file mode 100644
index 00000000..0d614f28
--- /dev/null
+++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModList.cs
@@ -0,0 +1,18 @@
+namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki
+{
+ /// <summary>Metadata from the wiki's mod compatibility list.</summary>
+ public class WikiModList
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The stable game version.</summary>
+ public string StableVersion { get; set; }
+
+ /// <summary>The beta game version (if any).</summary>
+ public string BetaVersion { get; set; }
+
+ /// <summary>The mods on the wiki.</summary>
+ public WikiModEntry[] Mods { get; set; }
+ }
+}
diff --git a/src/StardewModdingAPI.Toolkit/ModToolkit.cs b/src/StardewModdingAPI.Toolkit/ModToolkit.cs
index 44503b20..c55f6c70 100644
--- a/src/StardewModdingAPI.Toolkit/ModToolkit.cs
+++ b/src/StardewModdingAPI.Toolkit/ModToolkit.cs
@@ -47,10 +47,10 @@ namespace StardewModdingAPI.Toolkit
}
/// <summary>Extract mod metadata from the wiki compatibility list.</summary>
- public async Task<WikiModEntry[]> GetWikiCompatibilityListAsync()
+ public async Task<WikiModList> GetWikiCompatibilityListAsync()
{
- var client = new WikiCompatibilityClient(this.UserAgent);
- return await client.FetchAsync();
+ var client = new WikiClient(this.UserAgent);
+ return await client.FetchModsAsync();
}
/// <summary>Get SMAPI's internal mod database.</summary>