Files
WotBlitzStatisticsBlazor/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs
T

127 lines
3.7 KiB
C#
Raw Normal View History

2020-04-14 11:16:51 +02:00
using System.Collections.Generic;
2020-02-15 16:00:42 +03:00
using System.Net.Http;
using System.Threading.Tasks;
2020-05-23 11:43:14 +02:00
using WotBlitzStatisticsPro.Common;
using WotBlitzStatisticsPro.Common.Model;
2020-02-15 16:00:42 +03:00
using WotBlitzStatisticsPro.WgApiClient.Model;
namespace WotBlitzStatisticsPro.WgApiClient
{
2020-05-29 23:03:32 +02:00
public class WargamingApiClient : WagramingApiClientBase,
IWargamingApiClient,
IWargamingDictionariesApiClient
{
2020-02-15 16:00:42 +03:00
public WargamingApiClient(
HttpClient httpClient,
IWargamingApiSettings wargamingApiSettings) : base(httpClient, wargamingApiSettings)
{
}
2020-05-29 23:03:32 +02:00
#region Search methods
public async Task<List<WotAccountListResponse>> FindAccounts(string nickName,
2020-02-15 16:00:42 +03:00
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
2020-04-14 11:16:51 +02:00
return await GetFromBlitzApi<List<WotAccountListResponse>>(
realmType,
language,
"account/list/",
$"search={nickName}").ConfigureAwait(false);
}
2020-05-19 14:22:47 +02:00
public async Task<List<WotClanListResponse>> FindClans(string searchString,
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
return await GetFromBlitzApi<List<WotClanListResponse>>(
realmType,
language,
"clans/list/",
$"search={searchString}").ConfigureAwait(false);
}
2020-05-29 23:03:32 +02:00
#endregion
2020-02-15 16:00:42 +03:00
2020-05-29 23:03:32 +02:00
#region Encyclopedia methods
public async Task<(
WotEncyclopediaInfoResponse,
WotClanMembersDictionaryResponse)> GetStaticDictionariesAsync(
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
var encyclopedia = await GetFromBlitzApi<WotEncyclopediaInfoResponse>(
realmType,
language,
"encyclopedia/info/"
).ConfigureAwait(false);
var clanGlossaryResponse = await GetFromBlitzApi<WotClanMembersDictionaryResponse>(
realmType,
language,
"clans/glossary/");
return (encyclopedia, clanGlossaryResponse);
}
#endregion
public async Task<AccountInfo> GetPlayerAccountInfo(long accountId,
2020-02-15 16:00:42 +03:00
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
var account = await GetFromBlitzApi<Dictionary<string, AccountInfo>>(
realmType,
language,
"account/info/",
2020-02-25 00:46:02 +03:00
$"account_id={accountId}").ConfigureAwait(false);
2020-02-15 16:00:42 +03:00
return account[accountId.ToString()];
}
2020-02-25 00:46:02 +03:00
public async Task<ClanAccountInfo> GetPlayerClanInfo(long accountId,
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
var clanInfo = await GetFromBlitzApi<Dictionary<string, ClanAccountInfo>>(
realmType,
language,
"clans/accountinfo/",
$"account_id={accountId}").ConfigureAwait(false);
if (clanInfo.ContainsKey(accountId.ToString()))
{
return clanInfo[accountId.ToString()];
}
return null;
}
2020-03-06 17:33:40 +01:00
public async Task<ClanInfo> GetClanInfo(
long clanId,
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
var clanInfo = await GetFromBlitzApi<Dictionary<string, ClanInfo>>(
realmType,
language,
"clans/info/",
$"clan_id={clanId}").ConfigureAwait(false);
if (clanInfo.ContainsKey(clanId.ToString()))
{
return clanInfo[clanId.ToString()];
}
return null;
}
2020-05-29 23:03:32 +02:00
// https://api.wotblitz.ru/wotb/encyclopedia/achievements/?application_id=adc1387489cf9fc8d9a1d85dbd27763d
2020-03-19 22:00:47 +01:00
2020-05-29 23:03:32 +02:00
}
2020-02-15 16:00:42 +03:00
}