using System; using System.Collections.Generic; using System.Linq; using ChaosBot.Lodestone; namespace ChaosBot.Services { public static class LodestoneManager { private static readonly Dictionary EndpointPaths = new Dictionary { {Endpoints.CHARACTER_SEARCH_BY_ID, "character/%s"}, {Endpoints.CHARACTER_SEARCH, "character/search"}, {Endpoints.FREECOMPANY_SEARCH_BY_ID, "freecompany/%s"}, {Endpoints.FREECOMPANY_SEARCH, "freecompany/search"}, }; public static string GetEndpointPaths(Endpoints endpoint, params object[] parameters) { return string.Format(EndpointPaths.GetValueOrDefault(endpoint, string.Empty)!, parameters); } public static Character GetCharacter(string server, string name) { Dictionary parameters = new Dictionary {{"name", name}, {"server", server}}; PaginationWrapper characterWrapper = LodestoneHttpProxy.fetch>(GetEndpointPaths(Endpoints.CHARACTER_SEARCH), parameters); return characterWrapper.Results.First(); } public static Character GetCharacter(long id) { PaginationWrapper characterWrapper = LodestoneHttpProxy.fetch>(GetEndpointPaths(Endpoints.CHARACTER_SEARCH_BY_ID, id.ToString())); return characterWrapper.Results.First(); } public static FreeCompany GetFreeCompany(string server, string name) { Dictionary parameters = new Dictionary {{"name", name}, {"server", server}}; PaginationWrapper freeCompanyWrapper = LodestoneHttpProxy.fetch>(GetEndpointPaths(Endpoints.FREECOMPANY_SEARCH), parameters); return freeCompanyWrapper.Results.First(); } public static FreeCompany GetFreeCompanyById(string id) { PaginationWrapper freeCompanyWrapper = LodestoneHttpProxy.fetch>(GetEndpointPaths(Endpoints.FREECOMPANY_SEARCH_BY_ID, id)); return freeCompanyWrapper.Results.First();} } public enum Endpoints { CHARACTER_SEARCH_BY_ID, CHARACTER_SEARCH, FREECOMPANY_SEARCH_BY_ID, FREECOMPANY_SEARCH } }