1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Threading ;
4+ using System . Threading . Tasks ;
5+
6+ using Fortnite_API . Objects ;
7+
8+ using RestSharp ;
9+
10+ namespace Fortnite_API . Endpoints
11+ {
12+ public class CosmeticsEndpoints
13+ {
14+ private readonly IRestClient _client ;
15+
16+ internal CosmeticsEndpoints ( IRestClient client )
17+ {
18+ _client = client ;
19+ }
20+
21+ public async Task < ApiResponse < List < BrCosmetic > > > GetBrAsync ( ApiLanguage ? language = null , CancellationToken token = default )
22+ {
23+ var request = new RestRequest ( "/cosmetics/br" , Method . GET ) ;
24+
25+ if ( language . HasValue )
26+ {
27+ request . AddQueryParameter ( "language" , language . Value . GetLanguageCode ( ) ) ;
28+ }
29+
30+ var response = await _client . ExecuteTaskAsync < ApiResponse < List < BrCosmetic > > > ( request , token ) . ConfigureAwait ( false ) ;
31+ return response . Data ;
32+ }
33+
34+ public ApiResponse < List < BrCosmetic > > GetBr ( ApiLanguage ? language = null )
35+ {
36+ return GetBrAsync ( language ) . GetAwaiter ( ) . GetResult ( ) ;
37+ }
38+
39+ public async Task < ApiResponse < BrCosmetic > > GetBrAsync ( string cosmeticId , ApiLanguage ? language = null , CancellationToken token = default )
40+ {
41+ if ( cosmeticId == null )
42+ {
43+ throw new ArgumentNullException ( nameof ( cosmeticId ) ) ;
44+ }
45+
46+ if ( cosmeticId . Length == 0 )
47+ {
48+ throw new ArgumentOutOfRangeException ( nameof ( cosmeticId ) ) ;
49+ }
50+
51+ var request = new RestRequest ( $ "/cosmetics/br/{ cosmeticId } ", Method . GET ) ;
52+
53+ if ( language . HasValue )
54+ {
55+ request . AddQueryParameter ( "language" , language . Value . GetLanguageCode ( ) ) ;
56+ }
57+
58+ var response = await _client . ExecuteTaskAsync < ApiResponse < BrCosmetic > > ( request , token ) . ConfigureAwait ( false ) ;
59+ return response . Data ;
60+ }
61+
62+ public ApiResponse < BrCosmetic > GetBr ( string cosmeticId , ApiLanguage ? language = null )
63+ {
64+ return GetBrAsync ( cosmeticId , language ) . GetAwaiter ( ) . GetResult ( ) ;
65+ }
66+
67+ public async Task < ApiResponse < List < BrCosmetic > > > SearchBrIdsAsync ( IEnumerable < string > cosmeticIds , ApiLanguage ? language = null , CancellationToken token = default )
68+ {
69+ if ( cosmeticIds == null )
70+ {
71+ throw new ArgumentNullException ( nameof ( cosmeticIds ) ) ;
72+ }
73+
74+ var request = new RestRequest ( "/cosmetics/br/search/ids" , Method . GET ) ;
75+ var isArrayEmpty = true ;
76+
77+ foreach ( var cosmeticId in cosmeticIds )
78+ {
79+ isArrayEmpty = false ;
80+ request . AddQueryParameter ( "id" , cosmeticId ) ;
81+ }
82+
83+ if ( isArrayEmpty )
84+ {
85+ throw new ArgumentOutOfRangeException ( nameof ( cosmeticIds ) ) ;
86+ }
87+
88+ if ( language . HasValue )
89+ {
90+ request . AddQueryParameter ( "language" , language . Value . GetLanguageCode ( ) ) ;
91+ }
92+
93+ var response = await _client . ExecuteTaskAsync < ApiResponse < List < BrCosmetic > > > ( request , token ) . ConfigureAwait ( false ) ;
94+ return response . Data ;
95+ }
96+
97+ public ApiResponse < List < BrCosmetic > > SearchBrIds ( IEnumerable < string > cosmeticIds , ApiLanguage ? language = null )
98+ {
99+ return SearchBrIdsAsync ( cosmeticIds , language ) . GetAwaiter ( ) . GetResult ( ) ;
100+ }
101+
102+ public async Task < ApiResponse < BrCosmetic > > SearchBrAsync ( Action < BrCosmeticSearchProperties > func , CancellationToken token = default )
103+ {
104+ if ( func == null )
105+ {
106+ throw new ArgumentNullException ( nameof ( func ) ) ;
107+ }
108+
109+ var request = new RestRequest ( "/cosmetics/br/search" , Method . GET ) . ApplySearchParameters ( func ) ;
110+ var response = await _client . ExecuteTaskAsync < ApiResponse < BrCosmetic > > ( request , token ) . ConfigureAwait ( false ) ;
111+ return response . Data ;
112+ }
113+
114+ public ApiResponse < BrCosmetic > SearchBr ( Action < BrCosmeticSearchProperties > func )
115+ {
116+ return SearchBrAsync ( func ) . GetAwaiter ( ) . GetResult ( ) ;
117+ }
118+
119+ public async Task < ApiResponse < List < BrCosmetic > > > SearchAllBrAsync ( Action < BrCosmeticSearchProperties > func , CancellationToken token = default )
120+ {
121+ if ( func == null )
122+ {
123+ throw new ArgumentNullException ( nameof ( func ) ) ;
124+ }
125+
126+ var request = new RestRequest ( "/cosmetics/br/search/all" , Method . GET ) . ApplySearchParameters ( func ) ;
127+ var response = await _client . ExecuteTaskAsync < ApiResponse < List < BrCosmetic > > > ( request , token ) . ConfigureAwait ( false ) ;
128+ return response . Data ;
129+ }
130+
131+ public ApiResponse < List < BrCosmetic > > SearchAll ( Action < BrCosmeticSearchProperties > func )
132+ {
133+ return SearchAllBrAsync ( func ) . GetAwaiter ( ) . GetResult ( ) ;
134+ }
135+ }
136+ }
0 commit comments