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/{0}"}, {Endpoints.CHARACTER_SEARCH, "character/search"}, {Endpoints.FREECOMPANY_SEARCH_BY_ID, "freecompany/{0}"}, {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 CharacterDetailed GetCharacter(long id) { Dictionary parameters = new Dictionary {{"data", "CJ"}}; CharacterDetailed character = LodestoneHttpProxy.Fetch(GetEndpointPaths(Endpoints.CHARACTER_SEARCH_BY_ID, id.ToString()), parameters); return character; } 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 FreeCompanyDetailed GetFreeCompanyById(string id) { Dictionary parameters = new Dictionary {{"data", "FCM"}}; FreeCompanyDetailed freeCompany = LodestoneHttpProxy.Fetch(GetEndpointPaths(Endpoints.FREECOMPANY_SEARCH_BY_ID, id), parameters); return freeCompany; } } public enum Endpoints { CHARACTER_SEARCH_BY_ID, CHARACTER_SEARCH, FREECOMPANY_SEARCH_BY_ID, FREECOMPANY_SEARCH } }