Skip to content

Commit a5f0768

Browse files
Automatically update Dotnet SDK
1 parent 215e5b5 commit a5f0768

21 files changed

Lines changed: 969 additions & 13 deletions

src/TrophyApi.sln

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi", "TrophyApi\TrophyApi.csproj", "{0BD6B80D-737C-4D22-B40D-EB58A0EE64AD}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi", "TrophyApi\TrophyApi.csproj", "{7E391D9B-5A9D-486F-9A93-49673554DD78}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{11B58045-2083-4FC1-A364-BC4DC3C1DF9C}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{30C55E2A-E4FA-43E1-A093-CE8FE34C6B26}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -16,13 +16,13 @@ Global
1616
HideSolutionNode = FALSE
1717
EndGlobalSection
1818
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19-
{0BD6B80D-737C-4D22-B40D-EB58A0EE64AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20-
{0BD6B80D-737C-4D22-B40D-EB58A0EE64AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
21-
{0BD6B80D-737C-4D22-B40D-EB58A0EE64AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
22-
{0BD6B80D-737C-4D22-B40D-EB58A0EE64AD}.Release|Any CPU.Build.0 = Release|Any CPU
23-
{11B58045-2083-4FC1-A364-BC4DC3C1DF9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24-
{11B58045-2083-4FC1-A364-BC4DC3C1DF9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
25-
{11B58045-2083-4FC1-A364-BC4DC3C1DF9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
26-
{11B58045-2083-4FC1-A364-BC4DC3C1DF9C}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{7E391D9B-5A9D-486F-9A93-49673554DD78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{7E391D9B-5A9D-486F-9A93-49673554DD78}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{7E391D9B-5A9D-486F-9A93-49673554DD78}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{7E391D9B-5A9D-486F-9A93-49673554DD78}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{30C55E2A-E4FA-43E1-A093-CE8FE34C6B26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{30C55E2A-E4FA-43E1-A093-CE8FE34C6B26}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{30C55E2A-E4FA-43E1-A093-CE8FE34C6B26}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{30C55E2A-E4FA-43E1-A093-CE8FE34C6B26}.Release|Any CPU.Build.0 = Release|Any CPU
2727
EndGlobalSection
2828
EndGlobal

src/TrophyApi/Admin/AdminClient.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using TrophyApi.Admin.Streaks;
21
using TrophyApi.Core;
32

43
namespace TrophyApi.Admin;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Text.Json.Serialization;
2+
using TrophyApi.Core;
3+
4+
namespace TrophyApi.Admin;
5+
6+
[Serializable]
7+
public record RestoreStreaksRequest
8+
{
9+
/// <summary>
10+
/// Array of user IDs to restore streaks for. Maximum 100 users per request.
11+
/// </summary>
12+
[JsonPropertyName("userIds")]
13+
public IEnumerable<string> UserIds { get; set; } = new List<string>();
14+
15+
/// <inheritdoc />
16+
public override string ToString()
17+
{
18+
return JsonUtils.Serialize(this);
19+
}
20+
}

src/TrophyApi/Admin/Streaks/StreaksClient.cs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
using System.Net.Http;
2+
using System.Text.Json;
3+
using System.Threading;
4+
using TrophyApi;
5+
using TrophyApi.Admin.Streaks;
16
using TrophyApi.Core;
27

3-
namespace TrophyApi.Admin.Streaks;
8+
namespace TrophyApi.Admin;
49

510
public partial class StreaksClient
611
{
@@ -13,4 +18,76 @@ internal StreaksClient(RawClient client)
1318
}
1419

1520
public FreezesClient Freezes { get; }
21+
22+
/// <summary>
23+
/// Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks).
24+
/// </summary>
25+
/// <example><code>
26+
/// await client.Admin.Streaks.RestoreAsync(
27+
/// new RestoreStreaksRequest
28+
/// {
29+
/// UserIds = new List&lt;string&gt;() { "user-123", "user-456" },
30+
/// }
31+
/// );
32+
/// </code></example>
33+
public async Task<RestoreStreaksResponse> RestoreAsync(
34+
RestoreStreaksRequest request,
35+
RequestOptions? options = null,
36+
CancellationToken cancellationToken = default
37+
)
38+
{
39+
var response = await _client
40+
.SendRequestAsync(
41+
new JsonRequest
42+
{
43+
BaseUrl = _client.Options.Environment.Admin,
44+
Method = HttpMethod.Post,
45+
Path = "streaks/restore",
46+
Body = request,
47+
ContentType = "application/json",
48+
Options = options,
49+
},
50+
cancellationToken
51+
)
52+
.ConfigureAwait(false);
53+
if (response.StatusCode is >= 200 and < 400)
54+
{
55+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
56+
try
57+
{
58+
return JsonUtils.Deserialize<RestoreStreaksResponse>(responseBody)!;
59+
}
60+
catch (JsonException e)
61+
{
62+
throw new TrophyApiException("Failed to deserialize response", e);
63+
}
64+
}
65+
66+
{
67+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
68+
try
69+
{
70+
switch (response.StatusCode)
71+
{
72+
case 400:
73+
throw new BadRequestError(JsonUtils.Deserialize<ErrorBody>(responseBody));
74+
case 401:
75+
throw new UnauthorizedError(JsonUtils.Deserialize<ErrorBody>(responseBody));
76+
case 422:
77+
throw new UnprocessableEntityError(
78+
JsonUtils.Deserialize<ErrorBody>(responseBody)
79+
);
80+
}
81+
}
82+
catch (JsonException)
83+
{
84+
// unable to map error response, throwing generic error
85+
}
86+
throw new TrophyApiApiException(
87+
$"Error with status code {response.StatusCode}",
88+
response.StatusCode,
89+
responseBody
90+
);
91+
}
92+
}
1693
}

src/TrophyApi/TrophyApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<!-- 🔹 NuGet Metadata -->
1111
<PackageId>Trophy</PackageId>
12-
<Version>1.0.36</Version>
12+
<Version>1.0.38</Version>
1313
<Authors>Trophy Labs, Inc</Authors>
1414
<Description>.NET SDK for the Trophy API</Description>
1515
<PackageTags>trophy; api; gamification; sdk</PackageTags>

src/TrophyApi/Types/AchievementCompletionResponseAchievement.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ public record AchievementCompletionResponseAchievement
1919
[JsonPropertyName("achievedAt")]
2020
public DateTime? AchievedAt { get; set; }
2121

22+
/// <summary>
23+
/// The number of users who have completed this achievement.
24+
/// </summary>
25+
[JsonPropertyName("completions")]
26+
public required int Completions { get; set; }
27+
28+
/// <summary>
29+
/// The percentage of all users who have completed this achievement.
30+
/// </summary>
31+
[JsonPropertyName("rarity")]
32+
public required double Rarity { get; set; }
33+
34+
/// <summary>
35+
/// User attribute filters that must be met for this achievement to be completed. Only present if the achievement has user attribute filters configured.
36+
/// </summary>
37+
[JsonPropertyName("userAttributes")]
38+
public IEnumerable<AchievementWithStatsResponseUserAttributesItem>? UserAttributes { get; set; }
39+
40+
/// <summary>
41+
/// Event attribute filter that must be met for this achievement to be completed. Only present if the achievement has an event filter configured.
42+
/// </summary>
43+
[JsonPropertyName("eventAttribute")]
44+
public AchievementWithStatsResponseEventAttribute? EventAttribute { get; set; }
45+
2246
/// <summary>
2347
/// The unique ID of the achievement.
2448
/// </summary>

src/TrophyApi/Types/CompletedAchievementResponse.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ public record CompletedAchievementResponse
1313
[JsonPropertyName("achievedAt")]
1414
public DateTime? AchievedAt { get; set; }
1515

16+
/// <summary>
17+
/// The number of users who have completed this achievement.
18+
/// </summary>
19+
[JsonPropertyName("completions")]
20+
public required int Completions { get; set; }
21+
22+
/// <summary>
23+
/// The percentage of all users who have completed this achievement.
24+
/// </summary>
25+
[JsonPropertyName("rarity")]
26+
public required double Rarity { get; set; }
27+
28+
/// <summary>
29+
/// User attribute filters that must be met for this achievement to be completed. Only present if the achievement has user attribute filters configured.
30+
/// </summary>
31+
[JsonPropertyName("userAttributes")]
32+
public IEnumerable<AchievementWithStatsResponseUserAttributesItem>? UserAttributes { get; set; }
33+
34+
/// <summary>
35+
/// Event attribute filter that must be met for this achievement to be completed. Only present if the achievement has an event filter configured.
36+
/// </summary>
37+
[JsonPropertyName("eventAttribute")]
38+
public AchievementWithStatsResponseEventAttribute? EventAttribute { get; set; }
39+
1640
/// <summary>
1741
/// The unique ID of the achievement.
1842
/// </summary>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using TrophyApi.Core;
4+
5+
namespace TrophyApi;
6+
7+
/// <summary>
8+
/// Response containing restored users and any issues encountered.
9+
/// </summary>
10+
[Serializable]
11+
public record RestoreStreaksResponse
12+
{
13+
/// <summary>
14+
/// Array of user IDs whose streaks were successfully restored.
15+
/// </summary>
16+
[JsonPropertyName("restoredUsers")]
17+
public IEnumerable<string> RestoredUsers { get; set; } = new List<string>();
18+
19+
/// <summary>
20+
/// Array of issues encountered during streak restoration.
21+
/// </summary>
22+
[JsonPropertyName("issues")]
23+
public IEnumerable<BulkInsertIssue> Issues { get; set; } = new List<BulkInsertIssue>();
24+
25+
/// <summary>
26+
/// Additional properties received from the response, if any.
27+
/// </summary>
28+
/// <remarks>
29+
/// [EXPERIMENTAL] This API is experimental and may change in future releases.
30+
/// </remarks>
31+
[JsonExtensionData]
32+
public IDictionary<string, JsonElement> AdditionalProperties { get; internal set; } =
33+
new Dictionary<string, JsonElement>();
34+
35+
/// <inheritdoc />
36+
public override string ToString()
37+
{
38+
return JsonUtils.Serialize(this);
39+
}
40+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using TrophyApi.Core;
4+
5+
namespace TrophyApi;
6+
7+
/// <summary>
8+
/// The user's activity summary for the wrapped year.
9+
/// </summary>
10+
[Serializable]
11+
public record WrappedActivity
12+
{
13+
/// <summary>
14+
/// The number of days the user was active during the year.
15+
/// </summary>
16+
[JsonPropertyName("daysActive")]
17+
public required int DaysActive { get; set; }
18+
19+
/// <summary>
20+
/// The number of weeks the user was active during the year.
21+
/// </summary>
22+
[JsonPropertyName("weeksActive")]
23+
public required int WeeksActive { get; set; }
24+
25+
/// <summary>
26+
/// The number of months the user was active during the year.
27+
/// </summary>
28+
[JsonPropertyName("monthsActive")]
29+
public required int MonthsActive { get; set; }
30+
31+
/// <summary>
32+
/// Data about the user's most active day.
33+
/// </summary>
34+
[JsonPropertyName("mostActiveDay")]
35+
public required WrappedMostActiveDay MostActiveDay { get; set; }
36+
37+
/// <summary>
38+
/// Data about the user's most active week.
39+
/// </summary>
40+
[JsonPropertyName("mostActiveWeek")]
41+
public required WrappedMostActiveWeek MostActiveWeek { get; set; }
42+
43+
/// <summary>
44+
/// Data about the user's most active month.
45+
/// </summary>
46+
[JsonPropertyName("mostActiveMonth")]
47+
public required WrappedMostActiveMonth MostActiveMonth { get; set; }
48+
49+
/// <summary>
50+
/// Data about the user's activity for the entire year.
51+
/// </summary>
52+
[JsonPropertyName("entireYear")]
53+
public required WrappedEntireYear EntireYear { get; set; }
54+
55+
/// <summary>
56+
/// Additional properties received from the response, if any.
57+
/// </summary>
58+
/// <remarks>
59+
/// [EXPERIMENTAL] This API is experimental and may change in future releases.
60+
/// </remarks>
61+
[JsonExtensionData]
62+
public IDictionary<string, JsonElement> AdditionalProperties { get; internal set; } =
63+
new Dictionary<string, JsonElement>();
64+
65+
/// <inheritdoc />
66+
public override string ToString()
67+
{
68+
return JsonUtils.Serialize(this);
69+
}
70+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using TrophyApi.Core;
4+
5+
namespace TrophyApi;
6+
7+
/// <summary>
8+
/// Activity data for a specific period (day, week, month, or year).
9+
/// </summary>
10+
[Serializable]
11+
public record WrappedActivityPeriod
12+
{
13+
/// <summary>
14+
/// The user's metrics during this period, keyed by metric key.
15+
/// </summary>
16+
[JsonPropertyName("metrics")]
17+
public Dictionary<string, WrappedMetric> Metrics { get; set; } =
18+
new Dictionary<string, WrappedMetric>();
19+
20+
/// <summary>
21+
/// The user's points during this period, keyed by points system key.
22+
/// </summary>
23+
[JsonPropertyName("points")]
24+
public Dictionary<string, WrappedPoints> Points { get; set; } =
25+
new Dictionary<string, WrappedPoints>();
26+
27+
/// <summary>
28+
/// Achievements completed during this period.
29+
/// </summary>
30+
[JsonPropertyName("achievements")]
31+
public IEnumerable<CompletedAchievementResponse> Achievements { get; set; } =
32+
new List<CompletedAchievementResponse>();
33+
34+
/// <summary>
35+
/// The user's best leaderboard rankings during this period, keyed by leaderboard key.
36+
/// </summary>
37+
[JsonPropertyName("leaderboards")]
38+
public Dictionary<string, UserLeaderboardResponse> Leaderboards { get; set; } =
39+
new Dictionary<string, UserLeaderboardResponse>();
40+
41+
/// <summary>
42+
/// Additional properties received from the response, if any.
43+
/// </summary>
44+
/// <remarks>
45+
/// [EXPERIMENTAL] This API is experimental and may change in future releases.
46+
/// </remarks>
47+
[JsonExtensionData]
48+
public IDictionary<string, JsonElement> AdditionalProperties { get; internal set; } =
49+
new Dictionary<string, JsonElement>();
50+
51+
/// <inheritdoc />
52+
public override string ToString()
53+
{
54+
return JsonUtils.Serialize(this);
55+
}
56+
}

0 commit comments

Comments
 (0)