internal static async Task <CachedWar> FromClanWarLeagueWarResponseAsync( string warTag, DateTime season, ClansClientBase clansCacheBase, ClansApi clansApi, CancellationToken?cancellationToken = default) { try { ApiResponse <ClanWar> apiResponse = await clansApi.FetchClanWarLeagueWarResponseAsync(warTag, cancellationToken).ConfigureAwait(false); TimeSpan timeToLive = await clansCacheBase.ClanWarTimeToLiveAsync(apiResponse).ConfigureAwait(false); if (!apiResponse.IsSuccessStatusCode || apiResponse.Data?.State == WarState.NotInWar) { return(new CachedWar(warTag, timeToLive)); } CachedWar result = new CachedWar(apiResponse, timeToLive, warTag, season) { Season = season }; return(result); } catch (Exception e) { return(new CachedWar(warTag, await clansCacheBase.ClanWarTimeToLiveAsync(e).ConfigureAwait(false))); } }
public ClanMembersMonitor(PlayersClientBase playersClientBase, ClientConfiguration configuration, ClansApi clansApi, ClansClientBase clansClientBase) : base(configuration) { _playersClientBase = playersClientBase; _clansApi = clansApi; _clansClient = clansClientBase; }
private static ClansApi ClansApiFactory(IServiceProvider arg) { IHttpClientFactory factory = arg.GetRequiredService <IHttpClientFactory>(); HttpClient httpClient = factory.CreateClient("cocApi"); TokenProvider tokenProvider = arg.GetRequiredService <TokenProvider>(); ClansApi clansApi = new ClansApi(httpClient, tokenProvider); return(clansApi); }
public ClansClientBase(ClientConfiguration configuration, ClansApi clansApi) : base(configuration) { _clansApi = clansApi; //_activeWarMonitor = new ActiveWarMonitor(TokenQueue, Configuration, _clansApi, this); _clanWarLogMonitor = new WarLogMonitor(Configuration, _clansApi, this); _clanWarMonitor = new ClanWarMonitor(Configuration, _clansApi, this); _cwlMonitor = new CwlMonitor(Configuration, _clansApi, this); _warMonitor = new WarMonitor(Configuration, _clansApi, this); _clanMonitor = new ClanMonitor(Configuration, _clansApi, this); }
public ClansClient( Cache.ClientConfiguration cacheConfiguration, ClansApi clansApi, PlayersClient playersCache, LocationsApi locationsApi, PlayersApi playersApi) : base(cacheConfiguration, clansApi, playersCache) { _playersCache = playersCache; _locationsApi = locationsApi; _playersApi = playersApi; ClanUpdated += OnClanUpdated; ClanWarAdded += OnClanWarAdded; ClanWarLogUpdated += OnClanWarLogUpdated; ClanWarUpdated += OnClanWarUpdated; Log += OnLog; }
public async Task StartAsync(CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(_settings.Value.Token) || _settings.Value.Token == "put your token here") { throw InvalidToken(); } try { await ClansApi.FetchClanAsync("#929YJPYJ", cancellationToken); } catch (ApiException e) when(e.Message == "Forbidden") { throw InvalidToken(); } }
public ClansClient( IHttpClientFactory httpClientFactory, ILogger <ClansClient> logger, ClansApi clansApi, IServiceScopeFactory scopeFactory, Synchronizer synchronizer, IPerpetualExecution <object>[] backgroundServices, IOptions <CacheOptions> cacheOptions, IOptions <Settings> settings ) : base( logger, clansApi, scopeFactory, synchronizer, backgroundServices, cacheOptions) { _httpClientFactory = httpClientFactory; ClanWarAdded += ClansClient_ClanWarAdded; ClanWarUpdated += ClansClient_ClanWarUpdated; _settings = settings; }
public ClansClientBase(ClientConfiguration configuration, ClansApi clansApi, PlayersClientBase playersClient) : this(configuration, clansApi) { _playersClient = playersClient; _clanMembersMonitor = new ClanMembersMonitor(playersClient, configuration, clansApi, this); }
public WarLogMonitor(ClientConfiguration cacheConfiguration, ClansApi clansApi, ClansClientBase clansClientBase) : base(cacheConfiguration) { _clansApi = clansApi; _clansClient = clansClientBase; }
internal static async Task <CachedClanWarLeagueGroup> FromClanWarLeagueGroupResponseAsync(string tag, ClansClientBase clansCacheBase, ClansApi clansApi, CancellationToken?cancellationToken = default) { try { ApiResponse <ClanWarLeagueGroup> apiResponse = await clansApi.FetchClanWarLeagueGroupResponseAsync(tag, cancellationToken).ConfigureAwait(false); return(new CachedClanWarLeagueGroup(tag, apiResponse, await clansCacheBase.ClanWarLeagueGroupTimeToLiveAsync(apiResponse).ConfigureAwait(false))); } catch (Exception e) { return(new CachedClanWarLeagueGroup(tag, await clansCacheBase.ClanWarLeagueGroupTimeToLiveAsync(e).ConfigureAwait(false))); } }
public ClanMonitor(ClientConfiguration configuration, ClansApi clansApi, ClansClientBase clansClientBase) : base(configuration) { _clansApi = clansApi; _clansClient = clansClientBase; }