Skip to content

Commit 53a25c1

Browse files
Automatically update Dotnet SDK
1 parent 99f7935 commit 53a25c1

30 files changed

Lines changed: 1100 additions & 22 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", "{B98F1645-B048-4E26-8F4B-B552045682D7}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi", "TrophyApi\TrophyApi.csproj", "{31D07011-A9C9-43B3-9AD9-012E8ADDC217}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{7BE08930-F33D-4C4E-98F5-62D6C742DDD8}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{3D2E22C9-648B-459D-BC45-E99DC0ABC31D}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -16,13 +16,13 @@ Global
1616
HideSolutionNode = FALSE
1717
EndGlobalSection
1818
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19-
{B98F1645-B048-4E26-8F4B-B552045682D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20-
{B98F1645-B048-4E26-8F4B-B552045682D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
21-
{B98F1645-B048-4E26-8F4B-B552045682D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
22-
{B98F1645-B048-4E26-8F4B-B552045682D7}.Release|Any CPU.Build.0 = Release|Any CPU
23-
{7BE08930-F33D-4C4E-98F5-62D6C742DDD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24-
{7BE08930-F33D-4C4E-98F5-62D6C742DDD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
25-
{7BE08930-F33D-4C4E-98F5-62D6C742DDD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
26-
{7BE08930-F33D-4C4E-98F5-62D6C742DDD8}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{31D07011-A9C9-43B3-9AD9-012E8ADDC217}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{31D07011-A9C9-43B3-9AD9-012E8ADDC217}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{31D07011-A9C9-43B3-9AD9-012E8ADDC217}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{31D07011-A9C9-43B3-9AD9-012E8ADDC217}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{3D2E22C9-648B-459D-BC45-E99DC0ABC31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{3D2E22C9-648B-459D-BC45-E99DC0ABC31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{3D2E22C9-648B-459D-BC45-E99DC0ABC31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{3D2E22C9-648B-459D-BC45-E99DC0ABC31D}.Release|Any CPU.Build.0 = Release|Any CPU
2727
EndGlobalSection
2828
EndGlobal

src/TrophyApi/Admin/AdminClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using TrophyApi.Admin.Points;
12
using TrophyApi.Core;
23

34
namespace TrophyApi.Admin;
@@ -10,7 +11,10 @@ internal AdminClient(RawClient client)
1011
{
1112
_client = client;
1213
Streaks = new StreaksClient(_client);
14+
Points = new PointsClient(_client);
1315
}
1416

1517
public StreaksClient Streaks { get; }
18+
19+
public PointsClient Points { get; }
1620
}
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
using System.Net.Http;
2+
using System.Text.Json;
3+
using System.Threading;
4+
using global::System.Threading.Tasks;
5+
using TrophyApi;
6+
using TrophyApi.Core;
7+
8+
namespace TrophyApi.Admin.Points;
9+
10+
public partial class BoostsClient
11+
{
12+
private RawClient _client;
13+
14+
internal BoostsClient(RawClient client)
15+
{
16+
_client = client;
17+
}
18+
19+
/// <summary>
20+
/// Create points boosts for multiple users.
21+
/// </summary>
22+
/// <example><code>
23+
/// await client.Admin.Points.Boosts.CreateAsync(
24+
/// new CreatePointsBoostsRequest
25+
/// {
26+
/// SystemKey = "xp",
27+
/// Boosts = new List&lt;CreatePointsBoostsRequestBoostsItem&gt;()
28+
/// {
29+
/// new CreatePointsBoostsRequestBoostsItem
30+
/// {
31+
/// UserId = "user-123",
32+
/// Name = "Double XP Weekend",
33+
/// Start = "2024-01-01",
34+
/// End = "2024-01-03",
35+
/// Multiplier = 2,
36+
/// },
37+
/// new CreatePointsBoostsRequestBoostsItem
38+
/// {
39+
/// UserId = "user-456",
40+
/// Name = "Holiday Bonus",
41+
/// Start = "2024-12-25",
42+
/// Multiplier = 1.5,
43+
/// Rounding = CreatePointsBoostsRequestBoostsItemRounding.Up,
44+
/// },
45+
/// },
46+
/// }
47+
/// );
48+
/// </code></example>
49+
public async Task<CreatePointsBoostsResponse> CreateAsync(
50+
CreatePointsBoostsRequest request,
51+
RequestOptions? options = null,
52+
CancellationToken cancellationToken = default
53+
)
54+
{
55+
var response = await _client
56+
.SendRequestAsync(
57+
new JsonRequest
58+
{
59+
BaseUrl = _client.Options.Environment.Admin,
60+
Method = HttpMethod.Post,
61+
Path = "points/boosts",
62+
Body = request,
63+
ContentType = "application/json",
64+
Options = options,
65+
},
66+
cancellationToken
67+
)
68+
.ConfigureAwait(false);
69+
if (response.StatusCode is >= 200 and < 400)
70+
{
71+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
72+
try
73+
{
74+
return JsonUtils.Deserialize<CreatePointsBoostsResponse>(responseBody)!;
75+
}
76+
catch (JsonException e)
77+
{
78+
throw new TrophyApiException("Failed to deserialize response", e);
79+
}
80+
}
81+
82+
{
83+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
84+
try
85+
{
86+
switch (response.StatusCode)
87+
{
88+
case 400:
89+
throw new BadRequestError(JsonUtils.Deserialize<ErrorBody>(responseBody));
90+
case 401:
91+
throw new UnauthorizedError(JsonUtils.Deserialize<ErrorBody>(responseBody));
92+
case 404:
93+
throw new NotFoundError(JsonUtils.Deserialize<ErrorBody>(responseBody));
94+
case 422:
95+
throw new UnprocessableEntityError(
96+
JsonUtils.Deserialize<ErrorBody>(responseBody)
97+
);
98+
}
99+
}
100+
catch (JsonException)
101+
{
102+
// unable to map error response, throwing generic error
103+
}
104+
throw new TrophyApiApiException(
105+
$"Error with status code {response.StatusCode}",
106+
response.StatusCode,
107+
responseBody
108+
);
109+
}
110+
}
111+
112+
/// <summary>
113+
/// Archive multiple points boosts by ID.
114+
/// </summary>
115+
/// <example><code>
116+
/// await client.Admin.Points.Boosts.BatchArchiveAsync(new BoostsBatchArchiveRequest());
117+
/// </code></example>
118+
public async Task<ArchivePointsBoostsResponse> BatchArchiveAsync(
119+
BoostsBatchArchiveRequest request,
120+
RequestOptions? options = null,
121+
CancellationToken cancellationToken = default
122+
)
123+
{
124+
var _query = new Dictionary<string, object>();
125+
_query["ids"] = request.Ids;
126+
var response = await _client
127+
.SendRequestAsync(
128+
new JsonRequest
129+
{
130+
BaseUrl = _client.Options.Environment.Admin,
131+
Method = HttpMethod.Delete,
132+
Path = "points/boosts",
133+
Query = _query,
134+
Options = options,
135+
},
136+
cancellationToken
137+
)
138+
.ConfigureAwait(false);
139+
if (response.StatusCode is >= 200 and < 400)
140+
{
141+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
142+
try
143+
{
144+
return JsonUtils.Deserialize<ArchivePointsBoostsResponse>(responseBody)!;
145+
}
146+
catch (JsonException e)
147+
{
148+
throw new TrophyApiException("Failed to deserialize response", e);
149+
}
150+
}
151+
152+
{
153+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
154+
try
155+
{
156+
switch (response.StatusCode)
157+
{
158+
case 400:
159+
throw new BadRequestError(JsonUtils.Deserialize<ErrorBody>(responseBody));
160+
case 401:
161+
throw new UnauthorizedError(JsonUtils.Deserialize<ErrorBody>(responseBody));
162+
}
163+
}
164+
catch (JsonException)
165+
{
166+
// unable to map error response, throwing generic error
167+
}
168+
throw new TrophyApiApiException(
169+
$"Error with status code {response.StatusCode}",
170+
response.StatusCode,
171+
responseBody
172+
);
173+
}
174+
}
175+
176+
/// <summary>
177+
/// Archive a points boost by ID.
178+
/// </summary>
179+
/// <example><code>
180+
/// await client.Admin.Points.Boosts.ArchiveAsync("id");
181+
/// </code></example>
182+
public async global::System.Threading.Tasks.Task ArchiveAsync(
183+
string id,
184+
RequestOptions? options = null,
185+
CancellationToken cancellationToken = default
186+
)
187+
{
188+
var response = await _client
189+
.SendRequestAsync(
190+
new JsonRequest
191+
{
192+
BaseUrl = _client.Options.Environment.Admin,
193+
Method = HttpMethod.Delete,
194+
Path = string.Format(
195+
"points/boosts/{0}",
196+
ValueConvert.ToPathParameterString(id)
197+
),
198+
Options = options,
199+
},
200+
cancellationToken
201+
)
202+
.ConfigureAwait(false);
203+
if (response.StatusCode is >= 200 and < 400)
204+
{
205+
return;
206+
}
207+
{
208+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
209+
try
210+
{
211+
switch (response.StatusCode)
212+
{
213+
case 401:
214+
throw new UnauthorizedError(JsonUtils.Deserialize<ErrorBody>(responseBody));
215+
case 404:
216+
throw new NotFoundError(JsonUtils.Deserialize<ErrorBody>(responseBody));
217+
}
218+
}
219+
catch (JsonException)
220+
{
221+
// unable to map error response, throwing generic error
222+
}
223+
throw new TrophyApiApiException(
224+
$"Error with status code {response.StatusCode}",
225+
response.StatusCode,
226+
responseBody
227+
);
228+
}
229+
}
230+
}
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.Points;
5+
6+
[Serializable]
7+
public record BoostsBatchArchiveRequest
8+
{
9+
/// <summary>
10+
/// A list of up to 100 boost IDs.
11+
/// </summary>
12+
[JsonIgnore]
13+
public IEnumerable<string> Ids { get; set; } = new List<string>();
14+
15+
/// <inheritdoc />
16+
public override string ToString()
17+
{
18+
return JsonUtils.Serialize(this);
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text.Json.Serialization;
2+
using TrophyApi.Core;
3+
4+
namespace TrophyApi.Admin.Points;
5+
6+
[Serializable]
7+
public record CreatePointsBoostsRequest
8+
{
9+
/// <summary>
10+
/// The key of the points system to create boosts for.
11+
/// </summary>
12+
[JsonPropertyName("systemKey")]
13+
public required string SystemKey { get; set; }
14+
15+
/// <summary>
16+
/// Array of boosts to create. Maximum 1,000 boosts per request.
17+
/// </summary>
18+
[JsonPropertyName("boosts")]
19+
public IEnumerable<CreatePointsBoostsRequestBoostsItem> Boosts { get; set; } =
20+
new List<CreatePointsBoostsRequestBoostsItem>();
21+
22+
/// <inheritdoc />
23+
public override string ToString()
24+
{
25+
return JsonUtils.Serialize(this);
26+
}
27+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using TrophyApi.Core;
4+
5+
namespace TrophyApi.Admin.Points;
6+
7+
[Serializable]
8+
public record CreatePointsBoostsRequestBoostsItem
9+
{
10+
/// <summary>
11+
/// The ID of the user to create a boost for.
12+
/// </summary>
13+
[JsonPropertyName("userId")]
14+
public required string UserId { get; set; }
15+
16+
/// <summary>
17+
/// The name of the boost.
18+
/// </summary>
19+
[JsonPropertyName("name")]
20+
public required string Name { get; set; }
21+
22+
/// <summary>
23+
/// The start date of the boost (YYYY-MM-DD).
24+
/// </summary>
25+
[JsonPropertyName("start")]
26+
public required string Start { get; set; }
27+
28+
/// <summary>
29+
/// The end date of the boost (YYYY-MM-DD). If null, the boost has no end date.
30+
/// </summary>
31+
[JsonPropertyName("end")]
32+
public string? End { get; set; }
33+
34+
/// <summary>
35+
/// The points multiplier. Must be greater than 0, not equal to 1, and less than 100.
36+
/// </summary>
37+
[JsonPropertyName("multiplier")]
38+
public required double Multiplier { get; set; }
39+
40+
/// <summary>
41+
/// How to round the boosted points. Defaults to 'down'.
42+
/// </summary>
43+
[JsonPropertyName("rounding")]
44+
public CreatePointsBoostsRequestBoostsItemRounding? Rounding { get; set; }
45+
46+
/// <summary>
47+
/// Additional properties received from the response, if any.
48+
/// </summary>
49+
/// <remarks>
50+
/// [EXPERIMENTAL] This API is experimental and may change in future releases.
51+
/// </remarks>
52+
[JsonExtensionData]
53+
public IDictionary<string, JsonElement> AdditionalProperties { get; internal set; } =
54+
new Dictionary<string, JsonElement>();
55+
56+
/// <inheritdoc />
57+
public override string ToString()
58+
{
59+
return JsonUtils.Serialize(this);
60+
}
61+
}

0 commit comments

Comments
 (0)