Skip to content

Commit edb6473

Browse files
feat(api): Add PopScore endpoints (#39)
* Add PopScore endpoints Co-authored-by: Kamran Ayub <[email protected]>
1 parent 5b625b3 commit edb6473

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

IGDB.Tests/PopScore.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using IGDB.Models;
5+
using Xunit;
6+
7+
namespace IGDB.Tests
8+
{
9+
public class PopScore
10+
{
11+
IGDBClient _api;
12+
13+
public PopScore()
14+
{
15+
_api = new IGDB.IGDBClient(
16+
Environment.GetEnvironmentVariable("IGDB_CLIENT_ID"),
17+
Environment.GetEnvironmentVariable("IGDB_CLIENT_SECRET")
18+
);
19+
}
20+
21+
[Fact]
22+
public async Task ShouldReturnAllPopularityTypes()
23+
{
24+
var popularityTypes = await _api.QueryAsync<PopularityType>(IGDBClient.Endpoints.PopularityTypes, "fields *;");
25+
26+
Assert.NotNull(popularityTypes);
27+
foreach (var popularityType in popularityTypes)
28+
{
29+
Assert.NotNull(popularityType.Checksum);
30+
Assert.NotNull(popularityType.CreatedAt);
31+
Assert.NotNull(popularityType.Name);
32+
Assert.NotNull(popularityType.ExternalPopularitySource.Id);
33+
Assert.NotNull(popularityType.UpdatedAt);
34+
}
35+
}
36+
37+
[Fact]
38+
public async Task ShouldReturnLimitedPopularityPrimitives()
39+
{
40+
var popularityPrimitives = await _api.QueryAsync<PopularityPrimitive>(
41+
IGDBClient.Endpoints.PopularityPrimitives,
42+
"fields *; limit 10;");
43+
44+
Assert.NotNull(popularityPrimitives);
45+
Assert.True(popularityPrimitives.Length == 10);
46+
47+
foreach (var popularityPrimitive in popularityPrimitives)
48+
{
49+
Assert.NotNull(popularityPrimitive.CalculatedAt);
50+
Assert.NotNull(popularityPrimitive.CreatedAt);
51+
Assert.NotNull(popularityPrimitive.ExternalPopularitySource.Id);
52+
Assert.NotNull(popularityPrimitive.PopularityType);
53+
Assert.NotNull(popularityPrimitive.UpdatedAt);
54+
Assert.NotNull(popularityPrimitive.Value);
55+
}
56+
}
57+
}
58+
}

IGDB/IGDBApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ public static class Endpoints
296296
public const string PlatformVersionReleaseDates = "platform_version_release_dates";
297297
public const string PlatformWebsites = "platform_websites";
298298
public const string PlayerPerspectives = "player_perspectives";
299+
public const string PopularityPrimitives = "popularity_primitives";
300+
public const string PopularityTypes = "popularity_types";
299301
public const string ReleaseDates = "release_dates";
300302
public const string ReleaseDateRegions = "release_date_regions";
301303
public const string Screenshots = "screenshots";

IGDB/Models/PopularityPrimitive.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace IGDB.Models
4+
{
5+
public class PopularityPrimitive : ITimestamps
6+
{
7+
public DateTimeOffset? CalculatedAt { get; set; }
8+
public DateTimeOffset? CreatedAt { get; set; }
9+
public long? GameId { get; set; }
10+
public IdentityOrValue<ExternalGameSource> ExternalPopularitySource { get; set; }
11+
public IdentityOrValue<PopularityType> PopularityType { get; set; }
12+
public DateTimeOffset? UpdatedAt { get; set; }
13+
public decimal? Value { get; set; }
14+
}
15+
}

IGDB/Models/PopularityType.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace IGDB.Models
4+
{
5+
public class PopularityType : ITimestamps, IHasChecksum
6+
{
7+
public string Checksum { get; set; }
8+
public DateTimeOffset? CreatedAt { get; set; }
9+
public string Name { get; set; }
10+
public IdentityOrValue<ExternalGameSource> ExternalPopularitySource { get; set; }
11+
public DateTimeOffset? UpdatedAt { get; set; }
12+
}
13+
}

0 commit comments

Comments
 (0)