Split Geekbot.net into src/Bot, src/Core, and src/Web
This commit is contained in:
parent
7b6dd2d2f9
commit
fc0af492ad
197 changed files with 542 additions and 498 deletions
12
src/Core/MalClient/IMalClient.cs
Normal file
12
src/Core/MalClient/IMalClient.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Threading.Tasks;
|
||||
using MyAnimeListSharp.Core;
|
||||
|
||||
namespace Geekbot.Core.MalClient
|
||||
{
|
||||
public interface IMalClient
|
||||
{
|
||||
bool IsLoggedIn();
|
||||
Task<AnimeEntry> GetAnime(string query);
|
||||
Task<MangaEntry> GetManga(string query);
|
||||
}
|
||||
}
|
63
src/Core/MalClient/MalClient.cs
Normal file
63
src/Core/MalClient/MalClient.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using System.Threading.Tasks;
|
||||
using Geekbot.Core.GlobalSettings;
|
||||
using Geekbot.Core.Logger;
|
||||
using MyAnimeListSharp.Auth;
|
||||
using MyAnimeListSharp.Core;
|
||||
using MyAnimeListSharp.Facade.Async;
|
||||
|
||||
namespace Geekbot.Core.MalClient
|
||||
{
|
||||
public class MalClient : IMalClient
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private ICredentialContext _credentials;
|
||||
private AnimeSearchMethodsAsync _animeSearch;
|
||||
private MangaSearchMethodsAsync _mangaSearch;
|
||||
|
||||
public MalClient(IGlobalSettings globalSettings, IGeekbotLogger logger)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_logger = logger;
|
||||
ReloadClient();
|
||||
}
|
||||
|
||||
private bool ReloadClient()
|
||||
{
|
||||
var malCredentials = _globalSettings.GetKey("MalCredentials");
|
||||
if (!string.IsNullOrEmpty(malCredentials))
|
||||
{
|
||||
var credSplit = malCredentials.Split('|');
|
||||
_credentials = new CredentialContext()
|
||||
{
|
||||
UserName = credSplit[0],
|
||||
Password = credSplit[1]
|
||||
};
|
||||
_animeSearch = new AnimeSearchMethodsAsync(_credentials);
|
||||
_mangaSearch = new MangaSearchMethodsAsync(_credentials);
|
||||
_logger.Debug(LogSource.Geekbot, "Logged in to MAL");
|
||||
return true;
|
||||
}
|
||||
_logger.Debug(LogSource.Geekbot, "No MAL Credentials Set!");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public bool IsLoggedIn()
|
||||
{
|
||||
return _credentials != null;
|
||||
}
|
||||
|
||||
public async Task<AnimeEntry> GetAnime(string query)
|
||||
{
|
||||
var response = await _animeSearch.SearchDeserializedAsync(query);
|
||||
return response.Entries.Count == 0 ? null : response.Entries[0];
|
||||
}
|
||||
|
||||
public async Task<MangaEntry> GetManga(string query)
|
||||
{
|
||||
var response = await _mangaSearch.SearchDeserializedAsync(query);
|
||||
return response.Entries.Count == 0 ? null : response.Entries[0];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue