Skip to content

Commit 1b64f4f

Browse files
committed
Add a method to get the unread news count
1 parent 120ebe7 commit 1b64f4f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

API.Test/TeachingTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ public void GetLatestImportTime()
7777
Assert.Fail();
7878
}
7979

80+
[Test]
81+
public void GetUnreadNews()
82+
{
83+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
84+
85+
Task<int> unread = Client.GetUnreadNewsCountAsync();
86+
unread.Wait();
87+
if (unread.Result == 0)
88+
Assert.Pass();
89+
else
90+
Assert.Fail();
91+
}
92+
8093
[Test]
8194
public void GetNewsFeed()
8295
{

WebUntisAPI.Client/WebUntisClient.Teaching.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ public async Task<Department[]> GetDepartmentsAsync(string id = "getDepartments"
103103
return departments.ToArray();
104104
}
105105

106+
/// <summary>
107+
/// Get the count of unread news
108+
/// </summary>
109+
/// <param name="ct">Cancellation token</param>
110+
/// <returns>The unread news count</returns>
111+
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
112+
/// <exception cref="UnauthorizedAccessException">Thrown when you're not logged in</exception>
113+
/// <exception cref="HttpRequestException">Thrown when an error happend while the http request</exception>
114+
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
115+
public async Task<int> GetUnreadNewsCountAsync(CancellationToken ct = default)
116+
{
117+
string responseString = await MakeAPIGetRequestAsync("/WebUntis/api/rest/view/v1/dashboard/cards/status", ct);
118+
return JObject.Parse(responseString).Value<int>("unreadCardsCount");
119+
}
120+
106121
/// <summary>
107122
/// Get all the news for the school as string
108123
/// </summary>

0 commit comments

Comments
 (0)