chaosbot/ChaosBot/Services/LodestoneManager.cs

64 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using ChaosBot.Lodestone;
namespace ChaosBot.Services
{
public static class LodestoneManager
{
private static readonly Dictionary<Endpoints, string> EndpointPaths = new Dictionary<Endpoints, string>
{
{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<string,string> parameters = new Dictionary<string, string>
{{"name", name}, {"server", server}};
PaginationWrapper<Character> characterWrapper = LodestoneHttpProxy.Fetch<PaginationWrapper<Character>>(GetEndpointPaths(Endpoints.CHARACTER_SEARCH), parameters);
return characterWrapper.Results.First();
}
public static CharacterDetailed GetCharacter(long id)
{
Dictionary<string, string> parameters = new Dictionary<string, string>
{{"data", "CJ"}};
CharacterDetailed character = LodestoneHttpProxy.Fetch<CharacterDetailed>(GetEndpointPaths(Endpoints.CHARACTER_SEARCH_BY_ID, id.ToString()), parameters);
return character;
}
public static FreeCompany GetFreeCompany(string server, string name)
{
Dictionary<string,string> parameters = new Dictionary<string, string>
{{"name", name}, {"server", server}};
PaginationWrapper<FreeCompany> freeCompanyWrapper = LodestoneHttpProxy.Fetch<PaginationWrapper<FreeCompany>>(GetEndpointPaths(Endpoints.FREECOMPANY_SEARCH), parameters);
return freeCompanyWrapper.Results.First();
}
public static FreeCompanyDetailed GetFreeCompanyById(string id) {
Dictionary<string, string> parameters = new Dictionary<string, string>
{{"data", "FCM"}};
FreeCompanyDetailed freeCompany = LodestoneHttpProxy.Fetch<FreeCompanyDetailed>(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
}
}