This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented all V2 endpoints + minor refactoring
- Loading branch information
Not Officer
committed
Jul 5, 2020
1 parent
63ef26f
commit 1ff7442
Showing
68 changed files
with
3,377 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.V1 | ||
{ | ||
public class StatsV1Endpoints : EndpointBase | ||
{ | ||
internal StatsV1Endpoints(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($"v1/stats/br/v2/{props.AccountId.Value}", Method.GET); | ||
} | ||
else if (props.Name.HasValue) | ||
{ | ||
request = new RestRequest("v1/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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Fortnite_API.Objects; | ||
using Fortnite_API.Objects.V2; | ||
|
||
using RestSharp; | ||
|
||
namespace Fortnite_API.Endpoints.V2 | ||
{ | ||
public class AesV2Endpoints : EndpointBase | ||
{ | ||
internal AesV2Endpoints(IRestClient client) : base(client) { } | ||
|
||
public async Task<ApiResponse<AesV2>> GetAsync(AesV2KeyFormat? keyFormat = null, CancellationToken token = default) | ||
{ | ||
var request = new RestRequest("v2/aes", Method.GET); | ||
|
||
if (keyFormat.HasValue) | ||
{ | ||
request.AddQueryParameter("keyFormat", keyFormat.Value.GetString()); | ||
} | ||
|
||
var response = await _client.ExecuteAsync<ApiResponse<AesV2>>(request, token).ConfigureAwait(false); | ||
return response.Data; | ||
} | ||
|
||
public ApiResponse<AesV2> Get(AesV2KeyFormat? keyFormat = null) | ||
{ | ||
return GetAsync(keyFormat).GetAwaiter().GetResult(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Fortnite_API.Objects; | ||
using Fortnite_API.Objects.V2; | ||
|
||
using RestSharp; | ||
|
||
namespace Fortnite_API.Endpoints.V2 | ||
{ | ||
public class CosmeticsV2Endpoints : EndpointBase | ||
{ | ||
internal CosmeticsV2Endpoints(IRestClient client) : base(client) { } | ||
|
||
public async Task<ApiResponse<List<BrCosmeticV2>>> GetBrAsync(GameLanguage? language = null, CancellationToken token = default) | ||
{ | ||
var request = new RestRequest("v2/cosmetics/br", Method.GET); | ||
|
||
if (language.HasValue) | ||
{ | ||
request.AddQueryParameter("language", language.Value.GetLanguageCode()); | ||
} | ||
|
||
var response = await _client.ExecuteAsync<ApiResponse<List<BrCosmeticV2>>>(request, token).ConfigureAwait(false); | ||
return response.Data; | ||
} | ||
|
||
public ApiResponse<List<BrCosmeticV2>> GetBr(GameLanguage? language = null) | ||
{ | ||
return GetBrAsync(language).GetAwaiter().GetResult(); | ||
} | ||
|
||
public async Task<ApiResponse<BrCosmeticV2>> GetBrAsync(string cosmeticId, GameLanguage? language = null, CancellationToken token = default) | ||
{ | ||
if (cosmeticId == null) | ||
{ | ||
throw new ArgumentNullException(nameof(cosmeticId)); | ||
} | ||
|
||
if (cosmeticId.Length == 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(cosmeticId)); | ||
} | ||
|
||
var request = new RestRequest($"v2/cosmetics/br/{cosmeticId}", Method.GET); | ||
|
||
if (language.HasValue) | ||
{ | ||
request.AddQueryParameter("language", language.Value.GetLanguageCode()); | ||
} | ||
|
||
var response = await _client.ExecuteAsync<ApiResponse<BrCosmeticV2>>(request, token).ConfigureAwait(false); | ||
return response.Data; | ||
} | ||
|
||
public ApiResponse<BrCosmeticV2> GetBr(string cosmeticId, GameLanguage? language = null) | ||
{ | ||
return GetBrAsync(cosmeticId, language).GetAwaiter().GetResult(); | ||
} | ||
|
||
public async Task<ApiResponse<List<BrCosmeticV2>>> SearchBrIdsAsync(IEnumerable<string> cosmeticIds, GameLanguage? language = null, CancellationToken token = default) | ||
{ | ||
if (cosmeticIds == null) | ||
{ | ||
throw new ArgumentNullException(nameof(cosmeticIds)); | ||
} | ||
|
||
var request = new RestRequest("v2/cosmetics/br/search/ids", Method.GET); | ||
var isArrayEmpty = true; | ||
|
||
foreach (var cosmeticId in cosmeticIds) | ||
{ | ||
isArrayEmpty = false; | ||
request.AddQueryParameter("id", cosmeticId); | ||
} | ||
|
||
if (isArrayEmpty) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(cosmeticIds)); | ||
} | ||
|
||
if (language.HasValue) | ||
{ | ||
request.AddQueryParameter("language", language.Value.GetLanguageCode()); | ||
} | ||
|
||
var response = await _client.ExecuteAsync<ApiResponse<List<BrCosmeticV2>>>(request, token).ConfigureAwait(false); | ||
return response.Data; | ||
} | ||
|
||
public ApiResponse<List<BrCosmeticV2>> SearchBrIds(IEnumerable<string> cosmeticIds, GameLanguage? language = null) | ||
{ | ||
return SearchBrIdsAsync(cosmeticIds, language).GetAwaiter().GetResult(); | ||
} | ||
|
||
public async Task<ApiResponse<BrCosmeticV2>> SearchBrAsync(Action<BrCosmeticV2SearchProperties> func, CancellationToken token = default) | ||
{ | ||
if (func == null) | ||
{ | ||
throw new ArgumentNullException(nameof(func)); | ||
} | ||
|
||
var request = new RestRequest("v2/cosmetics/br/search", Method.GET).ApplySearchParameters(func); | ||
var response = await _client.ExecuteAsync<ApiResponse<BrCosmeticV2>>(request, token).ConfigureAwait(false); | ||
return response.Data; | ||
} | ||
|
||
public ApiResponse<BrCosmeticV2> SearchBr(Action<BrCosmeticV2SearchProperties> func) | ||
{ | ||
return SearchBrAsync(func).GetAwaiter().GetResult(); | ||
} | ||
|
||
public async Task<ApiResponse<List<BrCosmeticV2>>> SearchAllBrAsync(Action<BrCosmeticV2SearchProperties> func, CancellationToken token = default) | ||
{ | ||
if (func == null) | ||
{ | ||
throw new ArgumentNullException(nameof(func)); | ||
} | ||
|
||
var request = new RestRequest("v2/cosmetics/br/search/all", Method.GET).ApplySearchParameters(func); | ||
var response = await _client.ExecuteAsync<ApiResponse<List<BrCosmeticV2>>>(request, token).ConfigureAwait(false); | ||
return response.Data; | ||
} | ||
|
||
public ApiResponse<List<BrCosmeticV2>> SearchAll(Action<BrCosmeticV2SearchProperties> func) | ||
{ | ||
return SearchAllBrAsync(func).GetAwaiter().GetResult(); | ||
} | ||
} | ||
} |
Oops, something went wrong.