@@ -44,41 +44,8 @@ public partial class WebUntisClient
4444 /// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
4545 public async Task < Student [ ] > GetAllStudentsAsync ( string id = "getStudents" , CancellationToken ct = default )
4646 {
47- // Check for disposing
48- if ( _disposedValue )
49- throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
50-
51- // Check if you logged in
52- if ( ! LoggedIn )
53- throw new UnauthorizedAccessException ( "You're not logged in" ) ;
54-
55- // Make request
56- JSONRPCRequestModel < object > requestModel = new JSONRPCRequestModel < object > ( )
57- {
58- Id = id ,
59- Method = "getStudents" ,
60- Params = new object ( )
61- } ;
62- StringContent requestContent = new StringContent ( JsonConvert . SerializeObject ( requestModel ) , Encoding . UTF8 , "application/json" ) ;
63-
64- // Send request
65- HttpResponseMessage response = await _client . PostAsync ( ServerUrl + "/WebUntis/jsonrpc.do" , requestContent , ct ) ;
66-
67- // Check cancellation token
68- if ( ct . IsCancellationRequested )
69- return null ;
70-
71- // Verify response
72- if ( response . StatusCode != HttpStatusCode . OK )
73- throw new HttpRequestException ( $ "There was an error while the http request (Code: { response . StatusCode } ).") ;
74-
75- JSONRPCResponeModel < List < Student > > responseModel = JsonConvert . DeserializeObject < JSONRPCResponeModel < List < Student > > > ( await response . Content . ReadAsStringAsync ( ) ) ;
76-
77- // Check for WebUntis error
78- if ( responseModel . Error != null )
79- throw responseModel . Error ;
80-
81- return responseModel . Result . ToArray ( ) ;
47+ List < Student > students = await MakeRequestAsync < object , List < Student > > ( id , "getStudents" , new object ( ) , ct ) ;
48+ return students . ToArray ( ) ;
8249 }
8350
8451 /// <summary>
@@ -87,47 +54,14 @@ public async Task<Student[]> GetAllStudentsAsync(string id = "getStudents", Canc
8754 /// <param name="id">Identifier for the request</param>
8855 /// <param name="ct">Cancellation token</param>
8956 /// <returns>An array of all teachers</returns>
90- /// <exception cref="UnauthorizedAccessException">Thrown when you don't logged in</exception>
57+ /// <exception cref="UnauthorizedAccessException">Thrown when you're not logged in</exception>
9158 /// <exception cref="HttpRequestException">Thrown when there was an error while the http request</exception>
9259 /// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
9360 /// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
9461 public async Task < Teacher [ ] > GetAllTeachersAsync ( string id = "getTeachers" , CancellationToken ct = default )
9562 {
96- // Check for disposing
97- if ( _disposedValue )
98- throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
99-
100- // Check if you logged in
101- if ( ! LoggedIn )
102- throw new UnauthorizedAccessException ( "You're not logged in" ) ;
103-
104- // Make request
105- JSONRPCRequestModel < object > requestModel = new JSONRPCRequestModel < object > ( )
106- {
107- Id = id ,
108- Method = "getTeachers" ,
109- Params = new object ( )
110- } ;
111- StringContent requestContent = new StringContent ( JsonConvert . SerializeObject ( requestModel ) , Encoding . UTF8 , "application/json" ) ;
112-
113- // Send request
114- HttpResponseMessage response = await _client . PostAsync ( ServerUrl + "/WebUntis/jsonrpc.do" , requestContent , ct ) ;
115-
116- // Check cancellation token
117- if ( ct . IsCancellationRequested )
118- return null ;
119-
120- // Verify response
121- if ( response . StatusCode != HttpStatusCode . OK )
122- throw new HttpRequestException ( $ "There was an error while the http request (Code: { response . StatusCode } ).") ;
123-
124- JSONRPCResponeModel < List < Teacher > > responseModel = JsonConvert . DeserializeObject < JSONRPCResponeModel < List < Teacher > > > ( await response . Content . ReadAsStringAsync ( ) ) ;
125-
126- // Check for WebUntis error
127- if ( responseModel . Error != null )
128- throw responseModel . Error ;
129-
130- return responseModel . Result . ToArray ( ) ;
63+ List < Teacher > teachers = await MakeRequestAsync < object , List < Teacher > > ( id , "getTeachers" , new object ( ) , ct ) ;
64+ return teachers . ToArray ( ) ;
13165 }
13266 }
13367}
0 commit comments