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))); } }
internal static async Task <CachedClan> FromClanResponseAsync(string tag, ClansClientBase clansCacheBase, ClansApi clansApi, CancellationToken?cancellationToken = default) { try { ApiResponse <Clan> apiResponse = await clansApi.FetchClanResponseAsync(tag, cancellationToken).ConfigureAwait(false); return(new CachedClan(tag, apiResponse, await clansCacheBase.ClanTimeToLiveAsync(apiResponse).ConfigureAwait(false))); } catch (Exception e) { return(new CachedClan(tag, await clansCacheBase.ClanTimeToLiveAsync(e).ConfigureAwait(false))); } }