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

Commit 1ff7442

Browse files
author
Not Officer
committed
implemented all V2 endpoints + minor refactoring
1 parent 63ef26f commit 1ff7442

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3377
-131
lines changed

src/Fortnite-API.Test/Program.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Fortnite_API;
55
using Fortnite_API.Objects;
66
using Fortnite_API.Objects.V1;
7+
using Fortnite_API.Objects.V2;
78

89
namespace Fortnite_api.Test
910
{
@@ -14,6 +15,38 @@ private static async Task Main()
1415
const string apiKey = null; // optional as of now. check https://dash.fortnite-api.com to be sure
1516
var api = new FortniteApi(apiKey);
1617

18+
//var cosmeticsV2 = await api.V2.Cosmetics.GetBrAsync();
19+
var renegadeSearch = await api.V2.Cosmetics.SearchBrAsync(x =>
20+
{
21+
x.Name = "enegade raid";
22+
x.MatchMethod = MatchMethod.Contains;
23+
x.BackendType = "AthenaCharacter";
24+
});
25+
26+
var aesV2 = await api.V2.Aes.GetAsync();
27+
var aesV2Base64 = await api.V2.Aes.GetAsync(AesV2KeyFormat.Base64);
28+
29+
var newsV2 = await api.V2.News.GetAsync();
30+
var newsV2German = await api.V2.News.GetAsync(GameLanguage.DE);
31+
var newsV2Br = await api.V2.News.GetBrAsync();
32+
33+
var creatorCodeV2tfue = await api.V2.CreatorCode.GetAsync("tfue239042039480");
34+
var creatorCodeV2allStw = await api.V2.CreatorCode.SearchAllAsync("stw");
35+
36+
var shopV2 = await api.V2.Shop.GetBrAsync();
37+
var shopV2German = await api.V2.Shop.GetBrAsync(GameLanguage.DE);
38+
var shopV2Combined = await api.V2.Shop.GetBrCombinedAsync();
39+
40+
var statsV2V1 = await api.V1.Stats.GetBrV2Async(x =>
41+
{
42+
//x.AccountId = "4735ce9132924caf8a5b17789b40f79c";
43+
x.Name = "ninja";
44+
x.ImagePlatform = BrStatsV2V1ImagePlatform.All;
45+
});
46+
47+
Debugger.Break();
48+
return;
49+
1750
var aes = await api.V1.Aes.GetAsync();
1851
await Task.Delay(500);
1952
var tfueCode = await api.V1.CreatorCode.GetAsync("tfue");
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.V1
11+
{
12+
public class StatsV1Endpoints : EndpointBase
13+
{
14+
internal StatsV1Endpoints(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($"v1/stats/br/v2/{props.AccountId.Value}", Method.GET);
35+
}
36+
else if (props.Name.HasValue)
37+
{
38+
request = new RestRequest("v1/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/V1/V1Endpoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class V1Endpoints
99
public NewsV1Endpoints News { get; }
1010
public CreatorcodeV1Endpoints CreatorCode { get; }
1111
public AesV1Endpoints Aes { get; }
12+
public StatsV1Endpoints Stats { get; }
1213

1314
internal V1Endpoints(IRestClient client)
1415
{
@@ -17,6 +18,7 @@ internal V1Endpoints(IRestClient client)
1718
News = new NewsV1Endpoints(client);
1819
CreatorCode = new CreatorcodeV1Endpoints(client);
1920
Aes = new AesV1Endpoints(client);
21+
Stats = new StatsV1Endpoints(client);
2022
}
2123
}
2224
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
using Fortnite_API.Objects;
5+
using Fortnite_API.Objects.V2;
6+
7+
using RestSharp;
8+
9+
namespace Fortnite_API.Endpoints.V2
10+
{
11+
public class AesV2Endpoints : EndpointBase
12+
{
13+
internal AesV2Endpoints(IRestClient client) : base(client) { }
14+
15+
public async Task<ApiResponse<AesV2>> GetAsync(AesV2KeyFormat? keyFormat = null, CancellationToken token = default)
16+
{
17+
var request = new RestRequest("v2/aes", Method.GET);
18+
19+
if (keyFormat.HasValue)
20+
{
21+
request.AddQueryParameter("keyFormat", keyFormat.Value.GetString());
22+
}
23+
24+
var response = await _client.ExecuteAsync<ApiResponse<AesV2>>(request, token).ConfigureAwait(false);
25+
return response.Data;
26+
}
27+
28+
public ApiResponse<AesV2> Get(AesV2KeyFormat? keyFormat = null)
29+
{
30+
return GetAsync(keyFormat).GetAwaiter().GetResult();
31+
}
32+
}
33+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
using Fortnite_API.Objects;
7+
using Fortnite_API.Objects.V2;
8+
9+
using RestSharp;
10+
11+
namespace Fortnite_API.Endpoints.V2
12+
{
13+
public class CosmeticsV2Endpoints : EndpointBase
14+
{
15+
internal CosmeticsV2Endpoints(IRestClient client) : base(client) { }
16+
17+
public async Task<ApiResponse<List<BrCosmeticV2>>> GetBrAsync(GameLanguage? language = null, CancellationToken token = default)
18+
{
19+
var request = new RestRequest("v2/cosmetics/br", Method.GET);
20+
21+
if (language.HasValue)
22+
{
23+
request.AddQueryParameter("language", language.Value.GetLanguageCode());
24+
}
25+
26+
var response = await _client.ExecuteAsync<ApiResponse<List<BrCosmeticV2>>>(request, token).ConfigureAwait(false);
27+
return response.Data;
28+
}
29+
30+
public ApiResponse<List<BrCosmeticV2>> GetBr(GameLanguage? language = null)
31+
{
32+
return GetBrAsync(language).GetAwaiter().GetResult();
33+
}
34+
35+
public async Task<ApiResponse<BrCosmeticV2>> GetBrAsync(string cosmeticId, GameLanguage? language = null, CancellationToken token = default)
36+
{
37+
if (cosmeticId == null)
38+
{
39+
throw new ArgumentNullException(nameof(cosmeticId));
40+
}
41+
42+
if (cosmeticId.Length == 0)
43+
{
44+
throw new ArgumentOutOfRangeException(nameof(cosmeticId));
45+
}
46+
47+
var request = new RestRequest($"v2/cosmetics/br/{cosmeticId}", Method.GET);
48+
49+
if (language.HasValue)
50+
{
51+
request.AddQueryParameter("language", language.Value.GetLanguageCode());
52+
}
53+
54+
var response = await _client.ExecuteAsync<ApiResponse<BrCosmeticV2>>(request, token).ConfigureAwait(false);
55+
return response.Data;
56+
}
57+
58+
public ApiResponse<BrCosmeticV2> GetBr(string cosmeticId, GameLanguage? language = null)
59+
{
60+
return GetBrAsync(cosmeticId, language).GetAwaiter().GetResult();
61+
}
62+
63+
public async Task<ApiResponse<List<BrCosmeticV2>>> SearchBrIdsAsync(IEnumerable<string> cosmeticIds, GameLanguage? language = null, CancellationToken token = default)
64+
{
65+
if (cosmeticIds == null)
66+
{
67+
throw new ArgumentNullException(nameof(cosmeticIds));
68+
}
69+
70+
var request = new RestRequest("v2/cosmetics/br/search/ids", Method.GET);
71+
var isArrayEmpty = true;
72+
73+
foreach (var cosmeticId in cosmeticIds)
74+
{
75+
isArrayEmpty = false;
76+
request.AddQueryParameter("id", cosmeticId);
77+
}
78+
79+
if (isArrayEmpty)
80+
{
81+
throw new ArgumentOutOfRangeException(nameof(cosmeticIds));
82+
}
83+
84+
if (language.HasValue)
85+
{
86+
request.AddQueryParameter("language", language.Value.GetLanguageCode());
87+
}
88+
89+
var response = await _client.ExecuteAsync<ApiResponse<List<BrCosmeticV2>>>(request, token).ConfigureAwait(false);
90+
return response.Data;
91+
}
92+
93+
public ApiResponse<List<BrCosmeticV2>> SearchBrIds(IEnumerable<string> cosmeticIds, GameLanguage? language = null)
94+
{
95+
return SearchBrIdsAsync(cosmeticIds, language).GetAwaiter().GetResult();
96+
}
97+
98+
public async Task<ApiResponse<BrCosmeticV2>> SearchBrAsync(Action<BrCosmeticV2SearchProperties> func, CancellationToken token = default)
99+
{
100+
if (func == null)
101+
{
102+
throw new ArgumentNullException(nameof(func));
103+
}
104+
105+
var request = new RestRequest("v2/cosmetics/br/search", Method.GET).ApplySearchParameters(func);
106+
var response = await _client.ExecuteAsync<ApiResponse<BrCosmeticV2>>(request, token).ConfigureAwait(false);
107+
return response.Data;
108+
}
109+
110+
public ApiResponse<BrCosmeticV2> SearchBr(Action<BrCosmeticV2SearchProperties> func)
111+
{
112+
return SearchBrAsync(func).GetAwaiter().GetResult();
113+
}
114+
115+
public async Task<ApiResponse<List<BrCosmeticV2>>> SearchAllBrAsync(Action<BrCosmeticV2SearchProperties> func, CancellationToken token = default)
116+
{
117+
if (func == null)
118+
{
119+
throw new ArgumentNullException(nameof(func));
120+
}
121+
122+
var request = new RestRequest("v2/cosmetics/br/search/all", Method.GET).ApplySearchParameters(func);
123+
var response = await _client.ExecuteAsync<ApiResponse<List<BrCosmeticV2>>>(request, token).ConfigureAwait(false);
124+
return response.Data;
125+
}
126+
127+
public ApiResponse<List<BrCosmeticV2>> SearchAll(Action<BrCosmeticV2SearchProperties> func)
128+
{
129+
return SearchAllBrAsync(func).GetAwaiter().GetResult();
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)