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

Commit df17eab

Browse files
author
Not Officer
committed
api-key requirement
1 parent 5110275 commit df17eab

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/Fortnite-API/FortniteApi.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using System;
2+
using System.Reflection;
23

34
using Fortnite_API.Endpoints;
45

@@ -13,20 +14,29 @@ public class FortniteApi
1314
public ShopEndpoints Shop { get; }
1415
public NewsEndpoints News { get; }
1516

16-
public FortniteApi(string apiKey = null)
17+
public FortniteApi(string apiKey)
1718
{
19+
if (apiKey == null)
20+
{
21+
throw new ArgumentNullException(nameof(apiKey));
22+
}
23+
24+
if (apiKey.Length == 0)
25+
{
26+
throw new ArgumentOutOfRangeException(nameof(apiKey));
27+
}
28+
1829
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
1930
var _client = new RestClient("https://fortnite-api.com/")
2031
{
2132
UserAgent = $"Fortnite-API.NET/{currentVersion.ToString(3)}",
22-
Timeout = 10 * 1000
33+
Timeout = 10 * 1000,
34+
DefaultParameters =
35+
{
36+
new Parameter("x-api-key", apiKey, ParameterType.HttpHeader)
37+
}
2338
}.UseSerializer<JsonNetSerializer>();
2439

25-
if (!string.IsNullOrWhiteSpace(apiKey))
26-
{
27-
_client.DefaultParameters.Add(new Parameter("x-api-key", apiKey, ParameterType.HttpHeader));
28-
}
29-
3040
Cosmetics = new CosmeticsEndpoints(_client);
3141
Shop = new ShopEndpoints(_client);
3242
News = new NewsEndpoints(_client);

0 commit comments

Comments
 (0)