Skip to content

Commit

Permalink
Add support for builder base leagues/rankings (#140)
Browse files Browse the repository at this point in the history
* Update NuGet packages

* Update models

* Add APIs for builder base leagues/rankings

* Bump NuGet version to 8.8.0-rc1
  • Loading branch information
tparviainen committed Jun 6, 2023
1 parent 169f690 commit c7169ad
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build/version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Patch: Backwards compatible bug fixes only
# -Suffix (optional): a hyphen followed by a string denoting a pre-release version (rc1, rc2, etc.)

8.7.0
8.8.0-rc1
11 changes: 11 additions & 0 deletions src/ClashOfClans.Models/BuilderBaseLeague.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace ClashOfClans.Models
{
public class BuilderBaseLeague
{
private int? _id;

public int Id { get => _id ?? default; set => _id = value; }

public string Name { get; set; } = default!;
}
}
8 changes: 8 additions & 0 deletions src/ClashOfClans.Models/BuilderBaseLeagueList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace ClashOfClans.Models
{
public class BuilderBaseLeagueList : List<BuilderBaseLeague>
{
}
}
6 changes: 6 additions & 0 deletions src/ClashOfClans.Models/Clan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Clan : Identity
private Type? _type;
private int? _clanLevel;
private int? _clanPoints;
private int? _clanBuilderBasePoints;
private int? _clanVersusPoints;
private int? _clanCapitalPoints;
private int? _requiredTrophies;
Expand All @@ -15,6 +16,7 @@ public class Clan : Identity
private WarFrequency? _warFrequency;
private int? _warWinStreak;
private int? _warWins;
private int? _requiredBuilderBaseTrophies;
private bool? _isWarLogPublic;
private bool? _isFamilyFriendly;
private int? _members;
Expand All @@ -36,6 +38,8 @@ public class Clan : Identity

public int ClanPoints { get => _clanPoints ?? default; set => _clanPoints = value; }

public int ClanBuilderBasePoints { get => _clanBuilderBasePoints ?? default; set => _clanBuilderBasePoints = value; }

public int ClanVersusPoints { get => _clanVersusPoints ?? default; set => _clanVersusPoints = value; }

public int ClanCapitalPoints { get => _clanCapitalPoints ?? default; set => _clanCapitalPoints = value; }
Expand All @@ -62,6 +66,8 @@ public class Clan : Identity
/// </summary>
public int WarWins { get => _warWins ?? default; set => _warWins = value; }

public int RequiredBuilderBaseTrophies { get => _requiredBuilderBaseTrophies ?? default; set => _requiredBuilderBaseTrophies = value; }

public bool IsFamilyFriendly { get => _isFamilyFriendly ?? default; set => _isFamilyFriendly = value; }

public bool IsWarLogPublic { get => _isWarLogPublic ?? default; set => _isWarLogPublic = value; }
Expand Down
28 changes: 28 additions & 0 deletions src/ClashOfClans.Models/ClanBuilderBaseRanking.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace ClashOfClans.Models
{
public class ClanBuilderBaseRanking : Identity
{
private int? _members;
private int? _clanLevel;
private int? _rank;
private int? _previousRank;
private int? _clanBuilderBasePoints;
private int? _clanVersusPoints;

public Location? Location { get; set; }

public int Members { get => _members ?? default; set => _members = value; }

public int ClanLevel { get => _clanLevel ?? default; set => _clanLevel = value; }

public int Rank { get => _rank ?? default; set => _rank = value; }

public int PreviousRank { get => _previousRank ?? default; set => _previousRank = value; }

public int ClanBuilderBasePoints { get => _clanBuilderBasePoints ?? default; set => _clanBuilderBasePoints = value; }

public int ClanVersusPoints { get => _clanVersusPoints ?? default; set => _clanVersusPoints = value; }

public UrlContainer BadgeUrls { get; set; } = default!;
}
}
8 changes: 8 additions & 0 deletions src/ClashOfClans.Models/ClanBuilderBaseRankingList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace ClashOfClans.Models
{
public class ClanBuilderBaseRankingList : List<ClanBuilderBaseRanking>
{
}
}
5 changes: 5 additions & 0 deletions src/ClashOfClans.Models/ClanMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ClanMember : Identity
private Role? _role;
private int? _expLevel;
private int? _trophies;
private int? _builderBaseTrophies;
private int? _versusTrophies;
private int? _clanRank;
private int? _previousClanRank;
Expand All @@ -21,6 +22,8 @@ public class ClanMember : Identity

public int Trophies { get => _trophies ?? default; set => _trophies = value; }

public int BuilderBaseTrophies { get => _builderBaseTrophies ?? default; set => _builderBaseTrophies = value; }

public int VersusTrophies { get => _versusTrophies ?? default; set => _versusTrophies = value; }

public int ClanRank { get => _clanRank ?? default; set => _clanRank = value; }
Expand All @@ -32,5 +35,7 @@ public class ClanMember : Identity
public int DonationsReceived { get => _donationsReceived ?? default; set => _donationsReceived = value; }

public PlayerHouse? PlayerHouse { get; set; }

public BuilderBaseLeague? BuilderBaseLeague { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/ClashOfClans.Models/ClanVersusRanking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ClanVersusRanking : Identity
private int? _rank;
private int? _previousRank;
private int? _clanVersusPoints;
private int? _clanBuilderBasePoints;

public Location Location { get; set; } = default!;

Expand All @@ -23,5 +24,7 @@ public class ClanVersusRanking : Identity
public int PreviousRank { get => _previousRank ?? default; set => _previousRank = value; }

public int ClanVersusPoints { get => _clanVersusPoints ?? default; set => _clanVersusPoints = value; }

public int ClanBuilderBasePoints { get => _clanBuilderBasePoints ?? default; set => _clanBuilderBasePoints = value; }
}
}
8 changes: 8 additions & 0 deletions src/ClashOfClans.Models/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Player : Identity
private int? _versusBattleWins;
private int? _donations;
private int? _donationsReceived;
private int? _builderBaseTrophies;
private int? _bestBuilderBaseTrophies;
private int? _clanCapitalContributions;
private int? _versusBattleWinCount;

Expand Down Expand Up @@ -70,6 +72,10 @@ public class Player : Identity
/// </summary>
public int DonationsReceived { get => _donationsReceived ?? default; set => _donationsReceived = value; }

public int BuilderBaseTrophies { get => _builderBaseTrophies ?? default; set => _builderBaseTrophies = value; }

public int BestBuilderBaseTrophies { get => _bestBuilderBaseTrophies ?? default; set => _bestBuilderBaseTrophies = value; }

/// <summary>
/// Total capital contribution
/// </summary>
Expand Down Expand Up @@ -97,5 +103,7 @@ public class Player : Identity
public LabelList Labels { get; set; } = default!;

public PlayerHouse? PlayerHouse { get; set; }

public BuilderBaseLeague? BuilderBaseLeague { get; set; }
}
}
28 changes: 28 additions & 0 deletions src/ClashOfClans.Models/PlayerBuilderBaseRanking.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace ClashOfClans.Models
{
public class PlayerBuilderBaseRanking : Identity
{
private int? _expLevel;
private int? _rank;
private int? _previousRank;
private int? _builderBaseTrophies;
private int? _versusTrophies;
private int? _versusBattleWins;

public int ExpLevel { get => _expLevel ?? default; set => _expLevel = value; }

public int Rank { get => _rank ?? default; set => _rank = value; }

public int PreviousRank { get => _previousRank ?? default; set => _previousRank = value; }

public int BuilderBaseTrophies { get => _builderBaseTrophies ?? default; set => _builderBaseTrophies = value; }

public int VersusTrophies { get => _versusTrophies ?? default; set => _versusTrophies = value; }

public int VersusBattleWins { get => _versusBattleWins ?? default; set => _versusBattleWins = value; }

public PlayerRankingClan? Clan { get; set; }

public BuilderBaseLeague BuilderBaseLeague { get; set; } = default!;
}
}
8 changes: 8 additions & 0 deletions src/ClashOfClans.Models/PlayerBuilderBaseRankingList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace ClashOfClans.Models
{
public class PlayerBuilderBaseRankingList : List<PlayerBuilderBaseRanking>
{
}
}
4 changes: 4 additions & 0 deletions src/ClashOfClans.Models/PlayerLegendStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public class PlayerLegendStatistics
public LegendLeagueTournamentSeasonResult CurrentSeason { get; set; } = default!;

public LegendLeagueTournamentSeasonResult? PreviousSeason { get; set; }

public LegendLeagueTournamentSeasonResult? PreviousBuilderBaseSeason { get; set; }

public LegendLeagueTournamentSeasonResult? BestBuilderBaseSeason { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/ClashOfClans.Models/PlayerVersusRanking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class PlayerVersusRanking : Identity
private int? _previousRank;
private int? _versusTrophies;
private int? _versusBattleWins;
private int? _builderBaseTrophies;

public int ExpLevel { get => _expLevel ?? default; set => _expLevel = value; }

Expand All @@ -18,6 +19,10 @@ public class PlayerVersusRanking : Identity

public int VersusBattleWins { get => _versusBattleWins ?? default; set => _versusBattleWins = value; }

public int BuilderBaseTrophies { get => _builderBaseTrophies ?? default; set => _builderBaseTrophies = value; }

public PlayerRankingClan? Clan { get; set; }

public BuilderBaseLeague? BuilderBaseLeague { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
34 changes: 32 additions & 2 deletions src/ClashOfClans.Tests.Integration/LeaguesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public async Task GetWarLeagueInformation()
{
// Arrange
var leagues = _coc.Leagues;
var warLeagueId = GetRandom(_warLeagues).Id;
var warLeagues = (WarLeagueList)await _coc.Leagues.GetWarLeaguesAsync();
var warLeagueId = GetRandom(warLeagues).Id;

// Act
var warLeague = await leagues.GetWarLeagueAsync(warLeagueId);
Expand All @@ -112,13 +113,42 @@ public async Task GetCapitalLeagueInformation()
{
// Arrange
var leagues = _coc.Leagues;
var capitalLeagueId = GetRandom(_capitalLeagues).Id;
var capitalLeagues = (CapitalLeagueList)await _coc.Leagues.GetCapitalLeaguesAsync();
var capitalLeagueId = GetRandom(capitalLeagues).Id;

// Act
var capitalLeague = await leagues.GetCapitalLeagueAsync(capitalLeagueId);

// Assert
Assert.IsNotNull(capitalLeague);
}

[TestMethod]
public async Task ListBuilderBaseLeagues()
{
// Arrange
var leagues = _coc.Leagues;

// Act
var builderBaseLeagueList = (BuilderBaseLeagueList)await leagues.GetBuilderBaseLeaguesAsync();

// Assert
Assert.IsNotNull(builderBaseLeagueList);
}

[TestMethod]
public async Task GetBuilderBaseLeagueInformation()
{
// Arrange
var leagues = _coc.Leagues;
var builderBaseLeagues = (BuilderBaseLeagueList)await leagues.GetBuilderBaseLeaguesAsync();
var builderBaseLeagueId = GetRandom(builderBaseLeagues).Id;

// Act
var builderBaseLeague = await leagues.GetBuilderBaseLeagueAsync(builderBaseLeagueId);

// Assert
Assert.IsNotNull(builderBaseLeague);
}
}
}
36 changes: 36 additions & 0 deletions src/ClashOfClans.Tests.Integration/LocationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,41 @@ public async Task GetCapitalRankingsForASpecificLocation()
Assert.IsNotNull(clanCapitalRankingList);
Assert.IsTrue(clanCapitalRankingList.Count <= ItemLimit, $"Id {location.Id}");
}

[TestMethod]
public async Task GetPlayerBuilderBaseRankingsForASpecificLocation()
{
// Arrange
var location = GetRandom(_locations, l => l.IsCountry);
var query = new Query
{
Limit = ItemLimit
};

// Act
var playerBuilderBaseRankingList = (PlayerBuilderBaseRankingList)await _coc.Locations.GetPlayerBuilderBaseRankingAsync(location.Id, query);

// Assert
Assert.IsNotNull(playerBuilderBaseRankingList);
Assert.IsTrue(playerBuilderBaseRankingList.Count <= ItemLimit, $"Id {location.Id}");
}

[TestMethod]
public async Task GetClanBuilderBaseRankingsForASpecificLocation()
{
// Arrange
var location = GetRandom(_locations, l => l.IsCountry);
var query = new Query
{
Limit = ItemLimit
};

// Act
var clanBuilderBaseRankingList = (ClanBuilderBaseRankingList)await _coc.Locations.GetClanBuilderBaseRankingAsync(location.Id, query);

// Assert
Assert.IsNotNull(clanBuilderBaseRankingList);
Assert.IsTrue(clanBuilderBaseRankingList.Count <= ItemLimit, $"Id {location.Id}");
}
}
}
4 changes: 0 additions & 4 deletions src/ClashOfClans.Tests.Integration/TestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class TestsBase
protected static ClanList _clans = default!;
protected static LeagueList _leagues = default!;
protected static LocationList _locations = default!;
protected static WarLeagueList _warLeagues = default!;
protected static CapitalLeagueList _capitalLeagues = default!;
protected static IConfigurationRoot _config = default!;
protected static ClashOfClansClient _coc = default!;

Expand Down Expand Up @@ -51,8 +49,6 @@ public static async Task AssemblyInitialize(TestContext _)
_clans = (ClanList)await _coc.Clans.SearchClansAsync(query);
_leagues = (LeagueList)await _coc.Leagues.GetLeaguesAsync();
_locations = (LocationList)await _coc.Locations.GetLocationsAsync();
_warLeagues = (WarLeagueList)await _coc.Leagues.GetWarLeaguesAsync();
_capitalLeagues = (CapitalLeagueList)await _coc.Leagues.GetCapitalLeaguesAsync();
}
catch (ClashOfClansException ex)
{
Expand Down
22 changes: 22 additions & 0 deletions src/ClashOfClans/Api/Leagues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,27 @@ public Task<CapitalLeague> GetCapitalLeagueAsync(int? leagueId)

return _gameData.RequestAsync<CapitalLeague>(request);
}

public Task<QueryResult<BuilderBaseLeagueList>> GetBuilderBaseLeaguesAsync(Query? query = default)
{
var request = new AutoValidatedRequest
{
Query = query,
Uri = $"/builderbaseleagues"
};

return _gameData.QueryAsync<BuilderBaseLeagueList>(request);
}

public Task<BuilderBaseLeague> GetBuilderBaseLeagueAsync(int? leagueId)
{
var request = new AutoValidatedRequest
{
LeagueId = leagueId,
Uri = $"/builderbaseleagues/{leagueId}"
};

return _gameData.RequestAsync<BuilderBaseLeague>(request);
}
}
}
Loading

0 comments on commit c7169ad

Please sign in to comment.