Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
added stats v2 endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Not Officer committed Jul 9, 2021
1 parent a0d9b5b commit 70cc1b4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
70 changes: 70 additions & 0 deletions src/Fortnite-API/Endpoints/V2/StatsV1Endpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using Fortnite_API.Objects;
using Fortnite_API.Objects.V1;

using RestSharp;

namespace Fortnite_API.Endpoints.V2
{
public class StatsV2Endpoints : EndpointBase
{
internal StatsV2Endpoints(IRestClient client) : base(client) { }

[Obsolete("BR V1 stats are no longer available since Epic Games shut down the endpoint.", true)]
public Task GetBrV1Async()
{
return Task.Delay(1); // net452 doesnt have Task.CompletedTask
}

[Obsolete("BR V1 stats are no longer available since Epic Games shut down the endpoint.", true)]
public void GetBrV1() { }

public async Task<ApiResponse<BrStatsV2V1>> GetBrV2Async(Action<BrStatsV2V1RequestProperties> func, CancellationToken token = default)
{
var props = new BrStatsV2V1RequestProperties();
func(props);

RestRequest request;

if (props.AccountId.HasValue)
{
request = new RestRequest($"v2/stats/br/v2/{props.AccountId.Value}", Method.GET);
}
else if (props.Name.HasValue)
{
request = new RestRequest("v2/stats/br/v2", Method.GET);
request.AddQueryParameter("name", props.Name.Value);

if (props.AccountType.HasValue)
{
request.AddQueryParameter("accountType", props.AccountType.Value.GetString());
}
}
else
{
throw new ArgumentException("missing accountId or name");
}

if (props.TimeWindow.HasValue)
{
request.AddQueryParameter("timeWindow", props.TimeWindow.Value.GetString());
}

if (props.ImagePlatform.HasValue)
{
request.AddQueryParameter("image", props.ImagePlatform.Value.GetString());
}

var response = await _client.ExecuteAsync<ApiResponse<BrStatsV2V1>>(request, token).ConfigureAwait(false);
return response.Data;
}

public ApiResponse<BrStatsV2V1> GetBrV2Id(Action<BrStatsV2V1RequestProperties> func)
{
return GetBrV2Async(func).GetAwaiter().GetResult();
}
}
}
2 changes: 2 additions & 0 deletions src/Fortnite-API/Endpoints/V2/V2Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class V2Endpoints
public NewsV2Endpoints News { get; }
public CreatorCodeV2Endpoints CreatorCode { get; }
public ShopV2Endpoints Shop { get; }
public StatsV2Endpoints Stats { get; }

internal V2Endpoints(IRestClient client)
{
Expand All @@ -17,6 +18,7 @@ internal V2Endpoints(IRestClient client)
News = new NewsV2Endpoints(client);
CreatorCode = new CreatorCodeV2Endpoints(client);
Shop = new ShopV2Endpoints(client);
Stats = new StatsV2Endpoints(client);
}
}
}
6 changes: 3 additions & 3 deletions src/Fortnite-API/Fortnite-API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<PackageLicenseExpression></PackageLicenseExpression>
<Authors>Fortnite-API, NotOfficer</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>2.3.0</Version>
<Version>2.3.1</Version>
<Company>Fortnite-API</Company>
<PackageIconUrl></PackageIconUrl>
<RepositoryType>git</RepositoryType>
<Copyright>Copyright (c) 2019-2021 Fortnite-API.com</Copyright>
<AssemblyVersion>2.3.0.0</AssemblyVersion>
<FileVersion>2.3.0.0</FileVersion>
<AssemblyVersion>2.3.1.0</AssemblyVersion>
<FileVersion>2.3.1.0</FileVersion>
<PackageIcon>logo.png</PackageIcon>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>
Expand Down

0 comments on commit 70cc1b4

Please sign in to comment.