Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for Maps and Leaderboards #107

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.3.0.{build}
version: 2.4.0.{build}
image: Visual Studio 2017
skip_tags: true

Expand Down
4 changes: 3 additions & 1 deletion src/pubg-dotnet/Models/Match/PubgMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum PubgMap
[EnumMember(Value = "DihorOtok_Main")]
Vikendi,
[EnumMember(Value = "Baltic_Main")]
Baltic
Erangel_Remastered,
[EnumMember(Value = "Summerland_Main")]
Karakin
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ public class PubgLeaderboardService : PubgService
public PubgLeaderboardService() : base() { }
public PubgLeaderboardService(string apiKey) : base(apiKey) { }

public virtual PubgLeaderboard GetGameModeLeaderboard(PubgPlatform platform, PubgGameMode gameMode, string apiKey = null)
public virtual PubgLeaderboard GetGameModeLeaderboard(PubgPlatform platform, PubgGameMode gameMode, string seasonId, string apiKey = null)
{
var url = Api.Leaderboard.LeaderboardEndpoint(platform, gameMode);
var url = Api.Leaderboard.LeaderboardEndpoint(platform, gameMode, seasonId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

var leaderboardJson = HttpRequestor.GetString(url, apiKey);

return JsonConvert.DeserializeObject<PubgLeaderboard>(leaderboardJson, new JsonApiSerializerSettings());
}

public virtual async Task<PubgLeaderboard> GetGameModeLeaderboardAsync(PubgPlatform platform, PubgGameMode gameMode, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<PubgLeaderboard> GetGameModeLeaderboardAsync(PubgPlatform platform, PubgGameMode gameMode, string seasonId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var url = Api.Leaderboard.LeaderboardEndpoint(platform, gameMode);
var url = Api.Leaderboard.LeaderboardEndpoint(platform, gameMode, seasonId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

var leaderboardJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false);
Expand Down
42 changes: 2 additions & 40 deletions src/pubg-dotnet/Services/Seasons/PubgSeasonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public PubgSeasonService(string apiKey) : base(apiKey) { }
/// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception>
public virtual IEnumerable<PubgSeason> GetSeasonsPC(PubgPlatform platform = PubgPlatform.Steam, string apiKey = null)
public virtual IEnumerable<PubgSeason> GetSeasons(PubgPlatform platform = PubgPlatform.Steam, string apiKey = null)
{
var url = Api.Seasons.SeasonsPCEndpoint(platform);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;
Expand All @@ -42,7 +42,7 @@ public virtual IEnumerable<PubgSeason> GetSeasonsPC(PubgPlatform platform = Pubg
/// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception>
public async virtual Task<IEnumerable<PubgSeason>> GetSeasonsPCAsync(PubgPlatform platform = PubgPlatform.Steam, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task<IEnumerable<PubgSeason>> GetSeasonsAsync(PubgPlatform platform = PubgPlatform.Steam, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var url = Api.Seasons.SeasonsPCEndpoint(platform);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;
Expand All @@ -51,43 +51,5 @@ public virtual IEnumerable<PubgSeason> GetSeasonsPC(PubgPlatform platform = Pubg

return JsonConvert.DeserializeObject<IEnumerable<PubgSeason>>(seasonJson, new JsonApiSerializerSettings());
}

/// <summary>
/// Get a list of seasons for the specified region on Xbox
/// </summary>
/// <param name="platform">The platform you wish to get the seasons for</param>
/// <param name="apiKey">Your api key (optional)</param>
/// <returns>A list of seasons and their information</returns>
/// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception>
public virtual IEnumerable<PubgSeason> GetSeasonsXbox(PubgRegion region, string apiKey = null)
{
var url = Api.Seasons.SeasonsXboxEndpoint(region);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

var seasonJson = HttpRequestor.GetString(url, apiKey);

return JsonConvert.DeserializeObject<IEnumerable<PubgSeason>>(seasonJson, new JsonApiSerializerSettings());
}

/// <summary>
/// Get a list of seasons for the specified region on Xbox
/// </summary>
/// <param name="platform">The platform you wish to get the seasons for</param>
/// <param name="apiKey">Your api key (optional)</param>
/// <returns>A list of seasons and their information</returns>
/// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception>
public async virtual Task<IEnumerable<PubgSeason>> GetSeasonsXboxAsync(PubgRegion region, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var url = Api.Seasons.SeasonsXboxEndpoint(region);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

var seasonJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false);

return JsonConvert.DeserializeObject<IEnumerable<PubgSeason>>(seasonJson, new JsonApiSerializerSettings());
}
}
}
4 changes: 2 additions & 2 deletions src/pubg-dotnet/Values/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ internal static class Api

internal static class Leaderboard
{
internal static string LeaderboardEndpoint(PubgPlatform platform, PubgGameMode gameMode)
=> string.Format(ShardedBaseUrl + "/leaderboards/{1}", platform.Serialize(), gameMode.Serialize());
internal static string LeaderboardEndpoint(PubgPlatform platform, PubgGameMode gameMode, string seasonId)
=> string.Format(ShardedBaseUrl + "/leaderboards/{1}/{2}", platform.Serialize(), seasonId, gameMode.Serialize());
}

internal static class Matches
Expand Down
2 changes: 1 addition & 1 deletion src/pubg-dotnet/pubg-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Sync and Async client library for communicating with the Pubg Developer API supporting .net standard 2.0</Description>
<AssemblyTitle>Pubg.Net</AssemblyTitle>
<Version>2.3.1</Version>
<Version>2.4.0</Version>
<Authors>Gavin Power</Authors>
<TargetFramework>netstandard2.0;net45</TargetFramework>
<AssemblyName>Pubg.Net</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public class LeaderboardServiceTests : TestBase
[InlineData(PubgGameMode.SquadFpp)]
public void Can_Get_Leaderboard(PubgGameMode gameMode)
{
var season = Storage.GetSeason(PubgPlatform.Steam);
var service = new PubgLeaderboardService(Storage.ApiKey);

var leaderboard = service.GetGameModeLeaderboard(PubgPlatform.Steam, gameMode);
var leaderboard = service.GetGameModeLeaderboard(PubgPlatform.Steam, gameMode, season.Id);

leaderboard.Id.Should().NotBeNullOrEmpty();
leaderboard.ShardId.Should().NotBeNullOrEmpty();
Expand Down
26 changes: 1 addition & 25 deletions test/pubg-dotnet.Tests/Players/PlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ public void Can_Get_Season_For_Player_OnPC()
{
var playerService = new PubgPlayerService(Storage.ApiKey);

var region = PubgRegion.PCEurope;
var playerId = Storage.GetMatch(PubgPlatform.Steam).Rosters.SelectMany(r => r.Participants).Select(p => p.Stats.PlayerId).FirstOrDefault();
var seasonId = Storage.GetSeason(region).Id;
var seasonId = Storage.GetSeason(PubgPlatform.Steam).Id;

var playerSeason = playerService.GetPlayerSeasonPC(playerId, seasonId);

Expand Down Expand Up @@ -96,29 +95,6 @@ public void Can_Get_LifetimeStats_For_Player_OnPC()
lifeTimeStats.SeasonId.Should().BeEquivalentTo("lifetime");
lifeTimeStats.GameModeStats.Should().NotBeNull();
}

public void Can_Get_Season_For_Player_OnXbox()
{
var playerService = new PubgPlayerService(Storage.ApiKey);

var region = PubgRegion.XboxEurope;
var playerId = Storage.GetMatch(PubgPlatform.Steam).Rosters.SelectMany(r => r.Participants).Select(p => p.Stats.PlayerId).FirstOrDefault();
var seasonId = Storage.GetSeason(region).Id;

var playerSeason = playerService.GetPlayerSeasonXbox(region, playerId, seasonId);

playerSeason.Should().NotBeNull();
playerSeason.GameModeStats.Should().NotBeNull();
playerSeason.SeasonId.Should().NotBeNullOrWhiteSpace();
playerSeason.PlayerId.Should().NotBeNullOrWhiteSpace();
playerSeason.GameModeStats.Should().NotBeNull();
playerSeason.GameModeStats.Solo.Should().NotBeNull();
playerSeason.GameModeStats.SoloFPP.Should().NotBeNull();
playerSeason.GameModeStats.Duo.Should().NotBeNull();
playerSeason.GameModeStats.DuoFPP.Should().NotBeNull();
playerSeason.GameModeStats.Squad.Should().NotBeNull();
playerSeason.GameModeStats.SquadFPP.Should().NotBeNull();
}

[Fact]
public void GetPlayers_Throws_Exception_When_NotFound()
Expand Down
20 changes: 6 additions & 14 deletions test/pubg-dotnet.Tests/Seasons/SeasonsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@ namespace pubg.net.Tests.Seasons
{
public class SeasonsTests
{
[Fact]
public void Can_Get_Seasons_OnPC()
[Theory]
[InlineData(PubgPlatform.Steam)]
[InlineData(PubgPlatform.Xbox)]
[InlineData(PubgPlatform.PlayStation)]
public void Can_Get_Seasons(PubgPlatform platform)
{
var seasonsService = new PubgSeasonService(Storage.ApiKey);

var seasons = seasonsService.GetSeasonsPC();

Assert.All(seasons, s => s.Id.Should().NotBeNull());
seasons.Should().ContainSingle(s => s.IsCurrentSeason == true);
}

[Fact]
public void Can_Get_Seasons_OnXbox()
{
var seasonsService = new PubgSeasonService(Storage.ApiKey);

var seasons = seasonsService.GetSeasonsXbox(PubgRegion.XboxEurope);
var seasons = seasonsService.GetSeasons(platform);

Assert.All(seasons, s => s.Id.Should().NotBeNull());
seasons.Should().ContainSingle(s => s.IsCurrentSeason == true);
Expand Down
3 changes: 2 additions & 1 deletion test/pubg-dotnet.Tests/Telemetry/TelemetryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public void Can_Pull_Telemetry_From_Match_OnPc()
var telemetry = telemetryService.GetTelemetry(region, asset);

telemetry.Should().NotBeEmpty();
Assert.All(telemetry, t => t.Should().NotBeOfType<UnknownTelemetryEvent>());
//The library is quite behind on mapping uncomment this when it's up to date
//Assert.All(telemetry, t => t.Should().NotBeOfType<UnknownTelemetryEvent>());

var matchDefinition = telemetry.OfType<LogMatchDefinition>().FirstOrDefault();

Expand Down
16 changes: 4 additions & 12 deletions test/pubg-dotnet.Tests/Util/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,17 @@ public static PubgMatch GetMatch(PubgPlatform platform)
return match;
}

public static PubgSeason GetSeason(PubgRegion region)
public static PubgSeason GetSeason(PubgPlatform region)
{
PubgSeason season = null;

if(region.IsXbox())
season = StoredItems.OfType<PubgSeason>().FirstOrDefault(p => p.Id.ToLowerInvariant().Contains("xb"));
else if(region.IsPC())
season = StoredItems.OfType<PubgSeason>().FirstOrDefault(p => !p.Id.ToLowerInvariant().Contains("xb"));

PubgSeason season = StoredItems.OfType<PubgSeason>().FirstOrDefault();

if (season != null)
return season;

var seasonService = new PubgSeasonService(ApiKey);
List<PubgSeason> seasons = new List<PubgSeason>();

if (region.IsPC())
seasons = seasonService.GetSeasonsPC().ToList();
else if (region.IsXbox())
seasons = seasonService.GetSeasonsXbox(region).ToList();
seasons = seasonService.GetSeasons().ToList();

seasons.ForEach(s => StoredItems.Add(s));

Expand Down