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

Updated Player Endpoint to new scheme #84

Merged
merged 6 commits into from
Dec 12, 2018
Merged
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: 2 additions & 0 deletions src/pubg-dotnet/Models/Common/PubgPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public enum PubgPlatform
{
[EnumMember(Value = "steam")]
Steam,
[EnumMember(Value = "xbox")]
Xbox,
[EnumMember(Value = "kakao")]
Kakao
}
Expand Down
23 changes: 17 additions & 6 deletions src/pubg-dotnet/Models/Match/PubgGameMode.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Pubg.Net.Infrastructure.Attributes;
using Pubg.Net.Infrastructure.JsonConverters;
using System.Runtime.Serialization;

namespace Pubg.Net
{
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(DefaultValueStringEnumConverter))]
public enum PubgGameMode
{
[DefaultEnumMember]
Unknown,
[EnumMember(Value = "squad")]
Squad,
[EnumMember(Value = "squad-fpp")]
Expand All @@ -19,9 +22,17 @@ public enum PubgGameMode
Duo,
[EnumMember(Value = "duo-fpp")]
DuoFPP,
[EnumMember(Value = "warmodetpp")]
WarModeTPP,
[EnumMember(Value = "warmodefpp")]
WarModeFPP
[EnumMember(Value = "normal-duo")]
NormalDuo,
[EnumMember(Value = "normal-duo-fpp")]
NormalDuoFPP,
[EnumMember(Value = "normal-solo")]
NormalSolo,
[EnumMember(Value = "normal-solo-fpp")]
NormalSoloFPP,
[EnumMember(Value = "normal-squad")]
NormalSquad,
[EnumMember(Value = "normal-squad-fpp")]
NormalSquadFPP
}
}
9 changes: 7 additions & 2 deletions src/pubg-dotnet/Models/Match/PubgMatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Newtonsoft.Json;
using Pubg.Net.Models.Base;
using Pubg.Net.Models.Seasons;
using System;
using System.Collections.Generic;

namespace Pubg.Net
Expand All @@ -10,7 +12,7 @@ public class PubgMatch : PubgShardedEntity
public string CreatedAt { get; set; }

[JsonProperty]
public int Duration { get; set; }
public long Duration { get; set; }

[JsonProperty]
public IEnumerable<PubgRoster> Rosters { get; set; }
Expand All @@ -25,7 +27,7 @@ public class PubgMatch : PubgShardedEntity
public PubgMatchStats Stats { get; set; }

[JsonProperty]
public string GameMode { get; set; }
public PubgGameMode GameMode { get; set; }

[JsonProperty]
public string PatchVersion { get; set; }
Expand All @@ -41,5 +43,8 @@ public class PubgMatch : PubgShardedEntity

[JsonProperty]
public bool IsCustomMatch { get; set; }

[JsonProperty]
public PubgSeasonState SeasonState { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/pubg-dotnet/Models/Seasons/PubgSeasonState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;
using Pubg.Net.Infrastructure.Attributes;
using Pubg.Net.Infrastructure.JsonConverters;
using System.Runtime.Serialization;

namespace Pubg.Net.Models.Seasons
{
[JsonConverter(typeof(DefaultValueStringEnumConverter))]
public enum PubgSeasonState
{
[DefaultEnumMember]
Unknown,
[EnumMember(Value = "closed")]
Closed,
[EnumMember(Value = "prepare")]
Prepare,
[EnumMember(Value = "progress")]
Progress
}
}
102 changes: 64 additions & 38 deletions src/pubg-dotnet/Services/Players/PubgPlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@ public class PubgPlayerService : PubgService
public PubgPlayerService() : base() { }
public PubgPlayerService(string apiKey) : base(apiKey) { }

public virtual PubgPlayer GetPlayer(PubgRegion region, string playerId, string apiKey = null)
public virtual PubgPlayer GetPlayer(PubgPlatform platform, string playerId, string apiKey = null)
{
var url = Api.Players.PlayersEndpoint(region, playerId);
var url = Api.Players.PlayersEndpoint(platform, playerId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

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

return JsonConvert.DeserializeObject<PubgPlayer>(playerJson, new JsonApiSerializerSettings());
}

public virtual async Task<PubgPlayer> GetPlayerAsync(PubgRegion region, string playerId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<PubgPlayer> GetPlayerAsync(PubgPlatform platform, string playerId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var url = Api.Players.PlayersEndpoint(region, playerId);
var url = Api.Players.PlayersEndpoint(platform, playerId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

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

return JsonConvert.DeserializeObject<PubgPlayer>(playerJson, new JsonApiSerializerSettings());
}

public virtual IEnumerable<PubgPlayer> GetPlayers(PubgRegion region, GetPubgPlayersRequest filter)
public virtual IEnumerable<PubgPlayer> GetPlayers(PubgPlatform platform, GetPubgPlayersRequest filter)
{
var url = RequestBuilder.BuildRequestUrl(Api.Players.PlayersEndpoint(region), filter);
var url = RequestBuilder.BuildRequestUrl(Api.Players.PlayersEndpoint(platform), filter);
var apiKey = string.IsNullOrEmpty(filter.ApiKey) ? ApiKey : filter.ApiKey;

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

return JsonConvert.DeserializeObject<IEnumerable<PubgPlayer>>(collectionJson, new JsonApiSerializerSettings());
}

public virtual async Task<IEnumerable<PubgPlayer>> GetPlayersAsync(PubgRegion region, GetPubgPlayersRequest filter, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<IEnumerable<PubgPlayer>> GetPlayersAsync(PubgPlatform platform, GetPubgPlayersRequest filter, CancellationToken cancellationToken = default(CancellationToken))
{
var url = RequestBuilder.BuildRequestUrl(Api.Players.PlayersEndpoint(region), filter);
var url = RequestBuilder.BuildRequestUrl(Api.Players.PlayersEndpoint(platform), filter);
var apiKey = string.IsNullOrEmpty(filter.ApiKey) ? ApiKey : filter.ApiKey;

var collectionJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false);
Expand All @@ -55,8 +55,9 @@ public virtual IEnumerable<PubgPlayer> GetPlayers(PubgRegion region, GetPubgPlay
}

/// <summary>
/// Gets the players season stats and matches for the default platform (steam)
/// Gets the players season stats and matches for the specified platform
/// </summary>
/// <param name="platform">The platform on which the season took place</param>
/// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
/// <param name="seasonId">The ID of the season you wish to recieve stats and matches for</param>
/// <param name="apiKey">Your API key (optional)</param>
Expand All @@ -65,10 +66,18 @@ public virtual IEnumerable<PubgPlayer> GetPlayers(PubgRegion region, GetPubgPlay
/// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</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 PubgPlayerSeason GetPlayerSeasonPC(string playerId, string seasonId, string apiKey = null) => GetPlayerSeasonPC(PubgPlatform.Steam, playerId, seasonId, apiKey);
public virtual PubgPlayerSeason GetPlayerSeason(PubgPlatform platform, string playerId, string seasonId, string apiKey = null)
{
var url = Api.Players.PlayerSeasonsEndpoint(platform, playerId, seasonId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

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

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

/// <summary>
/// Gets the players season stats and matches for the specified platform
/// Gets the players season stats and matches for the specified platform asychronusly
/// </summary>
/// <param name="platform">The platform on which the season took place</param>
/// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
Expand All @@ -79,18 +88,52 @@ public virtual IEnumerable<PubgPlayer> GetPlayers(PubgRegion region, GetPubgPlay
/// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</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 PubgPlayerSeason GetPlayerSeasonPC(PubgPlatform platform, string playerId, string seasonId, string apiKey = null)
public async virtual Task<PubgPlayerSeason> GetPlayerSeasonAsync(PubgPlatform platform, string playerId, string seasonId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var url = Api.Players.PlayerSeasonsPCEndpoint(platform, playerId, seasonId);
var url = Api.Players.PlayerSeasonsEndpoint(platform, playerId, seasonId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

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

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

/// <summary>
/// Gets the players season stats and matches for the default platform (steam)
///
/// **NOTE**: This method has been deprecated and will be removed in the next major version.
/// </summary>
/// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
/// <param name="seasonId">The ID of the season you wish to recieve stats and matches for</param>
/// <param name="apiKey">Your API key (optional)</param>
/// <returns>Stats and matches for a given player during a given season</returns>
/// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</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 PubgPlayerSeason GetPlayerSeasonPC(string playerId, string seasonId, string apiKey = null) => GetPlayerSeason(PubgPlatform.Steam, playerId, seasonId, apiKey);

/// <summary>
/// Gets the players season stats and matches for the specified platform
///
/// **NOTE**: This method has been deprecated and will be removed in the next major version.
/// </summary>
/// <param name="platform">The platform on which the season took place</param>
/// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
/// <param name="seasonId">The ID of the season you wish to recieve stats and matches for</param>
/// <param name="apiKey">Your API key (optional)</param>
/// <returns>Stats and matches for a given player during a given season</returns>
/// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
/// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</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 PubgPlayerSeason GetPlayerSeasonPC(PubgPlatform platform, string playerId, string seasonId, string apiKey = null)
=> GetPlayerSeason(platform, playerId, seasonId, apiKey);

/// <summary>
/// Gets the players season stats and matches for the specified platform asynchronusly
///
/// **NOTE**: This method has been deprecated and will be removed in the next major version.
/// </summary>
/// <param name="platform">The platform on which the season took place</param>
/// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
Expand All @@ -102,17 +145,12 @@ public virtual PubgPlayerSeason GetPlayerSeasonPC(PubgPlatform platform, string
/// <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<PubgPlayerSeason> GetPlayerSeasonPCAsync(PubgPlatform platform, string playerId, string seasonId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var url = Api.Players.PlayerSeasonsPCEndpoint(platform, playerId, seasonId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

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

return JsonConvert.DeserializeObject<PubgPlayerSeason>(seasonJson, new JsonApiSerializerSettings());
}
=> await GetPlayerSeasonAsync(platform, playerId, seasonId, apiKey, cancellationToken);

/// <summary>
/// Gets the players season stats and matches played on the xbox in the specified region
///
/// **NOTE**: This method has been deprecated and will be removed in the next major version.
/// </summary>
/// <param name="region">The region which the player is located in</param>
/// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
Expand All @@ -124,17 +162,12 @@ public virtual PubgPlayerSeason GetPlayerSeasonPC(PubgPlatform platform, string
/// <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 PubgPlayerSeason GetPlayerSeasonXbox(PubgRegion region, string playerId, string seasonId, string apiKey = null)
{
var url = Api.Players.PlayerSeasonsXboxEndpoint(region, playerId, seasonId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

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

return JsonConvert.DeserializeObject<PubgPlayerSeason>(seasonJson, new JsonApiSerializerSettings());
}
=> GetPlayerSeason(PubgPlatform.Xbox, playerId, seasonId, apiKey);

/// <summary>
/// Gets the players season stats and matches played on the xbox in the specified region asychronusly
///
/// **NOTE**: This method has been deprecated and will be removed in the next major version.
/// </summary>
/// <param name="region">The region which the player is located in</param>
/// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
Expand All @@ -146,13 +179,6 @@ public virtual PubgPlayerSeason GetPlayerSeasonXbox(PubgRegion region, string pl
/// <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<PubgPlayerSeason> GetPlayerSeasonXboxAsync(PubgRegion region, string playerId, string seasonId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var url = Api.Players.PlayerSeasonsXboxEndpoint(region, playerId, seasonId);
apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

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

return JsonConvert.DeserializeObject<PubgPlayerSeason>(seasonJson, new JsonApiSerializerSettings());
}
=> await GetPlayerSeasonAsync(PubgPlatform.Xbox, playerId, seasonId, apiKey, cancellationToken);
}
}
7 changes: 3 additions & 4 deletions src/pubg-dotnet/Values/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ internal static class Status

internal static class Players
{
internal static string PlayersEndpoint(PubgRegion region) => string.Format(ShardedBaseUrl + "/players", region.Serialize());
internal static string PlayersEndpoint(PubgRegion region, string playerId) => PlayersEndpoint(region) + $"/{playerId}";
internal static string PlayerSeasonsPCEndpoint(PubgPlatform platform, string playerId, string seasonId) => string.Format(ShardedBaseUrl + "/players/{1}/seasons/{2}", platform.Serialize(), playerId, seasonId);
internal static string PlayerSeasonsXboxEndpoint(PubgRegion region, string playerId, string seasonId) => PlayersEndpoint(region) + $"/{playerId}/seasons/{seasonId}";
internal static string PlayersEndpoint(PubgPlatform platform) => string.Format(ShardedBaseUrl + "/players", platform.Serialize());
internal static string PlayersEndpoint(PubgPlatform platform, string playerId) => PlayersEndpoint(platform) + $"/{playerId}";
internal static string PlayerSeasonsEndpoint(PubgPlatform platform, string playerId, string seasonId) => string.Format(ShardedBaseUrl + "/players/{1}/seasons/{2}", platform.Serialize(), playerId, seasonId);
}

internal static class Samples
Expand Down
4 changes: 2 additions & 2 deletions test/pubg-dotnet.Tests/Matches/MatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Pubg.Net.Tests.Matches
{
public class MatchTests
public class MatchTests : TestBase
{
[Fact]
public void Can_Retrieve_Match_ForPC()
Expand All @@ -20,7 +20,7 @@ public void Can_Retrieve_Match_ForPC()
var match = matchService.GetMatchPC(samples.MatchIds.FirstOrDefault());

match.Rosters.Should().NotBeNull();
match.GameMode.Should().NotBeNullOrWhiteSpace();
match.GameMode.Should().NotBe(PubgGameMode.Unknown);

Assert.All(match.Rosters, r => r.Stats.Rank.Should().BeGreaterThan(0));
match.Rosters.Should().ContainSingle(x => x.Won == true);
Expand Down
Loading