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+ }
0 commit comments