Skip to content

Commit ec00da3

Browse files
committed
fix examination property in the status datajson converter
1 parent 077a339 commit ec00da3

4 files changed

Lines changed: 10 additions & 52 deletions

File tree

WebUntisAPI.Client/Converter/ClassJsonConverter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
namespace WebUntisAPI.Client.Converter
88
{
9-
/// <summary>
10-
/// Convert the teachers in webuntis get classes response to int array
11-
/// </summary>
129
internal class ClassJsonConverter : JsonConverter<Class>
1310
{
1411
/// <inheritdoc/>

WebUntisAPI.Client/Converter/StatusDataJsonConverter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public override StatusData ReadJson(JsonReader reader, Type objectType, StatusDa
2525
OhColors = lessonTypes.First(obj => obj.ContainsKey("oh"))["oh"].ToObject<ForeBackColors>(),
2626
SbColors = lessonTypes.First(obj => obj.ContainsKey("sb"))["sb"].ToObject<ForeBackColors>(),
2727
BsColors = lessonTypes.First(obj => obj.ContainsKey("bs"))["bs"].ToObject<ForeBackColors>(),
28+
ExColors = lessonTypes.First(obj => obj.ContainsKey("ex"))["ex"].ToObject<ForeBackColors>(),
2829
CancelledLessonColors = codes.First(obj => obj.ContainsKey("cancelled"))["cancelled"].ToObject<ForeBackColors>(),
2930
IrregularLessonColors = codes.First(obj => obj.ContainsKey("irregular"))["irregular"].ToObject<ForeBackColors>()
3031
};
@@ -57,6 +58,11 @@ public override void WriteJson(JsonWriter writer, StatusData value, JsonSerializ
5758
serializer.Serialize(writer, value.BsColors);
5859
writer.WriteEndObject();
5960

61+
writer.WriteStartObject();
62+
writer.WritePropertyName("ex");
63+
serializer.Serialize(writer, value.ExColors);
64+
writer.WriteEndObject();
65+
6066
writer.WriteEndArray();
6167

6268
writer.WritePropertyName("codes");

WebUntisAPI.Client/Enums.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public enum LessonType
117117
public enum Code
118118
{
119119
/// <summary>
120-
/// No code
120+
/// No code (normal lesson)
121121
/// </summary>
122122
[JsonProperty("")]
123123
None = 0,

WebUntisAPI.Client/SchoolSearch.cs

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,57 +36,12 @@ public static class SchoolSearch
3636
/// <exception cref="HttpRequestException">Throws when an error happend while request</exception>
3737
public static async Task<School[]> SearchAsync(string name, string id = "searchForSchool", CancellationToken ct = default)
3838
{
39-
StringWriter sw = new StringWriter();
40-
using (JsonWriter writer = new JsonTextWriter(sw))
39+
Action<JsonWriter> paramAction = new Action<JsonWriter>(writer =>
4140
{
42-
writer.WriteStartObject();
43-
44-
writer.WritePropertyName("id");
45-
writer.WriteValue(id);
46-
47-
writer.WritePropertyName("method");
48-
writer.WriteValue("searchSchool");
49-
50-
writer.WritePropertyName("params");
51-
writer.WriteStartArray();
52-
writer.WriteStartObject();
5341
writer.WritePropertyName("search");
5442
writer.WriteValue(name);
55-
writer.WriteEndObject();
56-
writer.WriteEndArray();
57-
58-
writer.WritePropertyName("jsonrpc");
59-
writer.WriteValue("2.0");
60-
61-
writer.WriteEndObject();
62-
}
63-
64-
StringContent requestContent = new StringContent(sw.ToString(), Encoding.UTF8, "application/json");
65-
66-
// Send request
67-
HttpResponseMessage response;
68-
using (HttpClient client = new HttpClient())
69-
response = await client.PostAsync(s_API_Url, requestContent, ct);
70-
71-
if (ct.IsCancellationRequested)
72-
return Array.Empty<School>();
73-
74-
// Verify response
75-
if (response.StatusCode != HttpStatusCode.OK)
76-
throw new HttpRequestException($"The request had an error (Code: {response.StatusCode}).");
77-
78-
JObject responseObject = JObject.Parse(await response.Content.ReadAsStringAsync());
79-
80-
// Check for WebUntis error
81-
if (responseObject["error"]?.ToObject<WebUntisException>() is WebUntisException error)
82-
{
83-
if (error.Code == (int)WebUntisException.Codes.TooManyResults)
84-
return null;
85-
86-
throw error;
87-
}
88-
89-
return responseObject["result"]["schools"].ToObject<School[]>();
43+
});
44+
return await SearchForSchoolAsync(paramAction, id, ct);
9045
}
9146

9247
/// <summary>

0 commit comments

Comments
 (0)