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

Commit

Permalink
implemented v1 playlist endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Not Officer committed Oct 10, 2020
1 parent df943db commit ca30c64
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 22 deletions.
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions src/Fortnite-API.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ 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 playlistsV1 = await api.V1.Playlists.GetAsync();
var playlistSoloV1 = await api.V1.Playlists.GetAsync("playlist_defaultsolo");

Debugger.Break();
return;

//var cosmeticsV2 = await api.V2.Cosmetics.GetBrAsync();
var renegadeSearch = await api.V2.Cosmetics.SearchBrAsync(x =>
{
Expand Down Expand Up @@ -44,9 +50,6 @@ private static async Task Main()
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
52 changes: 52 additions & 0 deletions src/Fortnite-API/Endpoints/V1/PlaylistsV1Endpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
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 PlaylistsV1Endpoint : EndpointBase
{
internal PlaylistsV1Endpoint(IRestClient client) : base(client) { }

public async Task<ApiResponse<List<PlaylistV1>>> GetAsync(GameLanguage? language = null, CancellationToken token = default)
{
var request = new RestRequest("v1/playlists", Method.GET);

if (language.HasValue)
{
request.AddQueryParameter("language", language.Value.GetLanguageCode());
}

var response = await _client.ExecuteAsync<ApiResponse<List<PlaylistV1>>>(request, token).ConfigureAwait(false);
return response.Data;
}

public ApiResponse<List<PlaylistV1>> Get(GameLanguage? language = null)
{
return GetAsync(language).GetAwaiter().GetResult();
}

public async Task<ApiResponse<PlaylistV1>> GetAsync(string playlistId, GameLanguage? language = null, CancellationToken token = default)
{
var request = new RestRequest($"v1/playlists/{playlistId}", Method.GET);

if (language.HasValue)
{
request.AddQueryParameter("language", language.Value.GetLanguageCode());
}

var response = await _client.ExecuteAsync<ApiResponse<PlaylistV1>>(request, token).ConfigureAwait(false);
return response.Data;
}

public ApiResponse<PlaylistV1> Get(string playlistId, GameLanguage? language = null)
{
return GetAsync(playlistId, language).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 @@ -10,6 +10,7 @@ public class V1Endpoints
public CreatorcodeV1Endpoints CreatorCode { get; }
public AesV1Endpoints Aes { get; }
public StatsV1Endpoints Stats { get; }
public PlaylistsV1Endpoint Playlists { get; }

internal V1Endpoints(IRestClient client)
{
Expand All @@ -19,6 +20,7 @@ internal V1Endpoints(IRestClient client)
CreatorCode = new CreatorcodeV1Endpoints(client);
Aes = new AesV1Endpoints(client);
Stats = new StatsV1Endpoints(client);
Playlists = new PlaylistsV1Endpoint(client);
}
}
}
12 changes: 6 additions & 6 deletions src/Fortnite-API/Fortnite-API.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net452;net452;net472;net48</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net452;net452;net472;net48;netcoreapp3.1</TargetFrameworks>
<RootNamespace>Fortnite_API</RootNamespace>
<Description>C# wrapper for https://fortnite-api.com</Description>
<PackageId>Fortnite-API-Wrapper</PackageId>
Expand All @@ -14,15 +14,15 @@
<PackageLicenseExpression></PackageLicenseExpression>
<Authors>Fortnite-API, NotOfficer</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>2.0.1</Version>
<Version>2.1.0</Version>
<Company>Fortnite-API</Company>
<PackageIconUrl></PackageIconUrl>
<RepositoryType>git</RepositoryType>
<Copyright>Copyright (c) 2019-2020 Fortnite-API.com</Copyright>
<AssemblyVersion>2.0.1.0</AssemblyVersion>
<FileVersion>2.0.1.0</FileVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<PackageIcon>logo.png</PackageIcon>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageReleaseNotes>added v1 playlists endpoint</PackageReleaseNotes>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RestSharp" Version="106.11.4" />
<PackageReference Include="RestSharp" Version="106.11.7" />
</ItemGroup>

<ItemGroup>
Expand Down
92 changes: 92 additions & 0 deletions src/Fortnite-API/Objects/V1/PlaylistV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

using I = Newtonsoft.Json.JsonIgnoreAttribute;
using J = Newtonsoft.Json.JsonPropertyAttribute;

namespace Fortnite_API.Objects.V1
{
[DebuggerDisplay("{" + nameof(Id) + "}")]
public class PlaylistV1 : IEquatable<PlaylistV1>
{
[J] public string Id { get; private set; }
[J] public string Name { get; private set; }
[J] public string SubName { get; private set; }
[J] public string Description { get; private set; }
[J] public string GameType { get; private set; }
[J] public int MinPlayers { get; private set; }
[J] public int MaxPlayers { get; private set; }
[J] public int MaxTeams { get; private set; }
[J] public int MaxTeamSize { get; private set; }
[J] public int MaxSquads { get; private set; }
[J] public int MaxSquadSize { get; private set; }
[J] public bool IsDefault { get; private set; }
[J] public bool IsTournament { get; private set; }
[J] public bool IsLimitedTimeMode { get; private set; }
[J] public bool IsLargeTeamGame { get; private set; }
[J] public bool AccumulateToProfileStats { get; private set; }
[J] public PlaylistV1Images Images { get; private set; }
[J] public List<string> GameplayTags { get; private set; }
[J] public string Path { get; private set; }
[J] public DateTime Added { get; private set; }

[I] public bool HasGameplayTags => GameplayTags != null && GameplayTags.Count != 0;

public bool Equals(PlaylistV1 other)
{
if (ReferenceEquals(null, other))
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return Id == other.Id && Path == other.Path && Added.Equals(other.Added);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((PlaylistV1)obj);
}

public override int GetHashCode()
{
unchecked
{
var hashCode = Id.GetHashCode();
hashCode = hashCode * 397 ^ Path.GetHashCode();
hashCode = hashCode * 397 ^ Added.GetHashCode();
return hashCode;
}
}

public static bool operator ==(PlaylistV1 left, PlaylistV1 right)
{
return Equals(left, right);
}

public static bool operator !=(PlaylistV1 left, PlaylistV1 right)
{
return !Equals(left, right);
}
}
}
69 changes: 69 additions & 0 deletions src/Fortnite-API/Objects/V1/PlaylistV1Images.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;

using I = Newtonsoft.Json.JsonIgnoreAttribute;
using J = Newtonsoft.Json.JsonPropertyAttribute;

namespace Fortnite_API.Objects.V1
{
public class PlaylistV1Images : IEquatable<PlaylistV1Images>
{
[J] public Uri Showcase { get; private set; }
[J] public Uri MissionIcon { get; private set; }

[I] public bool HasShowcase => Showcase != null;
[I] public bool HasMissionIcon => MissionIcon != null;

public bool Equals(PlaylistV1Images other)
{
if (ReferenceEquals(null, other))
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return Equals(Showcase, other.Showcase) && Equals(MissionIcon, other.MissionIcon);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((PlaylistV1Images)obj);
}

public override int GetHashCode()
{
unchecked
{
return (Showcase != null ? Showcase.GetHashCode() : 0) * 397 ^ (MissionIcon != null ? MissionIcon.GetHashCode() : 0);
}
}

public static bool operator ==(PlaylistV1Images left, PlaylistV1Images right)
{
return Equals(left, right);
}

public static bool operator !=(PlaylistV1Images left, PlaylistV1Images right)
{
return !Equals(left, right);
}
}
}
18 changes: 9 additions & 9 deletions src/Fortnite-API/Objects/V2/BrCosmeticV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ [J] public string ShowcaseVideo
[J] public DateTime Added { get; private set; }
[J] public List<DateTime> ShopHistory { get; private set; }

public bool HasSeries => Series != null;
public bool HasSet => Set != null;
public bool HasIntroduction => Introduction != null;
public bool HasVariants => Variants != null && Variants.Count != 0;
public bool HasGameplayTags => GameplayTags != null && GameplayTags.Count != 0;
public bool HasShowcaseVideo => ShowcaseVideo != null;
public bool HasDisplayAssetPath => DisplayAssetPath != null;
public bool HasDefinitionPath => DefinitionPath != null;
public bool HasShopHistory => ShopHistory != null;
[I] public bool HasSeries => Series != null;
[I] public bool HasSet => Set != null;
[I] public bool HasIntroduction => Introduction != null;
[I] public bool HasVariants => Variants != null && Variants.Count != 0;
[I] public bool HasGameplayTags => GameplayTags != null && GameplayTags.Count != 0;
[I] public bool HasShowcaseVideo => ShowcaseVideo != null;
[I] public bool HasDisplayAssetPath => DisplayAssetPath != null;
[I] public bool HasDefinitionPath => DefinitionPath != null;
[I] public bool HasShopHistory => ShopHistory != null;

public bool Equals(BrCosmeticV2 other)
{
Expand Down
9 changes: 5 additions & 4 deletions src/Fortnite-API/Objects/V2/BrCosmeticV2Images.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;

using I = Newtonsoft.Json.JsonIgnoreAttribute;
using J = Newtonsoft.Json.JsonPropertyAttribute;

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

public bool HasSmallIcon => SmallIcon != null;
public bool HasIcon => Icon != null;
public bool HasFeatured => Featured != null;
public bool HasOther => Other != null && Other.Count != 0;
[I] public bool HasSmallIcon => SmallIcon != null;
[I] public bool HasIcon => Icon != null;
[I] public bool HasFeatured => Featured != null;
[I] public bool HasOther => Other != null && Other.Count != 0;
public Uri Get(bool useFeatured = true)
{
return useFeatured && HasFeatured ? Featured : Icon ?? SmallIcon;
Expand Down

0 comments on commit ca30c64

Please sign in to comment.