@@ -49,34 +49,20 @@ public async Task<Class[]> GetAllClassesAsync(string id = "getClasses", Cancella
4949 return classes . ToArray ( ) ;
5050 }
5151
52- // Make request
53- JSONRPCRequestModel < object > requestModel = new JSONRPCRequestModel < object > ( )
54- {
55- Id = id ,
56- Method = "getKlassen" ,
57- Params = new object ( )
58- } ;
59- StringContent requestContent = new StringContent ( JsonConvert . SerializeObject ( requestModel ) , Encoding . UTF8 , "application/json" ) ;
60-
61- // Send request
62- HttpResponseMessage response = await _client . PostAsync ( ServerUrl + "/WebUntis/jsonrpc.do" , requestContent , ct ) ;
63-
64- // Check cancellation token
65- if ( ct . IsCancellationRequested )
66- return null ;
67-
68- // Verify response
69- if ( response . StatusCode ! = HttpStatusCode . OK )
70- throw new HttpRequestException( $"There was an error while the http request (Code: {response.StatusCode})." ) ;
71-
72- JSONRPCResponeModel < List < Class > > responseModel = JsonConvert . DeserializeObject < JSONRPCResponeModel < List < Class > > > ( await response . Content . ReadAsStringAsync ( ) ) ;
73-
74- // Check for WebUntis error
75- if ( responseModel . Error != null )
76- throw responseModel . Error ;
77-
78- return responseModel . Result . ToArray ( ) ;
52+ /// <summary>
53+ /// Get all rooms on the school
54+ /// </summary>
55+ /// <param name="id">Identifier of the request</param>
56+ /// <param name="ct">Cancellation token</param>
57+ /// <returns>All rooms on the school</returns>
58+ /// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
59+ /// <exception cref="UnauthorizedAccessException">Thrown when you're not logged in</exception>
60+ /// <exception cref="HttpRequestException">Thrown when an error happend while the http request</exception>
61+ /// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
62+ public async Task < Room [ ] > GetAllRoomsAsync ( string id = "getRooms" , CancellationToken ct = default )
63+ {
64+ List < Room > rooms = await MakeRequestAsync < object , List < Room > > ( id , "getRooms" , new object ( ) , ct ) ;
65+ return rooms . ToArray ( ) ;
7966 }
8067 }
81-
8268}
0 commit comments