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

Commit 0efbb7b

Browse files
author
Not Officer
committed
implemented '/creatorcode' endpoint
1 parent 7f11bde commit 0efbb7b

File tree

4 files changed

+185
-1
lines changed

4 files changed

+185
-1
lines changed

src/Fortnite-API.Test/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ internal class Program
99
{
1010
private static async Task Main()
1111
{
12-
var api = new FortniteApi();
12+
const string apiKey = "api-key";
13+
var api = new FortniteApi(apiKey);
1314

1415
var cosmetics = await api.Cosmetics.GetBrAsync(GameLanguage.DE);
1516
await Task.Delay(500);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 CreatorcodeEndpoints
13+
{
14+
private readonly IRestClient _client;
15+
16+
internal CreatorcodeEndpoints(IRestClient client)
17+
{
18+
_client = client;
19+
}
20+
21+
public async Task<ApiResponse<CreatorCode>> GetAsync(string slug, CancellationToken token = default)
22+
{
23+
if (slug == null)
24+
{
25+
throw new ArgumentNullException(nameof(slug));
26+
}
27+
28+
if (slug.Length == 0)
29+
{
30+
throw new ArgumentOutOfRangeException(nameof(slug));
31+
}
32+
33+
var request = new RestRequest("/creatorcode", Method.GET)
34+
{
35+
Parameters =
36+
{
37+
new Parameter("slug", slug, ParameterType.QueryString)
38+
}
39+
};
40+
41+
var response = await _client.ExecuteTaskAsync<ApiResponse<CreatorCode>>(request, token).ConfigureAwait(false);
42+
return response.Data;
43+
}
44+
45+
public ApiResponse<CreatorCode> Get(string slug)
46+
{
47+
return GetAsync(slug).GetAwaiter().GetResult();
48+
}
49+
50+
public async Task<ApiResponse<CreatorCode>> SearchAsync(string slug, CancellationToken token = default)
51+
{
52+
if (slug == null)
53+
{
54+
throw new ArgumentNullException(nameof(slug));
55+
}
56+
57+
if (slug.Length == 0)
58+
{
59+
throw new ArgumentOutOfRangeException(nameof(slug));
60+
}
61+
62+
var request = new RestRequest("/creatorcode/search", Method.GET)
63+
{
64+
Parameters =
65+
{
66+
new Parameter("slug", slug, ParameterType.QueryString)
67+
}
68+
};
69+
70+
var response = await _client.ExecuteTaskAsync<ApiResponse<CreatorCode>>(request, token).ConfigureAwait(false);
71+
return response.Data;
72+
}
73+
74+
public ApiResponse<CreatorCode> Search(string slug)
75+
{
76+
return SearchAsync(slug).GetAwaiter().GetResult();
77+
}
78+
79+
public async Task<ApiResponse<List<CreatorCode>>> SearchAllAsync(string slug, CancellationToken token = default)
80+
{
81+
if (slug == null)
82+
{
83+
throw new ArgumentNullException(nameof(slug));
84+
}
85+
86+
if (slug.Length == 0)
87+
{
88+
throw new ArgumentOutOfRangeException(nameof(slug));
89+
}
90+
91+
var request = new RestRequest("/creatorcode/search/all", Method.GET)
92+
{
93+
Parameters =
94+
{
95+
new Parameter("slug", slug, ParameterType.QueryString)
96+
}
97+
};
98+
99+
var response = await _client.ExecuteTaskAsync<ApiResponse<List<CreatorCode>>>(request, token).ConfigureAwait(false);
100+
return response.Data;
101+
}
102+
103+
public ApiResponse<List<CreatorCode>> SearchAll(string slug)
104+
{
105+
return SearchAllAsync(slug).GetAwaiter().GetResult();
106+
}
107+
}
108+
}

src/Fortnite-API/FortniteApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class FortniteApi
1313
public CosmeticsEndpoints Cosmetics { get; }
1414
public ShopEndpoints Shop { get; }
1515
public NewsEndpoints News { get; }
16+
public CreatorcodeEndpoints CreatorCode { get; }
1617

1718
public FortniteApi(string apiKey)
1819
{
@@ -40,6 +41,7 @@ public FortniteApi(string apiKey)
4041
Cosmetics = new CosmeticsEndpoints(_client);
4142
Shop = new ShopEndpoints(_client);
4243
News = new NewsEndpoints(_client);
44+
CreatorCode = new CreatorcodeEndpoints(_client);
4345
}
4446
}
4547
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
3+
using J = Newtonsoft.Json.JsonPropertyAttribute;
4+
5+
namespace Fortnite_API.Objects
6+
{
7+
public class CreatorCode : IEquatable<CreatorCode>
8+
{
9+
[J("id")] public string Id { get; private set; }
10+
[J("slug")] public string Slug { get; private set; }
11+
[J("displayName")] public string DisplayName { get; private set; }
12+
[J("status")] public string Status { get; private set; }
13+
[J("verified")] public bool Verified { get; private set; }
14+
15+
public bool Equals(CreatorCode other)
16+
{
17+
if (ReferenceEquals(null, other))
18+
{
19+
return false;
20+
}
21+
22+
if (ReferenceEquals(this, other))
23+
{
24+
return true;
25+
}
26+
27+
return Id == other.Id && Slug == other.Slug && DisplayName == other.DisplayName && Status == other.Status && Verified == other.Verified;
28+
}
29+
30+
public override bool Equals(object obj)
31+
{
32+
if (ReferenceEquals(null, obj))
33+
{
34+
return false;
35+
}
36+
37+
if (ReferenceEquals(this, obj))
38+
{
39+
return true;
40+
}
41+
42+
if (obj is CreatorCode creatorCode)
43+
{
44+
return Equals(creatorCode);
45+
}
46+
47+
return false;
48+
}
49+
50+
public override int GetHashCode()
51+
{
52+
unchecked
53+
{
54+
var hashCode = Id.GetHashCode();
55+
hashCode = hashCode * 397 ^ Slug.GetHashCode();
56+
hashCode = hashCode * 397 ^ DisplayName.GetHashCode();
57+
hashCode = hashCode * 397 ^ Status.GetHashCode();
58+
hashCode = hashCode * 397 ^ Verified.GetHashCode();
59+
return hashCode;
60+
}
61+
}
62+
63+
public static bool operator ==(CreatorCode left, CreatorCode right)
64+
{
65+
return Equals(left, right);
66+
}
67+
68+
public static bool operator !=(CreatorCode left, CreatorCode right)
69+
{
70+
return !Equals(left, right);
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)