summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Constants.cs16
-rw-r--r--src/SMAPI/Framework/WebApiClient.cs73
-rw-r--r--src/SMAPI/Program.cs4
-rw-r--r--src/SMAPI/SemanticVersion.cs19
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj1
5 files changed, 23 insertions, 90 deletions
diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs
index bdbd5fbb..786c1a39 100644
--- a/src/SMAPI/Constants.cs
+++ b/src/SMAPI/Constants.cs
@@ -38,10 +38,10 @@ namespace StardewModdingAPI
** Public
****/
/// <summary>SMAPI's current semantic version.</summary>
- public static ISemanticVersion ApiVersion { get; } = new SemanticVersion("2.6-beta.15");
+ public static ISemanticVersion ApiVersion { get; }
/// <summary>The minimum supported version of Stardew Valley.</summary>
- public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.3.13");
+ public static ISemanticVersion MinimumGameVersion { get; }
/// <summary>The maximum supported version of Stardew Valley.</summary>
public static ISemanticVersion MaximumGameVersion { get; } = null;
@@ -70,6 +70,9 @@ namespace StardewModdingAPI
/****
** Internal
****/
+ /// <summary>SMAPI's current semantic version as a mod toolkit version.</summary>
+ internal static Toolkit.ISemanticVersion ApiVersionForToolkit { get; }
+
/// <summary>The URL of the SMAPI home page.</summary>
internal const string HomePageUrl = "https://smapi.io";
@@ -104,6 +107,15 @@ namespace StardewModdingAPI
/*********
** Internal methods
*********/
+ /// <summary>Initialise the static values.</summary>
+ static Constants()
+ {
+ Constants.ApiVersionForToolkit = new Toolkit.SemanticVersion("2.6-beta.15");
+ Constants.MinimumGameVersion = new GameVersion("1.3.13");
+
+ Constants.ApiVersion = new SemanticVersion(Constants.ApiVersionForToolkit);
+ }
+
/// <summary>Get metadata for mapping assemblies to the current platform.</summary>
/// <param name="targetPlatform">The target game platform.</param>
internal static PlatformAssemblyMap GetAssemblyMap(Platform targetPlatform)
diff --git a/src/SMAPI/Framework/WebApiClient.cs b/src/SMAPI/Framework/WebApiClient.cs
deleted file mode 100644
index e33b2681..00000000
--- a/src/SMAPI/Framework/WebApiClient.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net;
-using Newtonsoft.Json;
-using StardewModdingAPI.Internal.Models;
-
-namespace StardewModdingAPI.Framework
-{
- /// <summary>Provides methods for interacting with the SMAPI web API.</summary>
- internal class WebApiClient
- {
- /*********
- ** Properties
- *********/
- /// <summary>The base URL for the web API.</summary>
- private readonly Uri BaseUrl;
-
- /// <summary>The API version number.</summary>
- private readonly ISemanticVersion Version;
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="baseUrl">The base URL for the web API.</param>
- /// <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;
- }
-
- /// <summary>Get the latest SMAPI version.</summary>
- /// <param name="modKeys">The mod keys for which to fetch the latest version.</param>
- public IDictionary<string, ModInfoModel> GetModInfo(params string[] modKeys)
- {
- return this.Post<ModSearchModel, Dictionary<string, ModInfoModel>>(
- $"v{this.Version}/mods",
- new ModSearchModel(modKeys, allowInvalidVersions: true)
- );
- }
-
-
- /*********
- ** Private methods
- *********/
- /// <summary>Fetch the response from the backend API.</summary>
- /// <typeparam name="TBody">The body content type.</typeparam>
- /// <typeparam name="TResult">The expected response type.</typeparam>
- /// <param name="url">The request URL, optionally excluding the base URL.</param>
- /// <param name="content">The body content to post.</param>
- private TResult Post<TBody, TResult>(string url, TBody content)
- {
- /***
- ** Note: avoid HttpClient for Mac compatibility.
- ***/
- using (WebClient client = new WebClient())
- {
- Uri fullUrl = new Uri(this.BaseUrl, url);
- string data = JsonConvert.SerializeObject(content);
-
- client.Headers["Content-Type"] = "application/json";
- client.Headers["User-Agent"] = $"SMAPI/{this.Version}";
- string response = client.UploadString(fullUrl, data);
- return JsonConvert.DeserializeObject<TResult>(response);
- }
- }
- }
-}
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index d5f5fdcd..b7b4dfc7 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -26,7 +26,7 @@ using StardewModdingAPI.Framework.ModLoading;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Framework.Serialisation;
using StardewModdingAPI.Internal;
-using StardewModdingAPI.Internal.Models;
+using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
using StardewModdingAPI.Toolkit.Utilities;
using StardewValley;
using Monitor = StardewModdingAPI.Framework.Monitor;
@@ -561,7 +561,7 @@ namespace StardewModdingAPI
new Thread(() =>
{
// create client
- WebApiClient client = new WebApiClient(this.Settings.WebApiBaseUrl, Constants.ApiVersion);
+ WebApiClient client = new WebApiClient(this.Settings.WebApiBaseUrl, Constants.ApiVersionForToolkit);
this.Monitor.Log("Checking for updates...", LogLevel.Trace);
// check SMAPI version
diff --git a/src/SMAPI/SemanticVersion.cs b/src/SMAPI/SemanticVersion.cs
index 3ee3ccf3..c4dd1912 100644
--- a/src/SMAPI/SemanticVersion.cs
+++ b/src/SMAPI/SemanticVersion.cs
@@ -54,6 +54,13 @@ namespace StardewModdingAPI
public SemanticVersion(Version version)
: this(new Toolkit.SemanticVersion(version)) { }
+ /// <summary>Construct an instance.</summary>
+ /// <param name="version">The underlying semantic version implementation.</param>
+ internal SemanticVersion(Toolkit.ISemanticVersion version)
+ {
+ this.Version = version;
+ }
+
/// <summary>Whether this is a pre-release version.</summary>
public bool IsPrerelease()
{
@@ -146,17 +153,5 @@ namespace StardewModdingAPI
parsed = null;
return false;
}
-
-
- /*********
- ** Private methods
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="version">The underlying semantic version implementation.</param>
- private SemanticVersion(Toolkit.ISemanticVersion version)
- {
- this.Version = version;
- }
-
}
}
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index 96b3aa5b..a5ccc62d 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -279,7 +279,6 @@
<Compile Include="ITranslationHelper.cs" />
<Compile Include="LogLevel.cs" />
<Compile Include="Framework\ModRegistry.cs" />
- <Compile Include="Framework\WebApiClient.cs" />
<Compile Include="IMonitor.cs" />
<Compile Include="Events\ChangeType.cs" />
<Compile Include="Events\ItemStackChange.cs" />