diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-21 23:48:47 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-21 23:48:47 -0400 |
commit | 1bd59fc1d82d6d6316812a5609f61c4157af78c3 (patch) | |
tree | 0a4fbac436b5d44fc09e009b878523344d60cfc9 /src/StardewModdingAPI.Web | |
parent | 1f32d72099b16a554c4c79f499f678ebd6a904a9 (diff) | |
download | SMAPI-1bd59fc1d82d6d6316812a5609f61c4157af78c3.tar.gz SMAPI-1bd59fc1d82d6d6316812a5609f61c4157af78c3.tar.bz2 SMAPI-1bd59fc1d82d6d6316812a5609f61c4157af78c3.zip |
split input model from Nexus response model (#336)
Diffstat (limited to 'src/StardewModdingAPI.Web')
-rw-r--r-- | src/StardewModdingAPI.Web/Controllers/CheckController.cs | 16 | ||||
-rw-r--r-- | src/StardewModdingAPI.Web/Models/ModSearchModel.cs | 9 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/StardewModdingAPI.Web/Controllers/CheckController.cs b/src/StardewModdingAPI.Web/Controllers/CheckController.cs index 8ab4611b..47b61b2f 100644 --- a/src/StardewModdingAPI.Web/Controllers/CheckController.cs +++ b/src/StardewModdingAPI.Web/Controllers/CheckController.cs @@ -19,7 +19,7 @@ namespace StardewModdingAPI.Web.Controllers /// <summary>Fetch version metadata for the given mods.</summary> /// <param name="mods">The mods for which to fetch update metadata.</param> [HttpPost] - public async Task<string> Post([FromBody] NexusResponseModel[] mods) + public async Task<string> Post([FromBody] ModSearchModel[] mods) { using (var client = new HttpClient()) { @@ -28,10 +28,13 @@ namespace StardewModdingAPI.Web.Controllers foreach (var mod in mods) { + if (!mod.NexusID.HasValue) + continue; + try { // create request with HttpRequestMessage - var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.ID}")); + var request = new HttpRequestMessage(HttpMethod.Get, new Uri($"http://www.nexusmods.com/stardewvalley/mods/{mod.NexusID}")); // add the Nexus Client useragent to get JSON response from the site request.Headers.UserAgent.ParseAdd("Nexus Client v0.63.15"); @@ -42,7 +45,7 @@ namespace StardewModdingAPI.Web.Controllers response.EnsureSuccessStatusCode(); // get the JSON string of the response - var stringResponse = await response.Content.ReadAsStringAsync(); + string stringResponse = await response.Content.ReadAsStringAsync(); // create the mod data from the JSON string var modData = JsonConvert.DeserializeObject<NexusResponseModel>(stringResponse); @@ -50,12 +53,9 @@ namespace StardewModdingAPI.Web.Controllers // add to the list of mods modList.Add(modData.ModInfo()); } - catch (Exception ex) + catch (Exception) { - var modData = mod.ModInfo(); - modData.Valid = false; - - modList.Add(modData); + modList.Add(new ModGenericModel { ID = mod.NexusID.Value, Vendor = "Nexus", Valid = false }); } } diff --git a/src/StardewModdingAPI.Web/Models/ModSearchModel.cs b/src/StardewModdingAPI.Web/Models/ModSearchModel.cs new file mode 100644 index 00000000..eb9ac920 --- /dev/null +++ b/src/StardewModdingAPI.Web/Models/ModSearchModel.cs @@ -0,0 +1,9 @@ +namespace StardewModdingAPI.Web.Models +{ + /// <summary>The search criteria for a mod.</summary> + public class ModSearchModel + { + /// <summary>The Nexus Mods ID (if any).</summary> + public int? NexusID { get; set; } + } +} |