Skip to content

Commit cf08040

Browse files
committed
Fix logout error
1 parent e333848 commit cf08040

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

API.Test/AuthentificationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Authentification()
3535
{
3636
using WebUntisClient client = new("WebUntisAPI_TEST");
3737
client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password, CancellationToken.None).Wait();
38-
client.LogoutAsync().Wait();
38+
client.LogoutAsync(CancellationToken.None).Wait();
3939
}
4040
catch
4141
{

WebUntisAPI.Client/Models/SchoolSearchResultModel.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ namespace WebUntisAPI.Client.Models
1111
/// </summary>
1212
internal struct SchoolSearchResultModel
1313
{
14-
/// <summary>
15-
/// Idk
16-
/// </summary>
17-
public int size;
18-
1914
/// <summary>
2015
/// All schools found
2116
/// </summary>

WebUntisAPI.Client/WebUntisClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace WebUntisAPI.Client
2020
/// </summary>
2121
/// <remarks>
2222
/// <para>
23-
/// Please use this class in a using declaration. When you dont use it in a using declaration please call <see cref="LogoutAsync(string)"/> and <see cref="Dispose()"/> when you don't need the connection.
23+
/// Please use this class in a using declaration. When you dont use it in a using declaration please call <see cref="LogoutAsync(CancellationToken, string)"/> and <see cref="Dispose()"/> when you don't need the connection.
2424
/// </para>
2525
/// <para>
2626
/// Under no circumstances should 10 req. per sec., more than 1800req. per hr (but in no case more than 3600 req. per hr). If the specifications are exceeded, access to WebUntis is permanently blocked by the WebUntis API.
@@ -59,7 +59,7 @@ public class WebUntisClient : IDisposable
5959
/// <summary>
6060
/// Current client
6161
/// </summary>
62-
private HttpClient _client;
62+
private readonly HttpClient _client;
6363

6464
/// <summary>
6565
/// Sesson id for requests
@@ -171,9 +171,10 @@ public async Task<bool> LoginAsync(string server, string loginName, string usern
171171
/// Logout (You can reuse the client)
172172
/// </summary>
173173
/// <param name="id">Identifier for the request</param>
174+
/// <param name="ct">Cancellation token</param>
174175
/// <returns>Task for the proccess</returns>
175176
/// <exception cref="HttpRequestException">There was an error while the request</exception>
176-
public async Task LogoutAsync(string id = "logout")
177+
public async Task LogoutAsync(CancellationToken ct, string id = "logout")
177178
{
178179
// Check if you logged in
179180
if (!LoggedIn)
@@ -190,14 +191,13 @@ public async Task LogoutAsync(string id = "logout")
190191
requestContent.Headers.Add("jsessionid", _sessonId);
191192

192193
// Send request
193-
HttpResponseMessage response = await _client.PostAsync(ServerUrl + "/WebUntis/jsonrpc.do", requestContent);
194+
HttpResponseMessage response = await _client.PostAsync(ServerUrl + "/WebUntis/jsonrpc.do", requestContent, ct);
194195

195196
// Clear data
196197
_serverUrl = null;
197198
_loginName = null;
198199
_sessonId = null;
199200
_loggedIn = false;
200-
_client.BaseAddress = null;
201201

202202
// Verify response
203203
if (response.StatusCode != HttpStatusCode.OK)
@@ -224,7 +224,7 @@ protected virtual void Dispose(bool disposing)
224224
{
225225
// When not manually logged out then logout
226226
if (LoggedIn)
227-
_ = LogoutAsync();
227+
_ = LogoutAsync(CancellationToken.None);
228228

229229
if (disposing)
230230
{

0 commit comments

Comments
 (0)