using System.Threading.Tasks; using Pathoschild.Http.Client; namespace StardewModdingAPI.Web.Framework.Clients.Nexus { /// An HTTP client for fetching mod metadata from the Nexus Mods API. internal class NexusClient : INexusClient { /********* ** Properties *********/ /// The URL for a Nexus Mods API query excluding the base URL, where {0} is the mod ID. private readonly string ModUrlFormat; /// The underlying HTTP client. private readonly IClient Client; /********* ** Public methods *********/ /// Construct an instance. /// The user agent for the Nexus Mods API client. /// The base URL for the Nexus Mods API. /// The URL for a Nexus Mods API query excluding the , where {0} is the mod ID. public NexusClient(string userAgent, string baseUrl, string modUrlFormat) { this.ModUrlFormat = modUrlFormat; this.Client = new FluentClient(baseUrl).SetUserAgent(userAgent); } /// Get metadata about a mod. /// The Nexus mod ID. /// Returns the mod info if found, else null. public async Task GetModAsync(uint id) { return await this.Client .GetAsync(string.Format(this.ModUrlFormat, id)) .As(); } /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public void Dispose() { this.Client?.Dispose(); } } }