Skip to content

Commit 03103a4

Browse files
Automatically update Dotnet SDK
1 parent dfc0009 commit 03103a4

10 files changed

Lines changed: 475 additions & 42 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", "{90DCDF52-396C-4033-832C-23C0CAA3D03B}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi", "TrophyApi\TrophyApi.csproj", "{908F274A-7409-48B0-A378-AD663AD96C5B}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{FD302654-5EB4-43DB-AF40-0ACB9279DB75}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{F701FD29-82A0-4A05-8767-1C12E372A04E}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -16,13 +16,13 @@ Global
1616
HideSolutionNode = FALSE
1717
EndGlobalSection
1818
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19-
{90DCDF52-396C-4033-832C-23C0CAA3D03B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20-
{90DCDF52-396C-4033-832C-23C0CAA3D03B}.Debug|Any CPU.Build.0 = Debug|Any CPU
21-
{90DCDF52-396C-4033-832C-23C0CAA3D03B}.Release|Any CPU.ActiveCfg = Release|Any CPU
22-
{90DCDF52-396C-4033-832C-23C0CAA3D03B}.Release|Any CPU.Build.0 = Release|Any CPU
23-
{FD302654-5EB4-43DB-AF40-0ACB9279DB75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24-
{FD302654-5EB4-43DB-AF40-0ACB9279DB75}.Debug|Any CPU.Build.0 = Debug|Any CPU
25-
{FD302654-5EB4-43DB-AF40-0ACB9279DB75}.Release|Any CPU.ActiveCfg = Release|Any CPU
26-
{FD302654-5EB4-43DB-AF40-0ACB9279DB75}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{908F274A-7409-48B0-A378-AD663AD96C5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{908F274A-7409-48B0-A378-AD663AD96C5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{908F274A-7409-48B0-A378-AD663AD96C5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{908F274A-7409-48B0-A378-AD663AD96C5B}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{F701FD29-82A0-4A05-8767-1C12E372A04E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{F701FD29-82A0-4A05-8767-1C12E372A04E}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{F701FD29-82A0-4A05-8767-1C12E372A04E}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{F701FD29-82A0-4A05-8767-1C12E372A04E}.Release|Any CPU.Build.0 = Release|Any CPU
2727
EndGlobalSection
2828
EndGlobal

src/TrophyApi/Points/PointsClient.cs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,138 @@ public async Task<IEnumerable<PointsBoost>> BoostsAsync(
226226
);
227227
}
228228
}
229+
230+
/// <summary>
231+
/// Get all levels for a points system.
232+
/// </summary>
233+
/// <example><code>
234+
/// await client.Points.LevelsAsync("points-system-key");
235+
/// </code></example>
236+
public async Task<IEnumerable<PointsLevel>> LevelsAsync(
237+
string key,
238+
RequestOptions? options = null,
239+
CancellationToken cancellationToken = default
240+
)
241+
{
242+
var response = await _client
243+
.SendRequestAsync(
244+
new JsonRequest
245+
{
246+
BaseUrl = _client.Options.Environment.Api,
247+
Method = HttpMethod.Get,
248+
Path = string.Format(
249+
"points/{0}/levels",
250+
ValueConvert.ToPathParameterString(key)
251+
),
252+
Options = options,
253+
},
254+
cancellationToken
255+
)
256+
.ConfigureAwait(false);
257+
if (response.StatusCode is >= 200 and < 400)
258+
{
259+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
260+
try
261+
{
262+
return JsonUtils.Deserialize<IEnumerable<PointsLevel>>(responseBody)!;
263+
}
264+
catch (JsonException e)
265+
{
266+
throw new TrophyApiException("Failed to deserialize response", e);
267+
}
268+
}
269+
270+
{
271+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
272+
try
273+
{
274+
switch (response.StatusCode)
275+
{
276+
case 401:
277+
throw new UnauthorizedError(JsonUtils.Deserialize<ErrorBody>(responseBody));
278+
case 404:
279+
throw new NotFoundError(JsonUtils.Deserialize<ErrorBody>(responseBody));
280+
}
281+
}
282+
catch (JsonException)
283+
{
284+
// unable to map error response, throwing generic error
285+
}
286+
throw new TrophyApiApiException(
287+
$"Error with status code {response.StatusCode}",
288+
response.StatusCode,
289+
responseBody
290+
);
291+
}
292+
}
293+
294+
/// <summary>
295+
/// Get a breakdown of the number of users at each level in a points system.
296+
/// </summary>
297+
/// <example><code>
298+
/// await client.Points.LevelSummaryAsync("points-system-key");
299+
/// </code></example>
300+
public async Task<IEnumerable<PointsLevelSummaryResponseItem>> LevelSummaryAsync(
301+
string key,
302+
RequestOptions? options = null,
303+
CancellationToken cancellationToken = default
304+
)
305+
{
306+
var response = await _client
307+
.SendRequestAsync(
308+
new JsonRequest
309+
{
310+
BaseUrl = _client.Options.Environment.Api,
311+
Method = HttpMethod.Get,
312+
Path = string.Format(
313+
"points/{0}/level-summary",
314+
ValueConvert.ToPathParameterString(key)
315+
),
316+
Options = options,
317+
},
318+
cancellationToken
319+
)
320+
.ConfigureAwait(false);
321+
if (response.StatusCode is >= 200 and < 400)
322+
{
323+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
324+
try
325+
{
326+
return JsonUtils.Deserialize<IEnumerable<PointsLevelSummaryResponseItem>>(
327+
responseBody
328+
)!;
329+
}
330+
catch (JsonException e)
331+
{
332+
throw new TrophyApiException("Failed to deserialize response", e);
333+
}
334+
}
335+
336+
{
337+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
338+
try
339+
{
340+
switch (response.StatusCode)
341+
{
342+
case 401:
343+
throw new UnauthorizedError(JsonUtils.Deserialize<ErrorBody>(responseBody));
344+
case 404:
345+
throw new NotFoundError(JsonUtils.Deserialize<ErrorBody>(responseBody));
346+
case 422:
347+
throw new UnprocessableEntityError(
348+
JsonUtils.Deserialize<ErrorBody>(responseBody)
349+
);
350+
}
351+
}
352+
catch (JsonException)
353+
{
354+
// unable to map error response, throwing generic error
355+
}
356+
throw new TrophyApiApiException(
357+
$"Error with status code {response.StatusCode}",
358+
response.StatusCode,
359+
responseBody
360+
);
361+
}
362+
}
229363
}

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.1.2</Version>
12+
<Version>1.2.1</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/GetUserPointsResponse.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ namespace TrophyApi;
77
[Serializable]
88
public record GetUserPointsResponse
99
{
10+
/// <summary>
11+
/// The user's total points
12+
/// </summary>
13+
[JsonPropertyName("total")]
14+
public required int Total { get; set; }
15+
16+
/// <summary>
17+
/// The user's current level in this points system, or null if no levels are configured or the user hasn't reached any level yet.
18+
/// </summary>
19+
[JsonPropertyName("level")]
20+
public PointsLevel? Level { get; set; }
21+
22+
/// <summary>
23+
/// Array of trigger awards that added points.
24+
/// </summary>
25+
[JsonPropertyName("awards")]
26+
public IEnumerable<PointsAward> Awards { get; set; } = new List<PointsAward>();
27+
1028
/// <summary>
1129
/// The ID of the points system
1230
/// </summary>
@@ -43,18 +61,6 @@ public record GetUserPointsResponse
4361
[JsonPropertyName("maxPoints")]
4462
public double? MaxPoints { get; set; }
4563

46-
/// <summary>
47-
/// The user's total points
48-
/// </summary>
49-
[JsonPropertyName("total")]
50-
public required int Total { get; set; }
51-
52-
/// <summary>
53-
/// Array of trigger awards that added points.
54-
/// </summary>
55-
[JsonPropertyName("awards")]
56-
public IEnumerable<PointsAward> Awards { get; set; } = new List<PointsAward>();
57-
5864
/// <summary>
5965
/// Additional properties received from the response, if any.
6066
/// </summary>

src/TrophyApi/Types/MetricEventPointsResponse.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,35 @@
55
namespace TrophyApi;
66

77
/// <summary>
8-
/// Points system response for metric events.
8+
/// Points system response for metric events and achievement completions.
99
/// </summary>
1010
[Serializable]
1111
public record MetricEventPointsResponse
1212
{
13+
/// <summary>
14+
/// The user's total points
15+
/// </summary>
16+
[JsonPropertyName("total")]
17+
public required int Total { get; set; }
18+
19+
/// <summary>
20+
/// The user's new level, included only when the level changed as a result of this event.
21+
/// </summary>
22+
[JsonPropertyName("level")]
23+
public PointsLevel? Level { get; set; }
24+
25+
/// <summary>
26+
/// The points added by this event.
27+
/// </summary>
28+
[JsonPropertyName("added")]
29+
public required int Added { get; set; }
30+
31+
/// <summary>
32+
/// Array of trigger awards that added points.
33+
/// </summary>
34+
[JsonPropertyName("awards")]
35+
public IEnumerable<PointsAward> Awards { get; set; } = new List<PointsAward>();
36+
1337
/// <summary>
1438
/// The ID of the points system
1539
/// </summary>
@@ -46,24 +70,6 @@ public record MetricEventPointsResponse
4670
[JsonPropertyName("maxPoints")]
4771
public double? MaxPoints { get; set; }
4872

49-
/// <summary>
50-
/// The user's total points
51-
/// </summary>
52-
[JsonPropertyName("total")]
53-
public required int Total { get; set; }
54-
55-
/// <summary>
56-
/// The points added by this event.
57-
/// </summary>
58-
[JsonPropertyName("added")]
59-
public required int Added { get; set; }
60-
61-
/// <summary>
62-
/// Array of trigger awards that added points.
63-
/// </summary>
64-
[JsonPropertyName("awards")]
65-
public IEnumerable<PointsAward> Awards { get; set; } = new List<PointsAward>();
66-
6773
/// <summary>
6874
/// Additional properties received from the response, if any.
6975
/// </summary>

src/TrophyApi/Types/PointsLevel.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using TrophyApi.Core;
4+
5+
namespace TrophyApi;
6+
7+
/// <summary>
8+
/// A level within a points system.
9+
/// </summary>
10+
[Serializable]
11+
public record PointsLevel
12+
{
13+
/// <summary>
14+
/// The ID of the level
15+
/// </summary>
16+
[JsonPropertyName("id")]
17+
public required string Id { get; set; }
18+
19+
/// <summary>
20+
/// The unique key of the level
21+
/// </summary>
22+
[JsonPropertyName("key")]
23+
public required string Key { get; set; }
24+
25+
/// <summary>
26+
/// The name of the level
27+
/// </summary>
28+
[JsonPropertyName("name")]
29+
public required string Name { get; set; }
30+
31+
/// <summary>
32+
/// The description of the level
33+
/// </summary>
34+
[JsonPropertyName("description")]
35+
public required string Description { get; set; }
36+
37+
/// <summary>
38+
/// The URL of the badge image for the level
39+
/// </summary>
40+
[JsonPropertyName("badgeUrl")]
41+
public string? BadgeUrl { get; set; }
42+
43+
/// <summary>
44+
/// The points threshold required to reach this level
45+
/// </summary>
46+
[JsonPropertyName("points")]
47+
public required int Points { get; set; }
48+
49+
/// <summary>
50+
/// Additional properties received from the response, if any.
51+
/// </summary>
52+
/// <remarks>
53+
/// [EXPERIMENTAL] This API is experimental and may change in future releases.
54+
/// </remarks>
55+
[JsonExtensionData]
56+
public IDictionary<string, JsonElement> AdditionalProperties { get; internal set; } =
57+
new Dictionary<string, JsonElement>();
58+
59+
/// <inheritdoc />
60+
public override string ToString()
61+
{
62+
return JsonUtils.Serialize(this);
63+
}
64+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using TrophyApi.Core;
4+
5+
namespace TrophyApi;
6+
7+
[Serializable]
8+
public record PointsLevelSummaryResponseItem
9+
{
10+
[JsonPropertyName("level")]
11+
public required PointsLevel Level { get; set; }
12+
13+
/// <summary>
14+
/// The number of users currently at this level
15+
/// </summary>
16+
[JsonPropertyName("users")]
17+
public required int Users { get; set; }
18+
19+
/// <summary>
20+
/// Additional properties received from the response, if any.
21+
/// </summary>
22+
/// <remarks>
23+
/// [EXPERIMENTAL] This API is experimental and may change in future releases.
24+
/// </remarks>
25+
[JsonExtensionData]
26+
public IDictionary<string, JsonElement> AdditionalProperties { get; internal set; } =
27+
new Dictionary<string, JsonElement>();
28+
29+
/// <inheritdoc />
30+
public override string ToString()
31+
{
32+
return JsonUtils.Serialize(this);
33+
}
34+
}

0 commit comments

Comments
 (0)