Skip to content

Commit 704f180

Browse files
committed
Add method to get the latest update date of the webuntis data, Fix a merge mistake
1 parent 5e2f2a4 commit 704f180

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

API.Test/TeachingTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,17 @@ public void GetDepartment()
6363
else
6464
Assert.Fail();
6565
}
66+
67+
[Test]
68+
public void GetLatestImportTime()
69+
{
70+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
71+
72+
Task<DateTime> time = Client.GetLatestImportTimeAsync();
73+
time.Wait();
74+
if (time.Result <= DateTime.Now)
75+
Assert.Pass();
76+
else
77+
Assert.Fail();
78+
}
6679
}

WebUntisAPI.Client/Exceptions/WebUntisException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public enum Codes
3333
/// <summary>
3434
/// Json rpc method not found
3535
/// </summary>
36-
MethodNotFound = -32601
36+
MethodNotFound = -32601,
3737

3838
/// <summary>
3939
/// Access denied for the requested timetable

WebUntisAPI.Client/WebUntisClient.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ public async Task LogoutAsync(string id = "getStudents", CancellationToken ct =
227227
throw new HttpRequestException($"There was an error while the http request (Code: {response.StatusCode}).");
228228
}
229229

230+
/// <summary>
231+
/// Get the latest update date of the WebUntis data
232+
/// </summary>
233+
/// <param name="id">Identifier for the request</param>
234+
/// <param name="ct">Cancellation token</param>
235+
/// <returns>The latest update date in <see cref="DateTimeKind.Utc"/></returns>
236+
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
237+
/// <exception cref="UnauthorizedAccessException">Thrown when the client isn't logged in</exception>
238+
/// <exception cref="HttpRequestException">Thrown when an error happend while the http request</exception>
239+
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
240+
public async Task<DateTime> GetLatestImportTimeAsync(string id = "getLatestImportTime", CancellationToken ct = default)
241+
{
242+
long timestamp = await MakeRequestAsync<object, long>(id, "getLatestImportTime", new object(), ct);
243+
return new DateTime(1970, 01, 01, 0, 0, 0, DateTimeKind.Utc).AddTicks(timestamp * 10000);
244+
}
245+
230246
/// <summary>
231247
/// Make an internal basic request to the WebUntis server
232248
/// </summary>

0 commit comments

Comments
 (0)