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

Commit ca30c64

Browse files
author
Not Officer
committed
implemented v1 playlist endpoints
1 parent df943db commit ca30c64

File tree

9 files changed

+241
-22
lines changed

9 files changed

+241
-22
lines changed

logo.png

405 KB
Loading

src/Fortnite-API.Test/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ private static async Task Main()
1515
const string apiKey = null; // optional as of now. check https://dash.fortnite-api.com to be sure
1616
var api = new FortniteApi(apiKey);
1717

18+
var playlistsV1 = await api.V1.Playlists.GetAsync();
19+
var playlistSoloV1 = await api.V1.Playlists.GetAsync("playlist_defaultsolo");
20+
21+
Debugger.Break();
22+
return;
23+
1824
//var cosmeticsV2 = await api.V2.Cosmetics.GetBrAsync();
1925
var renegadeSearch = await api.V2.Cosmetics.SearchBrAsync(x =>
2026
{
@@ -44,9 +50,6 @@ private static async Task Main()
4450
x.ImagePlatform = BrStatsV2V1ImagePlatform.All;
4551
});
4652

47-
Debugger.Break();
48-
return;
49-
5053
var aes = await api.V1.Aes.GetAsync();
5154
await Task.Delay(500);
5255
var tfueCode = await api.V1.CreatorCode.GetAsync("tfue");
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections.Generic;
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 PlaylistsV1Endpoint : EndpointBase
13+
{
14+
internal PlaylistsV1Endpoint(IRestClient client) : base(client) { }
15+
16+
public async Task<ApiResponse<List<PlaylistV1>>> GetAsync(GameLanguage? language = null, CancellationToken token = default)
17+
{
18+
var request = new RestRequest("v1/playlists", Method.GET);
19+
20+
if (language.HasValue)
21+
{
22+
request.AddQueryParameter("language", language.Value.GetLanguageCode());
23+
}
24+
25+
var response = await _client.ExecuteAsync<ApiResponse<List<PlaylistV1>>>(request, token).ConfigureAwait(false);
26+
return response.Data;
27+
}
28+
29+
public ApiResponse<List<PlaylistV1>> Get(GameLanguage? language = null)
30+
{
31+
return GetAsync(language).GetAwaiter().GetResult();
32+
}
33+
34+
public async Task<ApiResponse<PlaylistV1>> GetAsync(string playlistId, GameLanguage? language = null, CancellationToken token = default)
35+
{
36+
var request = new RestRequest($"v1/playlists/{playlistId}", Method.GET);
37+
38+
if (language.HasValue)
39+
{
40+
request.AddQueryParameter("language", language.Value.GetLanguageCode());
41+
}
42+
43+
var response = await _client.ExecuteAsync<ApiResponse<PlaylistV1>>(request, token).ConfigureAwait(false);
44+
return response.Data;
45+
}
46+
47+
public ApiResponse<PlaylistV1> Get(string playlistId, GameLanguage? language = null)
48+
{
49+
return GetAsync(playlistId, language).GetAwaiter().GetResult();
50+
}
51+
}
52+
}

src/Fortnite-API/Endpoints/V1/V1Endpoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class V1Endpoints
1010
public CreatorcodeV1Endpoints CreatorCode { get; }
1111
public AesV1Endpoints Aes { get; }
1212
public StatsV1Endpoints Stats { get; }
13+
public PlaylistsV1Endpoint Playlists { get; }
1314

1415
internal V1Endpoints(IRestClient client)
1516
{
@@ -19,6 +20,7 @@ internal V1Endpoints(IRestClient client)
1920
CreatorCode = new CreatorcodeV1Endpoints(client);
2021
Aes = new AesV1Endpoints(client);
2122
Stats = new StatsV1Endpoints(client);
23+
Playlists = new PlaylistsV1Endpoint(client);
2224
}
2325
}
2426
}

src/Fortnite-API/Fortnite-API.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.1;net452;net452;net472;net48</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.1;net452;net452;net472;net48;netcoreapp3.1</TargetFrameworks>
55
<RootNamespace>Fortnite_API</RootNamespace>
66
<Description>C# wrapper for https://fortnite-api.com</Description>
77
<PackageId>Fortnite-API-Wrapper</PackageId>
@@ -14,15 +14,15 @@
1414
<PackageLicenseExpression></PackageLicenseExpression>
1515
<Authors>Fortnite-API, NotOfficer</Authors>
1616
<PackageLicenseFile>LICENSE</PackageLicenseFile>
17-
<Version>2.0.1</Version>
17+
<Version>2.1.0</Version>
1818
<Company>Fortnite-API</Company>
1919
<PackageIconUrl></PackageIconUrl>
2020
<RepositoryType>git</RepositoryType>
2121
<Copyright>Copyright (c) 2019-2020 Fortnite-API.com</Copyright>
22-
<AssemblyVersion>2.0.1.0</AssemblyVersion>
23-
<FileVersion>2.0.1.0</FileVersion>
22+
<AssemblyVersion>2.1.0.0</AssemblyVersion>
23+
<FileVersion>2.1.0.0</FileVersion>
2424
<PackageIcon>logo.png</PackageIcon>
25-
<PackageReleaseNotes></PackageReleaseNotes>
25+
<PackageReleaseNotes>added v1 playlists endpoint</PackageReleaseNotes>
2626
</PropertyGroup>
2727

2828
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -39,7 +39,7 @@
3939

4040
<ItemGroup>
4141
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
42-
<PackageReference Include="RestSharp" Version="106.11.4" />
42+
<PackageReference Include="RestSharp" Version="106.11.7" />
4343
</ItemGroup>
4444

4545
<ItemGroup>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
5+
using I = Newtonsoft.Json.JsonIgnoreAttribute;
6+
using J = Newtonsoft.Json.JsonPropertyAttribute;
7+
8+
namespace Fortnite_API.Objects.V1
9+
{
10+
[DebuggerDisplay("{" + nameof(Id) + "}")]
11+
public class PlaylistV1 : IEquatable<PlaylistV1>
12+
{
13+
[J] public string Id { get; private set; }
14+
[J] public string Name { get; private set; }
15+
[J] public string SubName { get; private set; }
16+
[J] public string Description { get; private set; }
17+
[J] public string GameType { get; private set; }
18+
[J] public int MinPlayers { get; private set; }
19+
[J] public int MaxPlayers { get; private set; }
20+
[J] public int MaxTeams { get; private set; }
21+
[J] public int MaxTeamSize { get; private set; }
22+
[J] public int MaxSquads { get; private set; }
23+
[J] public int MaxSquadSize { get; private set; }
24+
[J] public bool IsDefault { get; private set; }
25+
[J] public bool IsTournament { get; private set; }
26+
[J] public bool IsLimitedTimeMode { get; private set; }
27+
[J] public bool IsLargeTeamGame { get; private set; }
28+
[J] public bool AccumulateToProfileStats { get; private set; }
29+
[J] public PlaylistV1Images Images { get; private set; }
30+
[J] public List<string> GameplayTags { get; private set; }
31+
[J] public string Path { get; private set; }
32+
[J] public DateTime Added { get; private set; }
33+
34+
[I] public bool HasGameplayTags => GameplayTags != null && GameplayTags.Count != 0;
35+
36+
public bool Equals(PlaylistV1 other)
37+
{
38+
if (ReferenceEquals(null, other))
39+
{
40+
return false;
41+
}
42+
43+
if (ReferenceEquals(this, other))
44+
{
45+
return true;
46+
}
47+
48+
return Id == other.Id && Path == other.Path && Added.Equals(other.Added);
49+
}
50+
51+
public override bool Equals(object obj)
52+
{
53+
if (ReferenceEquals(null, obj))
54+
{
55+
return false;
56+
}
57+
58+
if (ReferenceEquals(this, obj))
59+
{
60+
return true;
61+
}
62+
63+
if (obj.GetType() != GetType())
64+
{
65+
return false;
66+
}
67+
68+
return Equals((PlaylistV1)obj);
69+
}
70+
71+
public override int GetHashCode()
72+
{
73+
unchecked
74+
{
75+
var hashCode = Id.GetHashCode();
76+
hashCode = hashCode * 397 ^ Path.GetHashCode();
77+
hashCode = hashCode * 397 ^ Added.GetHashCode();
78+
return hashCode;
79+
}
80+
}
81+
82+
public static bool operator ==(PlaylistV1 left, PlaylistV1 right)
83+
{
84+
return Equals(left, right);
85+
}
86+
87+
public static bool operator !=(PlaylistV1 left, PlaylistV1 right)
88+
{
89+
return !Equals(left, right);
90+
}
91+
}
92+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
3+
using I = Newtonsoft.Json.JsonIgnoreAttribute;
4+
using J = Newtonsoft.Json.JsonPropertyAttribute;
5+
6+
namespace Fortnite_API.Objects.V1
7+
{
8+
public class PlaylistV1Images : IEquatable<PlaylistV1Images>
9+
{
10+
[J] public Uri Showcase { get; private set; }
11+
[J] public Uri MissionIcon { get; private set; }
12+
13+
[I] public bool HasShowcase => Showcase != null;
14+
[I] public bool HasMissionIcon => MissionIcon != null;
15+
16+
public bool Equals(PlaylistV1Images other)
17+
{
18+
if (ReferenceEquals(null, other))
19+
{
20+
return false;
21+
}
22+
23+
if (ReferenceEquals(this, other))
24+
{
25+
return true;
26+
}
27+
28+
return Equals(Showcase, other.Showcase) && Equals(MissionIcon, other.MissionIcon);
29+
}
30+
31+
public override bool Equals(object obj)
32+
{
33+
if (ReferenceEquals(null, obj))
34+
{
35+
return false;
36+
}
37+
38+
if (ReferenceEquals(this, obj))
39+
{
40+
return true;
41+
}
42+
43+
if (obj.GetType() != GetType())
44+
{
45+
return false;
46+
}
47+
48+
return Equals((PlaylistV1Images)obj);
49+
}
50+
51+
public override int GetHashCode()
52+
{
53+
unchecked
54+
{
55+
return (Showcase != null ? Showcase.GetHashCode() : 0) * 397 ^ (MissionIcon != null ? MissionIcon.GetHashCode() : 0);
56+
}
57+
}
58+
59+
public static bool operator ==(PlaylistV1Images left, PlaylistV1Images right)
60+
{
61+
return Equals(left, right);
62+
}
63+
64+
public static bool operator !=(PlaylistV1Images left, PlaylistV1Images right)
65+
{
66+
return !Equals(left, right);
67+
}
68+
}
69+
}

src/Fortnite-API/Objects/V2/BrCosmeticV2.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ [J] public string ShowcaseVideo
3636
[J] public DateTime Added { get; private set; }
3737
[J] public List<DateTime> ShopHistory { get; private set; }
3838

39-
public bool HasSeries => Series != null;
40-
public bool HasSet => Set != null;
41-
public bool HasIntroduction => Introduction != null;
42-
public bool HasVariants => Variants != null && Variants.Count != 0;
43-
public bool HasGameplayTags => GameplayTags != null && GameplayTags.Count != 0;
44-
public bool HasShowcaseVideo => ShowcaseVideo != null;
45-
public bool HasDisplayAssetPath => DisplayAssetPath != null;
46-
public bool HasDefinitionPath => DefinitionPath != null;
47-
public bool HasShopHistory => ShopHistory != null;
39+
[I] public bool HasSeries => Series != null;
40+
[I] public bool HasSet => Set != null;
41+
[I] public bool HasIntroduction => Introduction != null;
42+
[I] public bool HasVariants => Variants != null && Variants.Count != 0;
43+
[I] public bool HasGameplayTags => GameplayTags != null && GameplayTags.Count != 0;
44+
[I] public bool HasShowcaseVideo => ShowcaseVideo != null;
45+
[I] public bool HasDisplayAssetPath => DisplayAssetPath != null;
46+
[I] public bool HasDefinitionPath => DefinitionPath != null;
47+
[I] public bool HasShopHistory => ShopHistory != null;
4848

4949
public bool Equals(BrCosmeticV2 other)
5050
{

src/Fortnite-API/Objects/V2/BrCosmeticV2Images.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33

4+
using I = Newtonsoft.Json.JsonIgnoreAttribute;
45
using J = Newtonsoft.Json.JsonPropertyAttribute;
56

67
namespace Fortnite_API.Objects.V2
@@ -12,10 +13,10 @@ public class BrCosmeticV2Images : IEquatable<BrCosmeticV2Images>
1213
[J] public Uri Featured { get; private set; }
1314
[J] public Dictionary<string, Uri> Other { get; private set; }
1415

15-
public bool HasSmallIcon => SmallIcon != null;
16-
public bool HasIcon => Icon != null;
17-
public bool HasFeatured => Featured != null;
18-
public bool HasOther => Other != null && Other.Count != 0;
16+
[I] public bool HasSmallIcon => SmallIcon != null;
17+
[I] public bool HasIcon => Icon != null;
18+
[I] public bool HasFeatured => Featured != null;
19+
[I] public bool HasOther => Other != null && Other.Count != 0;
1920
public Uri Get(bool useFeatured = true)
2021
{
2122
return useFeatured && HasFeatured ? Featured : Icon ?? SmallIcon;

0 commit comments

Comments
 (0)