summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/WebApiClient.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-10-07 23:20:36 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-10-07 23:20:36 -0400
commitd0dd2f7ba729de6be749d326a2fed78988ba9d7b (patch)
treea22127da6a8900e9f29bbb847bfd5d3347f6b952 /src/StardewModdingAPI/Framework/WebApiClient.cs
parent7889676ea24cafc945899bf25608784e3f5bc9e0 (diff)
parent5928f5f86c4493ddb6b89bce0b7d0fb73a884c09 (diff)
downloadSMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.gz
SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.bz2
SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.zip
Merge branch 'add-mod-build-config' into develop
Diffstat (limited to 'src/StardewModdingAPI/Framework/WebApiClient.cs')
-rw-r--r--src/StardewModdingAPI/Framework/WebApiClient.cs73
1 files changed, 0 insertions, 73 deletions
diff --git a/src/StardewModdingAPI/Framework/WebApiClient.cs b/src/StardewModdingAPI/Framework/WebApiClient.cs
deleted file mode 100644
index f3c7de28..00000000
--- a/src/StardewModdingAPI/Framework/WebApiClient.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net;
-using Newtonsoft.Json;
-using StardewModdingAPI.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)
- );
- }
-
-
- /*********
- ** 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);
- }
- }
- }
-}