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

Commit 70cc1b4

Browse files
author
Not Officer
committed
added stats v2 endpoint
1 parent a0d9b5b commit 70cc1b4

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
using Fortnite_API.Objects;
6+
using Fortnite_API.Objects.V1;
7+
8+
using RestSharp;
9+
10+
namespace Fortnite_API.Endpoints.V2
11+
{
12+
public class StatsV2Endpoints : EndpointBase
13+
{
14+
internal StatsV2Endpoints(IRestClient client) : base(client) { }
15+
16+
[Obsolete("BR V1 stats are no longer available since Epic Games shut down the endpoint.", true)]
17+
public Task GetBrV1Async()
18+
{
19+
return Task.Delay(1); // net452 doesnt have Task.CompletedTask
20+
}
21+
22+
[Obsolete("BR V1 stats are no longer available since Epic Games shut down the endpoint.", true)]
23+
public void GetBrV1() { }
24+
25+
public async Task<ApiResponse<BrStatsV2V1>> GetBrV2Async(Action<BrStatsV2V1RequestProperties> func, CancellationToken token = default)
26+
{
27+
var props = new BrStatsV2V1RequestProperties();
28+
func(props);
29+
30+
RestRequest request;
31+
32+
if (props.AccountId.HasValue)
33+
{
34+
request = new RestRequest($"v2/stats/br/v2/{props.AccountId.Value}", Method.GET);
35+
}
36+
else if (props.Name.HasValue)
37+
{
38+
request = new RestRequest("v2/stats/br/v2", Method.GET);
39+
request.AddQueryParameter("name", props.Name.Value);
40+
41+
if (props.AccountType.HasValue)
42+
{
43+
request.AddQueryParameter("accountType", props.AccountType.Value.GetString());
44+
}
45+
}
46+
else
47+
{
48+
throw new ArgumentException("missing accountId or name");
49+
}
50+
51+
if (props.TimeWindow.HasValue)
52+
{
53+
request.AddQueryParameter("timeWindow", props.TimeWindow.Value.GetString());
54+
}
55+
56+
if (props.ImagePlatform.HasValue)
57+
{
58+
request.AddQueryParameter("image", props.ImagePlatform.Value.GetString());
59+
}
60+
61+
var response = await _client.ExecuteAsync<ApiResponse<BrStatsV2V1>>(request, token).ConfigureAwait(false);
62+
return response.Data;
63+
}
64+
65+
public ApiResponse<BrStatsV2V1> GetBrV2Id(Action<BrStatsV2V1RequestProperties> func)
66+
{
67+
return GetBrV2Async(func).GetAwaiter().GetResult();
68+
}
69+
}
70+
}

src/Fortnite-API/Endpoints/V2/V2Endpoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class V2Endpoints
99
public NewsV2Endpoints News { get; }
1010
public CreatorCodeV2Endpoints CreatorCode { get; }
1111
public ShopV2Endpoints Shop { get; }
12+
public StatsV2Endpoints Stats { get; }
1213

1314
internal V2Endpoints(IRestClient client)
1415
{
@@ -17,6 +18,7 @@ internal V2Endpoints(IRestClient client)
1718
News = new NewsV2Endpoints(client);
1819
CreatorCode = new CreatorCodeV2Endpoints(client);
1920
Shop = new ShopV2Endpoints(client);
21+
Stats = new StatsV2Endpoints(client);
2022
}
2123
}
2224
}

src/Fortnite-API/Fortnite-API.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
<PackageLicenseExpression></PackageLicenseExpression>
1515
<Authors>Fortnite-API, NotOfficer</Authors>
1616
<PackageLicenseFile>LICENSE</PackageLicenseFile>
17-
<Version>2.3.0</Version>
17+
<Version>2.3.1</Version>
1818
<Company>Fortnite-API</Company>
1919
<PackageIconUrl></PackageIconUrl>
2020
<RepositoryType>git</RepositoryType>
2121
<Copyright>Copyright (c) 2019-2021 Fortnite-API.com</Copyright>
22-
<AssemblyVersion>2.3.0.0</AssemblyVersion>
23-
<FileVersion>2.3.0.0</FileVersion>
22+
<AssemblyVersion>2.3.1.0</AssemblyVersion>
23+
<FileVersion>2.3.1.0</FileVersion>
2424
<PackageIcon>logo.png</PackageIcon>
2525
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2626
</PropertyGroup>

0 commit comments

Comments
 (0)