Skip to content

Commit 85c4638

Browse files
Automatically update Dotnet SDK
1 parent 338fadd commit 85c4638

23 files changed

Lines changed: 359 additions & 36 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", "{71434DC8-5CE8-41A8-8327-81AB2153803E}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi", "TrophyApi\TrophyApi.csproj", "{35C05A1E-59D5-4D96-9B7C-1C522E50D9C3}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{BB47A9F9-86B9-4D8A-BC4F-7D304BBC5632}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrophyApi.Test", "TrophyApi.Test\TrophyApi.Test.csproj", "{FFECC591-FFA2-40B7-BFFA-4861CEB7ED9F}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -16,13 +16,13 @@ Global
1616
HideSolutionNode = FALSE
1717
EndGlobalSection
1818
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19-
{71434DC8-5CE8-41A8-8327-81AB2153803E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20-
{71434DC8-5CE8-41A8-8327-81AB2153803E}.Debug|Any CPU.Build.0 = Debug|Any CPU
21-
{71434DC8-5CE8-41A8-8327-81AB2153803E}.Release|Any CPU.ActiveCfg = Release|Any CPU
22-
{71434DC8-5CE8-41A8-8327-81AB2153803E}.Release|Any CPU.Build.0 = Release|Any CPU
23-
{BB47A9F9-86B9-4D8A-BC4F-7D304BBC5632}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24-
{BB47A9F9-86B9-4D8A-BC4F-7D304BBC5632}.Debug|Any CPU.Build.0 = Debug|Any CPU
25-
{BB47A9F9-86B9-4D8A-BC4F-7D304BBC5632}.Release|Any CPU.ActiveCfg = Release|Any CPU
26-
{BB47A9F9-86B9-4D8A-BC4F-7D304BBC5632}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{35C05A1E-59D5-4D96-9B7C-1C522E50D9C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{35C05A1E-59D5-4D96-9B7C-1C522E50D9C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{35C05A1E-59D5-4D96-9B7C-1C522E50D9C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{35C05A1E-59D5-4D96-9B7C-1C522E50D9C3}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{FFECC591-FFA2-40B7-BFFA-4861CEB7ED9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{FFECC591-FFA2-40B7-BFFA-4861CEB7ED9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{FFECC591-FFA2-40B7-BFFA-4861CEB7ED9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{FFECC591-FFA2-40B7-BFFA-4861CEB7ED9F}.Release|Any CPU.Build.0 = Release|Any CPU
2727
EndGlobalSection
2828
EndGlobal

src/TrophyApi/Achievements/AchievementsClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task<IEnumerable<AchievementWithStatsResponse>> AllAsync(
3232
.MakeRequestAsync(
3333
new RawClient.JsonApiRequest
3434
{
35-
BaseUrl = _client.Options.BaseUrl,
35+
BaseUrl = _client.Options.Environment.Api,
3636
Method = HttpMethod.Get,
3737
Path = "achievements",
3838
Options = options,
@@ -108,7 +108,7 @@ public async Task<AchievementCompletionResponse> CompleteAsync(
108108
.MakeRequestAsync(
109109
new RawClient.JsonApiRequest
110110
{
111-
BaseUrl = _client.Options.BaseUrl,
111+
BaseUrl = _client.Options.Environment.Api,
112112
Method = HttpMethod.Post,
113113
Path = $"achievements/{key}/complete",
114114
Body = request,

src/TrophyApi/Admin/AdminClient.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using TrophyApi.Admin.Streaks;
2+
using TrophyApi.Core;
3+
4+
namespace TrophyApi.Admin;
5+
6+
public partial class AdminClient
7+
{
8+
private RawClient _client;
9+
10+
internal AdminClient(RawClient client)
11+
{
12+
_client = client;
13+
Streaks = new StreaksClient(_client);
14+
}
15+
16+
public StreaksClient Streaks { get; }
17+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Net.Http;
2+
using System.Text.Json;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using TrophyApi;
6+
using TrophyApi.Core;
7+
8+
namespace TrophyApi.Admin.Streaks;
9+
10+
public partial class FreezesClient
11+
{
12+
private RawClient _client;
13+
14+
internal FreezesClient(RawClient client)
15+
{
16+
_client = client;
17+
}
18+
19+
/// <summary>
20+
/// Create streak freezes for multiple users.
21+
/// </summary>
22+
/// <example>
23+
/// <code>
24+
/// await client.Admin.Streaks.Freezes.CreateAsync(
25+
/// new CreateStreakFreezesRequest
26+
/// {
27+
/// Freezes = new List&lt;CreateStreakFreezesRequestFreezesItem&gt;()
28+
/// {
29+
/// new CreateStreakFreezesRequestFreezesItem { UserId = "user-123" },
30+
/// new CreateStreakFreezesRequestFreezesItem { UserId = "user-456" },
31+
/// new CreateStreakFreezesRequestFreezesItem { UserId = "user-123" },
32+
/// },
33+
/// }
34+
/// );
35+
/// </code>
36+
/// </example>
37+
public async Task<CreateStreakFreezesResponse> CreateAsync(
38+
CreateStreakFreezesRequest request,
39+
RequestOptions? options = null,
40+
CancellationToken cancellationToken = default
41+
)
42+
{
43+
var response = await _client
44+
.MakeRequestAsync(
45+
new RawClient.JsonApiRequest
46+
{
47+
BaseUrl = _client.Options.Environment.Admin,
48+
Method = HttpMethod.Post,
49+
Path = "streaks/freezes",
50+
Body = request,
51+
ContentType = "application/json",
52+
Options = options,
53+
},
54+
cancellationToken
55+
)
56+
.ConfigureAwait(false);
57+
var responseBody = await response.Raw.Content.ReadAsStringAsync();
58+
if (response.StatusCode is >= 200 and < 400)
59+
{
60+
try
61+
{
62+
return JsonUtils.Deserialize<CreateStreakFreezesResponse>(responseBody)!;
63+
}
64+
catch (JsonException e)
65+
{
66+
throw new TrophyApiException("Failed to deserialize response", e);
67+
}
68+
}
69+
70+
try
71+
{
72+
switch (response.StatusCode)
73+
{
74+
case 400:
75+
throw new BadRequestError(JsonUtils.Deserialize<ErrorBody>(responseBody));
76+
case 401:
77+
throw new UnauthorizedError(JsonUtils.Deserialize<ErrorBody>(responseBody));
78+
case 422:
79+
throw new UnprocessableEntityError(
80+
JsonUtils.Deserialize<ErrorBody>(responseBody)
81+
);
82+
}
83+
}
84+
catch (JsonException)
85+
{
86+
// unable to map error response, throwing generic error
87+
}
88+
throw new TrophyApiApiException(
89+
$"Error with status code {response.StatusCode}",
90+
response.StatusCode,
91+
responseBody
92+
);
93+
}
94+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Text.Json.Serialization;
2+
using TrophyApi.Core;
3+
4+
namespace TrophyApi.Admin.Streaks;
5+
6+
public record CreateStreakFreezesRequest
7+
{
8+
/// <summary>
9+
/// Array of freezes to create. Maximum 1,000 freezes per request.
10+
/// </summary>
11+
[JsonPropertyName("freezes")]
12+
public IEnumerable<CreateStreakFreezesRequestFreezesItem> Freezes { get; set; } =
13+
new List<CreateStreakFreezesRequestFreezesItem>();
14+
15+
public override string ToString()
16+
{
17+
return JsonUtils.Serialize(this);
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Text.Json.Serialization;
2+
using TrophyApi.Core;
3+
4+
namespace TrophyApi.Admin.Streaks;
5+
6+
public record CreateStreakFreezesRequestFreezesItem
7+
{
8+
/// <summary>
9+
/// The ID of the user to create a freeze for.
10+
/// </summary>
11+
[JsonPropertyName("userId")]
12+
public required string UserId { get; set; }
13+
14+
public override string ToString()
15+
{
16+
return JsonUtils.Serialize(this);
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using TrophyApi.Core;
2+
3+
namespace TrophyApi.Admin.Streaks;
4+
5+
public partial class StreaksClient
6+
{
7+
private RawClient _client;
8+
9+
internal StreaksClient(RawClient client)
10+
{
11+
_client = client;
12+
Freezes = new FreezesClient(_client);
13+
}
14+
15+
public FreezesClient Freezes { get; }
16+
}

src/TrophyApi/Core/Public/ClientOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace TrophyApi;
77
public partial class ClientOptions
88
{
99
/// <summary>
10-
/// The Base URL for the API.
10+
/// The Environment for the API.
1111
/// </summary>
12-
public string BaseUrl { get; init; } = TrophyApiEnvironment.Default;
12+
public TrophyApiEnvironment Environment { get; init; } = TrophyApiEnvironment.Production;
1313

1414
/// <summary>
1515
/// The http client used to make requests.
@@ -38,7 +38,7 @@ internal ClientOptions Clone()
3838
{
3939
return new ClientOptions
4040
{
41-
BaseUrl = BaseUrl,
41+
Environment = Environment,
4242
HttpClient = HttpClient,
4343
MaxRetries = MaxRetries,
4444
Timeout = Timeout,

src/TrophyApi/Core/Public/TrophyApiEnvironment.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,19 @@ namespace TrophyApi;
22

33
public class TrophyApiEnvironment
44
{
5-
public const string Default = "https://app.trophy.so/api";
5+
public static readonly TrophyApiEnvironment Production = new TrophyApiEnvironment
6+
{
7+
Api = "api.trophy.so",
8+
Admin = "admin.trophy.so",
9+
};
10+
11+
/// <summary>
12+
/// URL for the api service
13+
/// </summary>
14+
public string Api { get; init; }
15+
16+
/// <summary>
17+
/// URL for the admin service
18+
/// </summary>
19+
public string Admin { get; init; }
620
}

src/TrophyApi/Leaderboards/LeaderboardsClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task<IEnumerable<LeaderboardResponse>> AllAsync(
3232
.MakeRequestAsync(
3333
new RawClient.JsonApiRequest
3434
{
35-
BaseUrl = _client.Options.BaseUrl,
35+
BaseUrl = _client.Options.Environment.Api,
3636
Method = HttpMethod.Get,
3737
Path = "leaderboards",
3838
Options = options,
@@ -115,7 +115,7 @@ public async Task<LeaderboardResponseWithRankings> GetAsync(
115115
.MakeRequestAsync(
116116
new RawClient.JsonApiRequest
117117
{
118-
BaseUrl = _client.Options.BaseUrl,
118+
BaseUrl = _client.Options.Environment.Api,
119119
Method = HttpMethod.Get,
120120
Path = $"leaderboards/{key}",
121121
Query = _query,

0 commit comments

Comments
 (0)