Files
WotBlitzStatisticsBlazor/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs
T

171 lines
5.7 KiB
C#
Raw Normal View History

2020-04-14 11:16:51 +02:00
using System.Collections.Generic;
2020-06-06 15:54:23 +02:00
using System.Linq;
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,
2020-09-18 16:07:25 +02:00
IWargamingDictionariesApiClient,
IWargamingTanksApiClient
2020-05-29 23:03:32 +02:00
{
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
2020-12-27 12:39:25 +01:00
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-12-27 12:39:25 +01:00
public async Task<List<WotClanListResponse>?> FindClans(string searchString,
2020-05-19 14:22:47 +02:00
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<(
2020-12-27 12:39:25 +01:00
WotEncyclopediaInfoResponse?,
WotClanMembersDictionaryResponse?)> GetStaticDictionariesAsync(
2020-05-29 23:03:32 +02:00
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);
}
2020-12-27 12:39:25 +01:00
public async Task<List<WotEncyclopediaAchievementsResponse>?> GetAchievementsDictionary(RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En)
2020-06-06 15:54:23 +02:00
{
var response = await GetFromBlitzApi<Dictionary<string, WotEncyclopediaAchievementsResponse>>(
realmType,
language,
"encyclopedia/achievements/").ConfigureAwait(false);
2020-12-27 12:39:25 +01:00
return response?.Values.ToList();
2020-06-06 15:54:23 +02:00
}
2020-05-29 23:03:32 +02:00
2020-12-27 12:39:25 +01:00
public async Task<List<WotEncyclopediaVehiclesResponse>?> GetVehicles(RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En)
2020-06-07 14:39:03 +02:00
{
var response = await GetFromBlitzApi<Dictionary<string, WotEncyclopediaVehiclesResponse>>(
realmType,
language,
"encyclopedia/vehicles/").ConfigureAwait(false);
2020-12-27 12:39:25 +01:00
return response?.Values.ToList();
2020-06-07 14:39:03 +02:00
}
2020-05-29 23:03:32 +02:00
#endregion
public async Task<WotAccountInfo?> GetPlayerAccountInfo(
long accountId,
2020-02-15 16:00:42 +03:00
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En,
string? authenticationToken = null)
2020-02-15 16:00:42 +03:00
{
var account = authenticationToken == null
? await GetFromBlitzApi<Dictionary<string, WotAccountInfo>>(
realmType,
language,
"account/info/",
$"account_id={accountId}").ConfigureAwait(false)
: await GetFromBlitzApi<Dictionary<string, WotAccountInfo>>(
realmType,
language,
"account/info/",
$"account_id={accountId}",
$"access_token={authenticationToken}").ConfigureAwait(false);
2020-12-27 12:39:25 +01:00
return account?[accountId.ToString()];
2020-02-15 16:00:42 +03:00
}
2020-02-25 00:46:02 +03:00
2020-12-27 12:39:25 +01:00
public async Task<ClanAccountInfo?> GetPlayerClanInfo(long accountId,
2020-02-25 00:46:02 +03:00
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
var clanInfo = await GetFromBlitzApi<Dictionary<string, ClanAccountInfo>>(
realmType,
language,
"clans/accountinfo/",
$"account_id={accountId}").ConfigureAwait(false);
2020-12-27 12:39:25 +01:00
if (clanInfo != null && clanInfo.ContainsKey(accountId.ToString()))
2020-02-25 00:46:02 +03:00
{
return clanInfo[accountId.ToString()];
}
return null;
}
2020-03-06 17:33:40 +01:00
2020-12-27 12:39:25 +01:00
public async Task<ClanInfo?> GetClanInfo(
2020-03-06 17:33:40 +01:00
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);
2020-12-27 12:39:25 +01:00
if (clanInfo != null && clanInfo.ContainsKey(clanId.ToString()))
2020-03-06 17:33:40 +01:00
{
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-09-18 16:07:25 +02:00
#region Tanks methods
2020-05-29 23:03:32 +02:00
2020-12-27 12:39:25 +01:00
public async Task<List<WotAccountTanksStatistics>?> GetPlayerAccountTanksInfo(
2020-09-18 16:07:25 +02:00
long accountId,
RealmType realmType = RealmType.Ru,
RequestLanguage language = RequestLanguage.En)
{
var tanks = await GetFromBlitzApi<Dictionary<string, List<WotAccountTanksStatistics>>>(
realmType,
language,
"tanks/stats/",
$"account_id={accountId}").ConfigureAwait(false);
2020-12-27 12:39:25 +01:00
return tanks?[accountId.ToString()] ?? new List<WotAccountTanksStatistics>();
2020-09-18 16:07:25 +02:00
}
2020-05-29 23:03:32 +02:00
2020-09-18 16:07:25 +02:00
#endregion
2020-05-29 23:03:32 +02:00
}
2020-02-15 16:00:42 +03:00
}