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

Commit

Permalink
implemented all V2 endpoints + minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Not Officer committed Jul 5, 2020
1 parent 63ef26f commit 1ff7442
Show file tree
Hide file tree
Showing 68 changed files with 3,377 additions and 131 deletions.
33 changes: 33 additions & 0 deletions src/Fortnite-API.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Fortnite_API;
using Fortnite_API.Objects;
using Fortnite_API.Objects.V1;
using Fortnite_API.Objects.V2;

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

//var cosmeticsV2 = await api.V2.Cosmetics.GetBrAsync();
var renegadeSearch = await api.V2.Cosmetics.SearchBrAsync(x =>
{
x.Name = "enegade raid";
x.MatchMethod = MatchMethod.Contains;
x.BackendType = "AthenaCharacter";
});

var aesV2 = await api.V2.Aes.GetAsync();
var aesV2Base64 = await api.V2.Aes.GetAsync(AesV2KeyFormat.Base64);

var newsV2 = await api.V2.News.GetAsync();
var newsV2German = await api.V2.News.GetAsync(GameLanguage.DE);
var newsV2Br = await api.V2.News.GetBrAsync();

var creatorCodeV2tfue = await api.V2.CreatorCode.GetAsync("tfue239042039480");
var creatorCodeV2allStw = await api.V2.CreatorCode.SearchAllAsync("stw");

var shopV2 = await api.V2.Shop.GetBrAsync();
var shopV2German = await api.V2.Shop.GetBrAsync(GameLanguage.DE);
var shopV2Combined = await api.V2.Shop.GetBrCombinedAsync();

var statsV2V1 = await api.V1.Stats.GetBrV2Async(x =>
{
//x.AccountId = "4735ce9132924caf8a5b17789b40f79c";
x.Name = "ninja";
x.ImagePlatform = BrStatsV2V1ImagePlatform.All;
});

Debugger.Break();
return;

var aes = await api.V1.Aes.GetAsync();
await Task.Delay(500);
var tfueCode = await api.V1.CreatorCode.GetAsync("tfue");
Expand Down
70 changes: 70 additions & 0 deletions src/Fortnite-API/Endpoints/V1/StatsV1Endpoints.cs
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();
}
}
}
2 changes: 2 additions & 0 deletions src/Fortnite-API/Endpoints/V1/V1Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class V1Endpoints
public NewsV1Endpoints News { get; }
public CreatorcodeV1Endpoints CreatorCode { get; }
public AesV1Endpoints Aes { get; }
public StatsV1Endpoints Stats { get; }

internal V1Endpoints(IRestClient client)
{
Expand All @@ -17,6 +18,7 @@ internal V1Endpoints(IRestClient client)
News = new NewsV1Endpoints(client);
CreatorCode = new CreatorcodeV1Endpoints(client);
Aes = new AesV1Endpoints(client);
Stats = new StatsV1Endpoints(client);
}
}
}
33 changes: 33 additions & 0 deletions src/Fortnite-API/Endpoints/V2/AesV2Endpoints.cs
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();
}
}
}
132 changes: 132 additions & 0 deletions src/Fortnite-API/Endpoints/V2/CosmeticsV2Endpoints.cs
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();
}
}
}
Loading

0 comments on commit 1ff7442

Please sign in to comment.