diff --git a/src/ClashOfClans.App/Examples/ClansExamples.cs b/src/ClashOfClans.App/Examples/ClansExamples.cs
index 1cc6fe87..f281abf8 100644
--- a/src/ClashOfClans.App/Examples/ClansExamples.cs
+++ b/src/ClashOfClans.App/Examples/ClansExamples.cs
@@ -5,147 +5,146 @@
using System.Linq;
using System.Threading.Tasks;
-namespace ClashOfClans.App.Examples
+namespace ClashOfClans.App.Examples;
+
+public class ClansExamples
{
- public class ClansExamples
+ private readonly string _token;
+ private readonly string _clanTag;
+
+ public ClansExamples(string token, string clanTag)
{
- private readonly string token;
- private readonly string clanTag;
+ _token = token;
+ _clanTag = clanTag;
+ }
- public ClansExamples(string token, string clanTag)
+ ///
+ /// Search all clans by name and/or filtering the results using various criteria.
+ ///
+ public async Task SearchClans()
+ {
+ var query = new QueryClans
{
- this.token = token;
- this.clanTag = clanTag;
- }
+ Name = "Phoenix",
+ MinMembers = 40,
+ MinClanLevel = 5,
+ Limit = 10
+ };
- ///
- /// Search all clans by name and/or filtering the results using various criteria.
- ///
- public async Task SearchClans()
+ var coc = new ClashOfClansClient(_token);
+ var clans = (ClanList)await coc.Clans.SearchClansAsync(query);
+
+ foreach (var clan in clans)
{
- var query = new QueryClans
- {
- Name = "Phoenix",
- MinMembers = 40,
- MinClanLevel = 5,
- Limit = 10
- };
+ Console.WriteLine($"{clan.Tag}/{clan.Name} has {clan.Members} members and is level {clan.ClanLevel} clan");
+ }
+ }
- var coc = new ClashOfClansClient(token);
- var clans = (ClanList)await coc.Clans.SearchClansAsync(query);
+ ///
+ /// Get information about a single clan by clan tag.
+ ///
+ public async Task GetClanInformation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var clan = await coc.Clans.GetClanAsync(_clanTag);
+ Console.WriteLine($"Clan '{clan.Name}' is a level {clan.ClanLevel} clan and has {clan.Members} members");
+ }
- foreach (var clan in clans)
- {
- Console.WriteLine($"{clan.Tag}/{clan.Name} has {clan.Members} members and is level {clan.ClanLevel} clan");
- }
- }
+ ///
+ /// List clan members
+ ///
+ public async Task ListClanMembers()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var clanMembers = (ClanMemberList)await coc.Clans.GetClanMembersAsync(_clanTag);
- ///
- /// Get information about a single clan by clan tag.
- ///
- public async Task GetClanInformation()
+ foreach (var member in clanMembers)
{
- var coc = new ClashOfClansClient(token);
- var clan = await coc.Clans.GetClanAsync(clanTag);
- Console.WriteLine($"Clan '{clan.Name}' is a level {clan.ClanLevel} clan and has {clan.Members} members");
+ Console.WriteLine($"{member.ClanRank}. {member.Name}, {member.Trophies} \uD83C\uDFC6, {member.League.Name}");
}
+ }
+
+ ///
+ /// Retrieve clan's clan war log
+ ///
+ public async Task RetrieveClansClanWarLog()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var clan = await coc.Clans.GetClanAsync(_clanTag);
- ///
- /// List clan members
- ///
- public async Task ListClanMembers()
+ if (clan.IsWarLogPublic)
{
- var coc = new ClashOfClansClient(token);
- var clanMembers = (ClanMemberList)await coc.Clans.GetClanMembersAsync(clanTag);
+ var warLog = await coc.Clans.GetClanWarLogAsync(_clanTag);
- foreach (var member in clanMembers)
+ foreach (var war in warLog.Items.Where(w => w.Result != null))
{
- Console.WriteLine($"{member.ClanRank}. {member.Name}, {member.Trophies} \uD83C\uDFC6, {member.League.Name}");
+ Console.WriteLine($"{war.Result.ToString()![0]}: {Statistics(war.Clan)} vs {Statistics(war.Opponent)}");
}
}
- ///
- /// Retrieve clan's clan war log
- ///
- public async Task RetrieveClansClanWarLog()
- {
- var coc = new ClashOfClansClient(token);
- var clan = await coc.Clans.GetClanAsync(clanTag);
-
- if (clan.IsWarLogPublic)
- {
- var warLog = await coc.Clans.GetClanWarLogAsync(clanTag);
+ static string Statistics(WarClan warClan) => $"{warClan.Name} [{warClan.Stars}\u2605/{warClan.DestructionPercentage}%]";
+ }
- foreach (var war in warLog.Items.Where(w => w.Result != null))
- {
- Console.WriteLine($"{war.Result.ToString()![0]}: {Statistics(war.Clan)} vs {Statistics(war.Opponent)}");
- }
- }
+ ///
+ /// Retrieve information about clan's current clan war
+ ///
+ public async Task RetrieveInformationAboutClansCurrentClanWar()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var clanWar = await coc.Clans.GetCurrentWarAsync(_clanTag);
- static string Statistics(WarClan warClan) => $"{warClan.Name} [{warClan.Stars}\u2605/{warClan.DestructionPercentage}%]";
- }
+ Console.WriteLine($"State: {clanWar.State}, {Statistics(clanWar.Clan)} vs {Statistics(clanWar.Opponent)}");
- ///
- /// Retrieve information about clan's current clan war
- ///
- public async Task RetrieveInformationAboutClansCurrentClanWar()
- {
- var coc = new ClashOfClansClient(token);
- var clanWar = await coc.Clans.GetCurrentWarAsync(clanTag);
+ static string Statistics(WarClan warClan) => $"{warClan.Name} {warClan.Attacks}/{warClan.Stars}\u2605/{warClan.DestructionPercentage:0.00}%";
+ }
- Console.WriteLine($"State: {clanWar.State}, {Statistics(clanWar.Clan)} vs {Statistics(clanWar.Opponent)}");
+ ///
+ /// Retrieve information about clan's current clan war league (CWL) group and wars
+ ///
+ public async Task RetrieveInformationAboutClansCurrentClanWarLeagueGroup()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var clanWarLeagueGroup = await coc.Clans.GetClanWarLeagueGroupAsync(_clanTag);
- static string Statistics(WarClan warClan) => $"{warClan.Name} {warClan.Attacks}/{warClan.Stars}\u2605/{warClan.DestructionPercentage:0.00}%";
- }
+ Console.WriteLine($"Season: {clanWarLeagueGroup.Season}, State: {clanWarLeagueGroup.State}");
- ///
- /// Retrieve information about clan's current clan war league (CWL) group and wars
- ///
- public async Task RetrieveInformationAboutClansCurrentClanWarLeagueGroup()
+ // Retrieve information about individual clan war league (CWL) war
+ for (int i = 0; i < clanWarLeagueGroup.Rounds.Count; i++)
{
- var coc = new ClashOfClansClient(token);
- var clanWarLeagueGroup = await coc.Clans.GetClanWarLeagueGroupAsync(clanTag);
-
- Console.WriteLine($"Season: {clanWarLeagueGroup.Season}, State: {clanWarLeagueGroup.State}");
+ var round = clanWarLeagueGroup.Rounds[i];
+ Console.WriteLine($"Round {i + 1}.");
- // Retrieve information about individual clan war league (CWL) war
- for (int i = 0; i < clanWarLeagueGroup.Rounds.Count; i++)
+ var clanWarLeagueRequests = new List>();
+ foreach (var warTag in round.WarTags.Where(wt => wt != "#0"))
{
- var round = clanWarLeagueGroup.Rounds[i];
- Console.WriteLine($"Round {i + 1}.");
-
- var clanWarLeagueRequests = new List>();
- foreach (var warTag in round.WarTags.Where(wt => wt != "#0"))
- {
- clanWarLeagueRequests.Add(coc.Clans.GetClanWarLeagueWarAsync(warTag));
- }
-
- var clanWarLeagueWars = await Task.WhenAll(clanWarLeagueRequests);
- foreach (var clanWarLeagueWar in clanWarLeagueWars)
- {
- Console.WriteLine($" {clanWarLeagueWar.StartTime.ToLocalTime()}: {Statistics(clanWarLeagueWar.Clan)} vs {Statistics(clanWarLeagueWar.Opponent)}");
- }
+ clanWarLeagueRequests.Add(coc.Clans.GetClanWarLeagueWarAsync(warTag));
}
- static string Statistics(ClanWarLeagueWarClan clan) => $"{clan.Name} [{clan.Stars}\u2605/{clan.DestructionPercentage:0.00}%/{clan.Attacks}]";
+ var clanWarLeagueWars = await Task.WhenAll(clanWarLeagueRequests);
+ foreach (var clanWarLeagueWar in clanWarLeagueWars)
+ {
+ Console.WriteLine($" {clanWarLeagueWar.StartTime.ToLocalTime()}: {Statistics(clanWarLeagueWar.Clan)} vs {Statistics(clanWarLeagueWar.Opponent)}");
+ }
}
- ///
- /// Retrieve clan's capital raid seasons
- ///
- public async Task RetrieveClansCapitalRaidSeasons()
+ static string Statistics(ClanWarLeagueWarClan clan) => $"{clan.Name} [{clan.Stars}\u2605/{clan.DestructionPercentage:0.00}%/{clan.Attacks}]";
+ }
+
+ ///
+ /// Retrieve clan's capital raid seasons
+ ///
+ public async Task RetrieveClansCapitalRaidSeasons()
+ {
+ var query = new Query
{
- var query = new Query
- {
- Limit = 1
- };
- var coc = new ClashOfClansClient(token);
- var capitalRaidSeasons = (ClanCapitalRaidSeasons)await coc.Clans.GetCapitalRaidSeasonsAsync(clanTag, query);
+ Limit = 1
+ };
+ var coc = new ClashOfClansClient(_token);
+ var capitalRaidSeasons = (ClanCapitalRaidSeasons)await coc.Clans.GetCapitalRaidSeasonsAsync(_clanTag, query);
- if (capitalRaidSeasons.SingleOrDefault() is ClanCapitalRaidSeason crs)
- {
- Console.WriteLine($"CapitalTotalLoot {crs.CapitalTotalLoot}, TotalAttacks {crs.TotalAttacks}");
- }
+ if (capitalRaidSeasons.SingleOrDefault() is ClanCapitalRaidSeason crs)
+ {
+ Console.WriteLine($"CapitalTotalLoot {crs.CapitalTotalLoot}, TotalAttacks {crs.TotalAttacks}");
}
}
}
diff --git a/src/ClashOfClans.App/Examples/GoldPassExamples.cs b/src/ClashOfClans.App/Examples/GoldPassExamples.cs
index 3db8bef0..2a737d8a 100644
--- a/src/ClashOfClans.App/Examples/GoldPassExamples.cs
+++ b/src/ClashOfClans.App/Examples/GoldPassExamples.cs
@@ -1,27 +1,26 @@
using System;
using System.Threading.Tasks;
-namespace ClashOfClans.App.Examples
+namespace ClashOfClans.App.Examples;
+
+public class GoldPassExamples
{
- public class GoldPassExamples
- {
- private readonly string token;
+ private readonly string _token;
- public GoldPassExamples(string token)
- {
- this.token = token;
- }
+ public GoldPassExamples(string token)
+ {
+ _token = token;
+ }
- ///
- /// Get information about the current gold pass season.
- ///
- public async Task GetCurrentGoldPassSeason()
- {
- var coc = new ClashOfClansClient(token);
- var currentGoldPassSeason = await coc.GoldPass.GetCurrentGoldPassSeasonAsync();
+ ///
+ /// Get information about the current gold pass season.
+ ///
+ public async Task GetCurrentGoldPassSeason()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var currentGoldPassSeason = await coc.GoldPass.GetCurrentGoldPassSeasonAsync();
- Console.WriteLine($"Current GoldPass season started '{currentGoldPassSeason.StartTime.ToLocalTime()}'" +
- $" and ends '{currentGoldPassSeason.EndTime.ToLocalTime()}'");
- }
+ Console.WriteLine($"Current GoldPass season started '{currentGoldPassSeason.StartTime.ToLocalTime()}'" +
+ $" and ends '{currentGoldPassSeason.EndTime.ToLocalTime()}'");
}
}
diff --git a/src/ClashOfClans.App/Examples/LabelsExamples.cs b/src/ClashOfClans.App/Examples/LabelsExamples.cs
index 2b07119c..377f0371 100644
--- a/src/ClashOfClans.App/Examples/LabelsExamples.cs
+++ b/src/ClashOfClans.App/Examples/LabelsExamples.cs
@@ -2,43 +2,42 @@
using System;
using System.Threading.Tasks;
-namespace ClashOfClans.App.Examples
+namespace ClashOfClans.App.Examples;
+
+public class LabelsExamples
{
- public class LabelsExamples
+ private readonly string _token;
+
+ public LabelsExamples(string token)
{
- private readonly string token;
+ _token = token;
+ }
- public LabelsExamples(string token)
- {
- this.token = token;
- }
+ ///
+ /// List clan labels
+ ///
+ public async Task ListClanLabels()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var labels = (LabelList)await coc.Labels.GetClanLabelsAsync();
- ///
- /// List clan labels
- ///
- public async Task ListClanLabels()
+ foreach (var label in labels)
{
- var coc = new ClashOfClansClient(token);
- var labels = (LabelList)await coc.Labels.GetClanLabelsAsync();
-
- foreach (var label in labels)
- {
- Console.WriteLine($"Id: {label.Id}, Name: {label.Name}");
- }
+ Console.WriteLine($"Id: {label.Id}, Name: {label.Name}");
}
+ }
- ///
- /// List player labels
- ///
- public async Task ListPlayerLabels()
- {
- var coc = new ClashOfClansClient(token);
- var labels = (LabelList)await coc.Labels.GetPlayerLabelsAsync();
+ ///
+ /// List player labels
+ ///
+ public async Task ListPlayerLabels()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var labels = (LabelList)await coc.Labels.GetPlayerLabelsAsync();
- foreach (var label in labels)
- {
- Console.WriteLine($"Id: {label.Id}, Name: {label.Name}");
- }
+ foreach (var label in labels)
+ {
+ Console.WriteLine($"Id: {label.Id}, Name: {label.Name}");
}
}
}
diff --git a/src/ClashOfClans.App/Examples/LeaguesExamples.cs b/src/ClashOfClans.App/Examples/LeaguesExamples.cs
index f8f8c7ce..a97a44d5 100644
--- a/src/ClashOfClans.App/Examples/LeaguesExamples.cs
+++ b/src/ClashOfClans.App/Examples/LeaguesExamples.cs
@@ -4,168 +4,167 @@
using System.Linq;
using System.Threading.Tasks;
-namespace ClashOfClans.App.Examples
+namespace ClashOfClans.App.Examples;
+
+public class LeaguesExamples
{
- public class LeaguesExamples
+ private readonly string _token;
+
+ public LeaguesExamples(string token)
+ {
+ _token = token;
+ }
+
+ ///
+ /// List leagues
+ ///
+ public async Task ListLeagues()
{
- private readonly string token;
+ var coc = new ClashOfClansClient(_token);
+ var leagues = (LeagueList)await coc.Leagues.GetLeaguesAsync();
+
+ Console.WriteLine($"Total amount of leagues: {leagues.Count}");
- public LeaguesExamples(string token)
+ foreach (var league in leagues)
{
- this.token = token;
+ Console.WriteLine($"Id: {league.Id}, Name: {league.Name}");
}
+ }
- ///
- /// List leagues
- ///
- public async Task ListLeagues()
- {
- var coc = new ClashOfClansClient(token);
- var leagues = (LeagueList)await coc.Leagues.GetLeaguesAsync();
+ ///
+ /// Get league information
+ ///
+ public async Task GetLeagueInformation()
+ {
+ var leagueId = 29000022; // Legend League identifier
+ var coc = new ClashOfClansClient(_token);
+ var league = await coc.Leagues.GetLeagueAsync(leagueId);
- Console.WriteLine($"Total amount of leagues: {leagues.Count}");
+ Console.WriteLine($"Id: {league.Id} = {league.Name}");
+ }
- foreach (var league in leagues)
- {
- Console.WriteLine($"Id: {league.Id}, Name: {league.Name}");
- }
- }
+ ///
+ /// Get league seasons. Note that league season information is available only for Legend League.
+ ///
+ public async Task GetLeagueSeasons()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var leagues = (LeagueList)await coc.Leagues.GetLeaguesAsync();
+ var legendLeague = leagues["Legend League"];
+ var leagueSeasons = (LeagueSeasonList)await coc.Leagues.GetLeagueSeasonsAsync(legendLeague!.Id);
- ///
- /// Get league information
- ///
- public async Task GetLeagueInformation()
- {
- var leagueId = 29000022; // Legend League identifier
- var coc = new ClashOfClansClient(token);
- var league = await coc.Leagues.GetLeagueAsync(leagueId);
+ Console.WriteLine($"Total amount of '{legendLeague.Name}' seasons: {leagueSeasons.Count}");
- Console.WriteLine($"Id: {league.Id} = {league.Name}");
+ foreach (var season in leagueSeasons)
+ {
+ Console.WriteLine($"{season.Id}");
}
+ }
- ///
- /// Get league seasons. Note that league season information is available only for Legend League.
- ///
- public async Task GetLeagueSeasons()
+ ///
+ /// Get league season rankings. Note that league season information is available only for Legend League.
+ ///
+ public async Task GetLeagueSeasonRankings()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var leagues = (LeagueList)await coc.Leagues.GetLeaguesAsync();
+ var legendLeague = leagues["Legend League"];
+ var leagueSeasons = (LeagueSeasonList)await coc.Leagues.GetLeagueSeasonsAsync(legendLeague!.Id);
+ var lastSeason = leagueSeasons.Last();
+ var query = new Query
{
- var coc = new ClashOfClansClient(token);
- var leagues = (LeagueList)await coc.Leagues.GetLeaguesAsync();
- var legendLeague = leagues["Legend League"];
- var leagueSeasons = (LeagueSeasonList)await coc.Leagues.GetLeagueSeasonsAsync(legendLeague!.Id);
+ Limit = 100
+ };
- Console.WriteLine($"Total amount of '{legendLeague.Name}' seasons: {leagueSeasons.Count}");
+ var playerRankings = (PlayerRankingList)await coc.Leagues.GetLeagueSeasonRankingsAsync(legendLeague.Id, lastSeason.Id, query);
- foreach (var season in leagueSeasons)
- {
- Console.WriteLine($"{season.Id}");
- }
- }
-
- ///
- /// Get league season rankings. Note that league season information is available only for Legend League.
- ///
- public async Task GetLeagueSeasonRankings()
+ foreach (var player in playerRankings)
{
- var coc = new ClashOfClansClient(token);
- var leagues = (LeagueList)await coc.Leagues.GetLeaguesAsync();
- var legendLeague = leagues["Legend League"];
- var leagueSeasons = (LeagueSeasonList)await coc.Leagues.GetLeagueSeasonsAsync(legendLeague!.Id);
- var lastSeason = leagueSeasons.Last();
- var query = new Query
- {
- Limit = 100
- };
-
- var playerRankings = (PlayerRankingList)await coc.Leagues.GetLeagueSeasonRankingsAsync(legendLeague.Id, lastSeason.Id, query);
-
- foreach (var player in playerRankings)
- {
- Console.WriteLine($"{player.Rank}. {player.Name}, {player.Trophies} \uD83C\uDFC6, attacks won {player.AttackWins}, defenses won {player.DefenseWins}");
- }
+ Console.WriteLine($"{player.Rank}. {player.Name}, {player.Trophies} \uD83C\uDFC6, attacks won {player.AttackWins}, defenses won {player.DefenseWins}");
}
+ }
- ///
- /// List war leagues
- ///
- public async Task ListWarLeagues()
- {
- var coc = new ClashOfClansClient(token);
- var warLeagues = (WarLeagueList)await coc.Leagues.GetWarLeaguesAsync();
+ ///
+ /// List war leagues
+ ///
+ public async Task ListWarLeagues()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var warLeagues = (WarLeagueList)await coc.Leagues.GetWarLeaguesAsync();
- Console.WriteLine($"Total amount of war leagues: {warLeagues.Count}");
+ Console.WriteLine($"Total amount of war leagues: {warLeagues.Count}");
- foreach (var warLeague in warLeagues)
- {
- Console.WriteLine($"Id: {warLeague.Id}, Name: {warLeague.Name}");
- }
+ foreach (var warLeague in warLeagues)
+ {
+ Console.WriteLine($"Id: {warLeague.Id}, Name: {warLeague.Name}");
}
+ }
- ///
- /// Get war league information
- ///
- public async Task GetWarLeagueInformation()
- {
- var warLeagueId = 48000000; // Unranked
- var coc = new ClashOfClansClient(token);
- var warLeague = await coc.Leagues.GetWarLeagueAsync(warLeagueId);
+ ///
+ /// Get war league information
+ ///
+ public async Task GetWarLeagueInformation()
+ {
+ var warLeagueId = 48000000; // Unranked
+ var coc = new ClashOfClansClient(_token);
+ var warLeague = await coc.Leagues.GetWarLeagueAsync(warLeagueId);
- Console.WriteLine($"Id: {warLeague.Id} = {warLeague.Name}");
- }
+ Console.WriteLine($"Id: {warLeague.Id} = {warLeague.Name}");
+ }
- ///
- /// List capital leagues
- ///
- public async Task ListCapitalLeagues()
- {
- var coc = new ClashOfClansClient(token);
- var capitalLeagues = (CapitalLeagueList)await coc.Leagues.GetCapitalLeaguesAsync();
+ ///
+ /// List capital leagues
+ ///
+ public async Task ListCapitalLeagues()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var capitalLeagues = (CapitalLeagueList)await coc.Leagues.GetCapitalLeaguesAsync();
- Console.WriteLine($"Total amount of capital leagues: {capitalLeagues.Count}");
+ Console.WriteLine($"Total amount of capital leagues: {capitalLeagues.Count}");
- foreach (var capitalLeague in capitalLeagues)
- {
- Console.WriteLine($"Id: {capitalLeague.Id}, Name: {capitalLeague.Name}");
- }
+ foreach (var capitalLeague in capitalLeagues)
+ {
+ Console.WriteLine($"Id: {capitalLeague.Id}, Name: {capitalLeague.Name}");
}
+ }
- ///
- /// Get capital league information
- ///
- public async Task GetCapitalLeagueInformation()
- {
- var capitalLeagueId = 85000015; // Master League I
- var coc = new ClashOfClansClient(token);
- var capitalLeague = await coc.Leagues.GetCapitalLeagueAsync(capitalLeagueId);
+ ///
+ /// Get capital league information
+ ///
+ public async Task GetCapitalLeagueInformation()
+ {
+ var capitalLeagueId = 85000015; // Master League I
+ var coc = new ClashOfClansClient(_token);
+ var capitalLeague = await coc.Leagues.GetCapitalLeagueAsync(capitalLeagueId);
- Console.WriteLine($"Id: {capitalLeague.Id} = {capitalLeague.Name}");
- }
+ Console.WriteLine($"Id: {capitalLeague.Id} = {capitalLeague.Name}");
+ }
- ///
- /// Get Builder Base league information
- ///
- public async Task GetBuilderBaseLeagueInformation()
- {
- var builderBaseLeagueId = 44000010; // Stone League V
- var coc = new ClashOfClansClient(token);
- var builderBaseLeague = await coc.Leagues.GetBuilderBaseLeagueAsync(builderBaseLeagueId);
+ ///
+ /// Get Builder Base league information
+ ///
+ public async Task GetBuilderBaseLeagueInformation()
+ {
+ var builderBaseLeagueId = 44000010; // Stone League V
+ var coc = new ClashOfClansClient(_token);
+ var builderBaseLeague = await coc.Leagues.GetBuilderBaseLeagueAsync(builderBaseLeagueId);
- Console.WriteLine($"Id: {builderBaseLeague.Id} = {builderBaseLeague.Name}");
- }
+ Console.WriteLine($"Id: {builderBaseLeague.Id} = {builderBaseLeague.Name}");
+ }
- ///
- /// List Builder Base leagues
- ///
- public async Task ListBuilderBaseLeagues()
- {
- var coc = new ClashOfClansClient(token);
- var builderBaseLeagues = (BuilderBaseLeagueList)await coc.Leagues.GetBuilderBaseLeaguesAsync();
+ ///
+ /// List Builder Base leagues
+ ///
+ public async Task ListBuilderBaseLeagues()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var builderBaseLeagues = (BuilderBaseLeagueList)await coc.Leagues.GetBuilderBaseLeaguesAsync();
- Console.WriteLine($"Total amount of builder base leagues: {builderBaseLeagues.Count}");
+ Console.WriteLine($"Total amount of builder base leagues: {builderBaseLeagues.Count}");
- foreach (var builderBaseLeague in builderBaseLeagues)
- {
- Console.WriteLine($"Id: {builderBaseLeague.Id}, Name: {builderBaseLeague.Name}");
- }
+ foreach (var builderBaseLeague in builderBaseLeagues)
+ {
+ Console.WriteLine($"Id: {builderBaseLeague.Id}, Name: {builderBaseLeague.Name}");
}
}
}
diff --git a/src/ClashOfClans.App/Examples/LocationsExamples.cs b/src/ClashOfClans.App/Examples/LocationsExamples.cs
index 377aae43..97bfa36a 100644
--- a/src/ClashOfClans.App/Examples/LocationsExamples.cs
+++ b/src/ClashOfClans.App/Examples/LocationsExamples.cs
@@ -3,136 +3,135 @@
using System;
using System.Threading.Tasks;
-namespace ClashOfClans.App.Examples
+namespace ClashOfClans.App.Examples;
+
+public class LocationsExamples
{
- class LocationsExamples
+ private readonly string _token;
+
+ public LocationsExamples(string token)
+ {
+ _token = token;
+ }
+
+ ///
+ /// List locations
+ ///
+ public async Task ListLocations()
{
- private readonly string token;
+ var coc = new ClashOfClansClient(_token);
+ var locations = (LocationList)await coc.Locations.GetLocationsAsync();
+
+ Console.WriteLine($"Total amount of locations: {locations.Count}");
- public LocationsExamples(string token)
+ foreach (var location in locations)
{
- this.token = token;
+ Console.WriteLine($"Id: {location.Id}, Name: {location.Name}, IsCountry: {location.IsCountry}, CountryCode: {location.CountryCode}");
}
+ }
- ///
- /// List locations
- ///
- public async Task ListLocations()
- {
- var coc = new ClashOfClansClient(token);
- var locations = (LocationList)await coc.Locations.GetLocationsAsync();
+ ///
+ /// Get information about specific location
+ ///
+ public async Task GetLocationInformation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var locationId = 32000086; // Finland
+ var location = await coc.Locations.GetLocationAsync(locationId);
- Console.WriteLine($"Total amount of locations: {locations.Count}");
+ Console.WriteLine($"Id: {location.Id}, Name: {location.Name}, IsCountry: {location.IsCountry}");
+ }
- foreach (var location in locations)
- {
- Console.WriteLine($"Id: {location.Id}, Name: {location.Name}, IsCountry: {location.IsCountry}, CountryCode: {location.CountryCode}");
- }
- }
+ ///
+ /// Get clan rankings for a specific location
+ ///
+ public async Task GetClanRankingsForASpecificLocation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var locations = (LocationList)await coc.Locations.GetLocationsAsync();
+ var location = locations["Finland"];
- ///
- /// Get information about specific location
- ///
- public async Task GetLocationInformation()
- {
- var coc = new ClashOfClansClient(token);
- var locationId = 32000086; // Finland
- var location = await coc.Locations.GetLocationAsync(locationId);
+ Console.WriteLine($"Clan rankings for {location!.Name}");
- Console.WriteLine($"Id: {location.Id}, Name: {location.Name}, IsCountry: {location.IsCountry}");
- }
+ var clanRankings = (ClanRankingList)await coc.Locations.GetClanRankingAsync(location.Id);
- ///
- /// Get clan rankings for a specific location
- ///
- public async Task GetClanRankingsForASpecificLocation()
+ foreach (var clan in clanRankings)
{
- var coc = new ClashOfClansClient(token);
- var locations = (LocationList)await coc.Locations.GetLocationsAsync();
- var location = locations["Finland"];
-
- Console.WriteLine($"Clan rankings for {location!.Name}");
+ Console.WriteLine($"{clan.Rank}. {clan.Name}, clan level {clan.ClanLevel}");
+ }
+ }
- var clanRankings = (ClanRankingList)await coc.Locations.GetClanRankingAsync(location.Id);
+ ///
+ /// Get player rankings for a specific location
+ ///
+ public async Task GetPlayerRankingsForASpecificLocation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var locations = (LocationList)await coc.Locations.GetLocationsAsync();
+ var location = locations["Finland"];
+ var query = new Query
+ {
+ Limit = 10
+ };
- foreach (var clan in clanRankings)
- {
- Console.WriteLine($"{clan.Rank}. {clan.Name}, clan level {clan.ClanLevel}");
- }
- }
+ var playerRankings = (PlayerRankingList)await coc.Locations.GetPlayerRankingAsync(location!.Id, query);
- ///
- /// Get player rankings for a specific location
- ///
- public async Task GetPlayerRankingsForASpecificLocation()
+ Console.WriteLine($"{location.Name} top {query.Limit} @ {DateTime.Now}");
+ foreach (var player in playerRankings)
{
- var coc = new ClashOfClansClient(token);
- var locations = (LocationList)await coc.Locations.GetLocationsAsync();
- var location = locations["Finland"];
- var query = new Query
- {
- Limit = 10
- };
-
- var playerRankings = (PlayerRankingList)await coc.Locations.GetPlayerRankingAsync(location!.Id, query);
-
- Console.WriteLine($"{location.Name} top {query.Limit} @ {DateTime.Now}");
- foreach (var player in playerRankings)
- {
- Console.WriteLine($"Rank {player.Rank}, {player.Trophies} \uD83C\uDFC6, player {player.Name}");
- }
+ Console.WriteLine($"Rank {player.Rank}, {player.Trophies} \uD83C\uDFC6, player {player.Name}");
}
+ }
- ///
- /// Get clan Builder Base rankings for a specific location
- ///
- public async Task GetClanBuilderBaseRankingsForASpecificLocation()
- {
- var coc = new ClashOfClansClient(token);
- var locations = (LocationList)await coc.Locations.GetLocationsAsync();
- var location = locations["Finland"];
+ ///
+ /// Get clan Builder Base rankings for a specific location
+ ///
+ public async Task GetClanBuilderBaseRankingsForASpecificLocation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var locations = (LocationList)await coc.Locations.GetLocationsAsync();
+ var location = locations["Finland"];
- Console.WriteLine($"Clan builder base rankings for {location!.Name}");
- var clanBuilderBaseRankings = (ClanBuilderBaseRankingList)await coc.Locations.GetClanBuilderBaseRankingAsync(location.Id);
+ Console.WriteLine($"Clan builder base rankings for {location!.Name}");
+ var clanBuilderBaseRankings = (ClanBuilderBaseRankingList)await coc.Locations.GetClanBuilderBaseRankingAsync(location.Id);
- foreach (var clan in clanBuilderBaseRankings)
- {
- Console.WriteLine($"{clan.Rank}. {clan.Name}, clan level {clan.ClanLevel}, {clan.ClanVersusPoints} \uD83C\uDFC6");
- }
+ foreach (var clan in clanBuilderBaseRankings)
+ {
+ Console.WriteLine($"{clan.Rank}. {clan.Name}, clan level {clan.ClanLevel}, {clan.ClanVersusPoints} \uD83C\uDFC6");
}
+ }
- ///
- /// Get player Builder Base rankings for a specific location
- ///
- public async Task GetPlayerBuilderBaseRankingsForASpecificLocation()
- {
- var coc = new ClashOfClansClient(token);
- var locations = (LocationList)await coc.Locations.GetLocationsAsync();
- var location = locations["Finland"];
+ ///
+ /// Get player Builder Base rankings for a specific location
+ ///
+ public async Task GetPlayerBuilderBaseRankingsForASpecificLocation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var locations = (LocationList)await coc.Locations.GetLocationsAsync();
+ var location = locations["Finland"];
- var playerBuilderBaseRankings = (PlayerBuilderBaseRankingList)await coc.Locations.GetPlayerBuilderBaseRankingAsync(location!.Id);
+ var playerBuilderBaseRankings = (PlayerBuilderBaseRankingList)await coc.Locations.GetPlayerBuilderBaseRankingAsync(location!.Id);
- foreach (var player in playerBuilderBaseRankings)
- {
- Console.WriteLine($"Rank {player.Rank}, {player.VersusTrophies} \uD83C\uDFC6, player {player.Name}");
- }
+ foreach (var player in playerBuilderBaseRankings)
+ {
+ Console.WriteLine($"Rank {player.Rank}, {player.VersusTrophies} \uD83C\uDFC6, player {player.Name}");
}
+ }
- ///
- /// Get capital rankings for a specific location
- ///
- public async Task GetCapitalRankingsForASpecificLocation()
- {
- var coc = new ClashOfClansClient(token);
- var locations = (LocationList)await coc.Locations.GetLocationsAsync();
- var location = locations["Finland"];
+ ///
+ /// Get capital rankings for a specific location
+ ///
+ public async Task GetCapitalRankingsForASpecificLocation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var locations = (LocationList)await coc.Locations.GetLocationsAsync();
+ var location = locations["Finland"];
- var clanCapitalRankingList = (ClanCapitalRankingList)await coc.Locations.GetClanCapitalRankingAsync(location!.Id);
+ var clanCapitalRankingList = (ClanCapitalRankingList)await coc.Locations.GetClanCapitalRankingAsync(location!.Id);
- foreach (var clan in clanCapitalRankingList)
- {
- Console.WriteLine($"Rank {clan.Rank}, {clan.ClanCapitalPoints} \uD83C\uDFC6, clan {clan.Name}");
- }
+ foreach (var clan in clanCapitalRankingList)
+ {
+ Console.WriteLine($"Rank {clan.Rank}, {clan.ClanCapitalPoints} \uD83C\uDFC6, clan {clan.Name}");
}
}
}
diff --git a/src/ClashOfClans.App/Examples/PlayersExamples.cs b/src/ClashOfClans.App/Examples/PlayersExamples.cs
index b8888a7e..97980170 100644
--- a/src/ClashOfClans.App/Examples/PlayersExamples.cs
+++ b/src/ClashOfClans.App/Examples/PlayersExamples.cs
@@ -1,46 +1,45 @@
using System;
using System.Threading.Tasks;
-namespace ClashOfClans.App.Examples
+namespace ClashOfClans.App.Examples;
+
+public class PlayersExamples
{
- public class PlayersExamples
+ private readonly string _token;
+ private readonly string _playerTag;
+
+ public PlayersExamples(string token, string playerTag)
{
- private readonly string token;
- private readonly string playerTag;
+ _token = token;
+ _playerTag = playerTag;
+ }
- public PlayersExamples(string token, string playerTag)
- {
- this.token = token;
- this.playerTag = playerTag;
- }
+ ///
+ /// Get information about a single player by player tag.
+ ///
+ public async Task GetPlayerInformation()
+ {
+ var coc = new ClashOfClansClient(_token);
+ var player = await coc.Players.GetPlayerAsync(_playerTag);
+ Console.WriteLine($"'{player.Name}' has {player.Trophies} \uD83C\uDFC6 and {player.WarStars} war stars");
- ///
- /// Get information about a single player by player tag.
- ///
- public async Task GetPlayerInformation()
+ if (player.Clan != null)
{
- var coc = new ClashOfClansClient(token);
- var player = await coc.Players.GetPlayerAsync(playerTag);
- Console.WriteLine($"'{player.Name}' has {player.Trophies} \uD83C\uDFC6 and {player.WarStars} war stars");
-
- if (player.Clan != null)
- {
- var d = player.Donations;
- var dr = player.DonationsReceived;
- Console.WriteLine($"'{player.Name}' is a member of '{player.Clan.Name}' and has a donation ratio {d}/{dr}={(dr != 0 ? (d / (float)dr) : 0):0.00}");
- }
+ var d = player.Donations;
+ var dr = player.DonationsReceived;
+ Console.WriteLine($"'{player.Name}' is a member of '{player.Clan.Name}' and has a donation ratio {d}/{dr}={(dr != 0 ? (d / (float)dr) : 0):0.00}");
}
+ }
- ///
- /// Verify player API token that can be found from the game settings
- ///
- public async Task VerifyPlayerApiToken()
- {
- var playerApiToken = "123456789";
- var coc = new ClashOfClansClient(token);
- var result = await coc.Players.VerifyTokenAsync(playerTag, playerApiToken);
+ ///
+ /// Verify player API token that can be found from the game settings
+ ///
+ public async Task VerifyPlayerApiToken()
+ {
+ var playerApiToken = "123456789";
+ var coc = new ClashOfClansClient(_token);
+ var result = await coc.Players.VerifyTokenAsync(_playerTag, playerApiToken);
- Console.WriteLine($"Player '{result.Tag}' API token '{result.Token}' status '{result.Status}'");
- }
+ Console.WriteLine($"Player '{result.Tag}' API token '{result.Token}' status '{result.Status}'");
}
}
diff --git a/src/ClashOfClans.App/Program.cs b/src/ClashOfClans.App/Program.cs
index f7f0beb1..e3687c75 100644
--- a/src/ClashOfClans.App/Program.cs
+++ b/src/ClashOfClans.App/Program.cs
@@ -2,92 +2,85 @@
using ClashOfClans.Core;
using Microsoft.Extensions.Configuration;
using System;
-using System.Threading.Tasks;
-namespace ClashOfClans.App
+///
+/// The examples each create own ClashOfClansClient instance in order for each example
+/// to be standalone. Normally you would create one instance of ClashOfClansClient and
+/// use it everywhere in your application!
+///
+try
{
- ///
- /// The examples each create own ClashOfClansClient instance in order for each example
- /// to be standalone. Normally you would create one instance of ClashOfClansClient and
- /// use it everywhere in your application!
- ///
- static class Program
- {
- static async Task Main(string[] _)
- {
- AddConfigurationValues(out string clanTag, out string playerTag, out string token);
+ AddConfigurationValues(out string clanTag, out string playerTag, out string token);
- try
- {
- // Access clan specific information
- var clansExamples = new ClansExamples(token, clanTag);
- await clansExamples.RetrieveInformationAboutClansCurrentClanWarLeagueGroup();
- await clansExamples.RetrieveClansClanWarLog();
- await clansExamples.SearchClans();
- await clansExamples.RetrieveInformationAboutClansCurrentClanWar();
- await clansExamples.GetClanInformation();
- await clansExamples.ListClanMembers();
- await clansExamples.RetrieveClansCapitalRaidSeasons();
+ // Access clan specific information
+ var clansExamples = new ClansExamples(token, clanTag);
+ await clansExamples.RetrieveInformationAboutClansCurrentClanWarLeagueGroup();
+ await clansExamples.RetrieveClansClanWarLog();
+ await clansExamples.SearchClans();
+ await clansExamples.RetrieveInformationAboutClansCurrentClanWar();
+ await clansExamples.GetClanInformation();
+ await clansExamples.ListClanMembers();
+ await clansExamples.RetrieveClansCapitalRaidSeasons();
- // Access player specific information
- var playersExamples = new PlayersExamples(token, playerTag);
- await playersExamples.GetPlayerInformation();
- await playersExamples.VerifyPlayerApiToken();
+ // Access player specific information
+ var playersExamples = new PlayersExamples(token, playerTag);
+ await playersExamples.GetPlayerInformation();
+ await playersExamples.VerifyPlayerApiToken();
- // Access league information
- var leaguesExamples = new LeaguesExamples(token);
- await leaguesExamples.ListCapitalLeagues();
- await leaguesExamples.ListLeagues();
- await leaguesExamples.GetLeagueSeasonRankings();
- await leaguesExamples.GetCapitalLeagueInformation();
- await leaguesExamples.GetBuilderBaseLeagueInformation();
- await leaguesExamples.ListBuilderBaseLeagues();
- await leaguesExamples.GetLeagueInformation();
- await leaguesExamples.GetLeagueSeasons();
- await leaguesExamples.GetWarLeagueInformation();
- await leaguesExamples.ListWarLeagues();
+ // Access league information
+ var leaguesExamples = new LeaguesExamples(token);
+ await leaguesExamples.ListCapitalLeagues();
+ await leaguesExamples.ListLeagues();
+ await leaguesExamples.GetLeagueSeasonRankings();
+ await leaguesExamples.GetCapitalLeagueInformation();
+ await leaguesExamples.GetBuilderBaseLeagueInformation();
+ await leaguesExamples.ListBuilderBaseLeagues();
+ await leaguesExamples.GetLeagueInformation();
+ await leaguesExamples.GetLeagueSeasons();
+ await leaguesExamples.GetWarLeagueInformation();
+ await leaguesExamples.ListWarLeagues();
- // Access global and local rankings
- var locationsExamples = new LocationsExamples(token);
- await locationsExamples.GetClanRankingsForASpecificLocation();
- await locationsExamples.GetPlayerRankingsForASpecificLocation();
- await locationsExamples.GetPlayerBuilderBaseRankingsForASpecificLocation();
- await locationsExamples.GetClanBuilderBaseRankingsForASpecificLocation();
- await locationsExamples.ListLocations();
- await locationsExamples.GetCapitalRankingsForASpecificLocation();
- await locationsExamples.GetLocationInformation();
+ // Access global and local rankings
+ var locationsExamples = new LocationsExamples(token);
+ await locationsExamples.GetClanRankingsForASpecificLocation();
+ await locationsExamples.GetPlayerRankingsForASpecificLocation();
+ await locationsExamples.GetPlayerBuilderBaseRankingsForASpecificLocation();
+ await locationsExamples.GetClanBuilderBaseRankingsForASpecificLocation();
+ await locationsExamples.ListLocations();
+ await locationsExamples.GetCapitalRankingsForASpecificLocation();
+ await locationsExamples.GetLocationInformation();
- // Access information about gold pass
- var goldPassExamples = new GoldPassExamples(token);
- await goldPassExamples.GetCurrentGoldPassSeason();
+ // Access information about gold pass
+ var goldPassExamples = new GoldPassExamples(token);
+ await goldPassExamples.GetCurrentGoldPassSeason();
- // Access labels
- var labelsExamples = new LabelsExamples(token);
- await labelsExamples.ListPlayerLabels();
- await labelsExamples.ListClanLabels();
- }
- catch (ClashOfClansException ex)
- {
- Console.WriteLine($"Exception: {ex.Error.Reason}, {ex.Error.Message}");
- Console.WriteLine($"StackTrace:{Environment.NewLine + ex.StackTrace}");
- }
- }
+ // Access labels
+ var labelsExamples = new LabelsExamples(token);
+ await labelsExamples.ListPlayerLabels();
+ await labelsExamples.ListClanLabels();
+}
+catch (ClashOfClansException ex)
+{
+ Console.WriteLine($"Exception: {ex.Error.Reason}, {ex.Error.Message}");
+ Console.WriteLine($"StackTrace:{Environment.NewLine + ex.StackTrace}");
+}
- ///
- /// Reads the configuration values from the JSON file
- ///
- private static void AddConfigurationValues(out string clanTag, out string playerTag, out string token)
- {
- var config = new ConfigurationBuilder()
- .AddJsonFile("appsettings.json")
- .Build();
+///
+/// Reads the configuration values from the JSON file
+///
+static void AddConfigurationValues(out string clanTag, out string playerTag, out string token)
+{
+ var config = new ConfigurationBuilder()
+ .AddJsonFile("appsettings.json")
+ .Build();
- token = GetConfigurationValue(config["api:token"]);
- clanTag = GetConfigurationValue(config["clanTag"]);
- playerTag = GetConfigurationValue(config["playerTag"]);
+ token = GetConfigurationValue(config["api:token"]);
+ clanTag = GetConfigurationValue(config["clanTag"]);
+ playerTag = GetConfigurationValue(config["playerTag"]);
- static string GetConfigurationValue(string? value)
- => value ?? throw new NullReferenceException();
- }
+ static string GetConfigurationValue(string? value)
+ {
+ ArgumentNullException.ThrowIfNull(value);
+ return value;
}
}